Exemple #1
0
        public override TSAFuzzySystem Generate(TSAFuzzySystem Approximate, IGeneratorConf config)
        {
            type_alg            = ((kMeanRulesGeneratorConfig)config).KMRGTypeAlg;
            count_rules         = ((kMeanRulesGeneratorConfig)config).KMRGCountRules;
            type_func           = ((kMeanRulesGeneratorConfig)config).KMRGTypeFunc;
            nebulisation_factor = ((kMeanRulesGeneratorConfig)config).KMRGExponentialWeight;
            Max_iteration       = ((kMeanRulesGeneratorConfig)config).KMRGIteraton;
            need_precision      = ((kMeanRulesGeneratorConfig)config).KMRGAccuracy;


            Approxk_mean_base K_Agl = null;

            switch (type_alg)
            {
            case Type_k_mean_algorithm.GathGeva: K_Agl = new Approxk_mean_Gath_Geva(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;

            case Type_k_mean_algorithm.GustafsonKessel: K_Agl = new Approxk_mean_Gustafson_kessel(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;

            case Type_k_mean_algorithm.FCM: K_Agl = new Approxk_mean_base(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;
            }
            K_Agl.Calc();

            KnowlegeBaseTSARules New_Rules = new KnowlegeBaseTSARules();

            for (int i = 0; i < count_rules; i++)
            {
                int []      order_terms = new int [Approximate.LearnSamplesSet.CountVars];
                List <Term> term_set    = new List <Term>();
                for (int j = 0; j < Approximate.LearnSamplesSet.CountVars; j++)
                {
                    Term temp_term = Term.MakeTerm(K_Agl.Centroid_cordinate_S[i][j], Math.Sqrt(Calc_distance_for_member_ship_function_for_Clust(i, j, K_Agl)) * 3, type_func, j);
                    term_set.Add(temp_term);
                }
                New_Rules.ConstructNewRule(term_set, Approximate);
            }

            TSAFuzzySystem Result = Approximate;

            if (Result.RulesDatabaseSet.Count > 0)
            {
                Result.RulesDatabaseSet[0] = New_Rules;
            }
            else
            {
                Result.RulesDatabaseSet.Add(New_Rules);
            }
            Result.UnlaidProtectionFix(Result.RulesDatabaseSet[0]);
            GC.Collect();
            Result.RulesDatabaseSet[0].TermsSet.Trim();
            return(Result);
        }
Exemple #2
0
        private double Calc_distance_for_member_ship_function_for_Clust(int number_cluster, int number_var, Approxk_mean_base Alg)
        {
            double nominator   = 0;
            double denominator = 0;

            for (int e = 0; e < Alg.Learn_table.CountSamples; e++)
            {
                nominator   += Math.Pow(Alg.U_matrix[number_cluster][e], 2) * Math.Pow(Alg.Centroid_cordinate_S[number_cluster][number_var] - Alg.Learn_table.DataRows[e].InputAttributeValue[number_var], 2);
                denominator += Math.Pow(Alg.U_matrix[number_cluster][e], 2);
            }
            return(nominator / denominator);
        }