Ejemplo n.º 1
0
        public Knowlege_base_CRules(Knowlege_base_CRules source, List <bool> used_rules = null)
        {
            for (int i = 0; i < source.Terms_Set.Count; i++)
            {
                Term temp_term = new Term(source.terms_set[i]);
                terms_set.Add(temp_term);
            }


            for (int j = 0; j < source.Rules_Database.Count; j++)
            {
                if ((used_rules == null) || (used_rules[j]))
                {
                    int [] order = new int[source.crules_database[j].Term_of_Rule_Set.Count];
                    for (int k = 0; k < source.crules_database[j].Term_of_Rule_Set.Count; k++)
                    {
                        Term temp_term = source.crules_database[j].Term_of_Rule_Set[k];
                        order[k] = source.Terms_Set.FindIndex(x => x == temp_term);
                    }
                    string temp_class_label = source.crules_database[j].Label_of_Class;
                    double temp_cf          = source.crules_database[j].CF;
                    CRule  temp_rule        = new CRule(terms_set, order, temp_class_label, temp_cf);
                    crules_database.Add(temp_rule);
                }
            }
        }
Ejemplo n.º 2
0
        public void Init_Rules_By_samples(Type_Term_Func_Enum type_func)
        {
            if (Count_Rulles_Databases == 0)
            {
                Knowlege_base_CRules temp_rules = new Knowlege_base_CRules();
                rulles_database_set.Add(temp_rules);
            }

            for (int i = 0; i < Count_Class; i++)
            {
                if (!learn_samples_set.exist_class_var_max(i) || !learn_samples_set.exist_class_var_min(i))
                {
                    continue;
                }
                int[] order_terms = new int[Count_Vars];

                for (int j = 0; j < Count_Vars; j++)
                {
                    double[] paramerts = new double[c_Fuzzy_System.Count_Params_For_Term(type_func)];
                    switch (type_func)
                    {
                    case Type_Term_Func_Enum.Треугольник:
                        paramerts[0] = learn_samples_set.get_class_var_min(i, j) - 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        paramerts[2] = learn_samples_set.get_class_var_max(i, j) + 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        paramerts[1] = (paramerts[0] + paramerts[2]) / 2;
                        break;

                    case Type_Term_Func_Enum.Гауссоида:
                        paramerts[0] = (learn_samples_set.get_class_var_max(i, j) +
                                        learn_samples_set.get_class_var_min(i, j)) / 2;
                        paramerts[1] = (paramerts[0] - learn_samples_set.get_class_var_min(i, j)) / 3;   // rule of 3g
                        break;

                    case Type_Term_Func_Enum.Парабола:
                        paramerts[0] = learn_samples_set.get_class_var_min(i, j) - 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        paramerts[1] = learn_samples_set.get_class_var_max(i, j) + 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        break;

                    case Type_Term_Func_Enum.Трапеция:
                        paramerts[0] = learn_samples_set.get_class_var_min(i, j) - 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        paramerts[3] = learn_samples_set.get_class_var_max(i, j) + 0.001 * (learn_samples_set.get_class_var_max(i, j) - learn_samples_set.get_class_var_min(i, j));
                        paramerts[1] = paramerts[0] + 0.4 * (paramerts[3] - paramerts[0]);
                        paramerts[2] = paramerts[0] + 0.6 * (paramerts[3] - paramerts[0]);
                        break;
                    }
                    Term temp_term = new Term(paramerts, type_func, j);
                    rulles_database_set[0].Terms_Set.Add(temp_term);
                    order_terms[j] = rulles_database_set[0].Terms_Set.Count - 1;
                }
                CRule temp_Rule = new CRule(rulles_database_set[0].Terms_Set, order_terms,
                                            learn_samples_set.Output_Attributes.labels_values[i], 1);
                rulles_database_set[0].Rules_Database.Add(temp_Rule);
            }
        }
Ejemplo n.º 3
0
        public void Init_Rules_everyone_with_everyone(Type_Term_Func_Enum type_func, int [] count_slice__for_var)
        {
            if (Count_Rulles_Databases == 0)
            {
                Knowlege_base_CRules temp_rules = new Knowlege_base_CRules();
                rulles_database_set.Add(temp_rules);
            }
            int[][] position_of_terms = new int[Count_Vars][];
            for (int i = 0; i < Count_Vars; i++)
            {
                position_of_terms[i] = new int[count_slice__for_var[i]];
                double current_value = learn_samples_set.Attribute_Min(i);
                double coeef         = (learn_samples_set.Attribute_Max(i) - learn_samples_set.Attribute_Min(i)) /
                                       (count_slice__for_var[i] - 1);
                for (int j = 0; j < count_slice__for_var[i]; j++)
                {
                    double [] parametrs = new double[Count_Params_For_Term(type_func)];
                    switch (type_func)
                    {
                    case Type_Term_Func_Enum.Треугольник:
                        parametrs[1] = current_value;
                        parametrs[0] = parametrs[1] - coeef;
                        parametrs[2] = parametrs[1] + coeef;
                        break;

                    case Type_Term_Func_Enum.Гауссоида:
                        parametrs[0] = current_value;
                        parametrs[1] = coeef / 3;

                        break;

                    case Type_Term_Func_Enum.Парабола:
                        parametrs[0] = current_value - coeef;
                        parametrs[1] = current_value + coeef;

                        break;

                    case Type_Term_Func_Enum.Трапеция:
                        parametrs[0] = current_value - coeef;
                        parametrs[3] = current_value + coeef;
                        parametrs[1] = parametrs[0] + 0.4 * (parametrs[3] - parametrs[0]);
                        parametrs[2] = parametrs[0] + 0.6 * (parametrs[3] - parametrs[0]);

                        break;
                    }
                    Term temp_term = new Term(parametrs, type_func, i);
                    rulles_database_set[0].Terms_Set.Add(temp_term);
                    position_of_terms[i][j] = rulles_database_set[0].Terms_Set.Count - 1;

                    current_value += coeef;
                }
            }

            int [] counter = new int[Count_Vars];
            for (int i = 0; i < Count_Vars; i++)
            {
                counter [i] = count_slice__for_var[i] - 1;
            }
            while (counter[0] >= 0)
            {
                List <Term> temp_term_set = new List <Term>();
                int []      order         = new int[Count_Vars];
                for (int i = 0; i < Count_Vars; i++)
                {
                    temp_term_set.Add(rulles_database_set[0].Terms_Set[position_of_terms[i][counter[i]]]);
                    order[i] = position_of_terms[i][counter[i]];
                }
                string class_label = Nearest_Class(temp_term_set);

                CRule temp_rule = new CRule(rulles_database_set[0].Terms_Set, order, class_label, 1.0);
                rulles_database_set[0].Rules_Database.Add(temp_rule);
                counter = dec_count(counter, count_slice__for_var);
            }
        }