public override SAFuzzySystem Generate(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, IGeneratorConf config) { SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { AbstractNotSafeGenerator tempGen = new GeneratorRulesEveryoneWithEveryone(); result = tempGen.Generate(result, config); GC.Collect(); } count_shrink = ((TermShrinkAndRotateConf)config).TSARCShrinkVars; size_shrink = ((TermShrinkAndRotateConf)config).TSARCShrinkTerm; type_func = ((TermShrinkAndRotateConf)config).IEWEFuncType; count_slices = ((TermShrinkAndRotateConf)config).IEWECountSlice; List <int> Varians_of_run_system = new List <int>(); for (int i = 0; i < Approximate.CountFeatures; i++) { int count_terms_for_var = Approximate.RulesDatabaseSet[0].TermsSet.FindAll(x => x.NumVar == i).Count; if (i < count_shrink) { Varians_of_run_system.Add(count_terms_for_var - size_shrink); } else { Varians_of_run_system.Add(count_terms_for_var); } } Varians_of_run_system.Sort(); TypeTermFuncEnum type_of_term = Approximate.RulesDatabaseSet[0].TermsSet[0].TermFuncType; Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { Approximate.RulesDatabaseSet.Clear(); GeneratorRulesEveryoneWithEveryone.InitRulesEveryoneWithEveryone(Approximate, type_of_term, Pull_of_systems[i].ToArray()); Systems_ready_to_test.Add(Approximate.RulesDatabaseSet[0]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[0])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(Systems_ready_to_test[best_index]); Console.WriteLine(Pull_of_systems.Count()); GC.Collect(); // result.UnlaidProtectionFix(); result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
public override SAFuzzySystem Generate(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, IGeneratorConf config) { start_add_rules = Approximate.RulesDatabaseSet.Count; SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { AbstractNotSafeGenerator tempGen = new GeneratorRulesEveryoneWithEveryone(); result = tempGen.Generate(result, config); GC.Collect(); } Request_count_rules = ((RullesShrinkConf)config).RSCCountRules; max_count_rules = ((RullesShrinkConf)config).RSCMaxRules; count_slices = ((RullesShrinkConf)config).IEWECountSlice; min_count_rules = ((RullesShrinkConf)config).RSCMinRules; type_term = ((RullesShrinkConf)config).IEWEFuncType; int count_of_swith_off = ((RullesShrinkConf)config).RSCMaxRules - Request_count_rules; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++) { Varians_of_run_system.Add(1); } for (int i = 0; i < count_of_swith_off; i++) { Varians_of_run_system[i] = 0; } Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { KnowlegeBaseSARules temp_rules = new KnowlegeBaseSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]); temp_rules.TrimTerms(); result.RulesDatabaseSet.Add(temp_rules); result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[start_add_rules + i])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); KnowlegeBaseSARules best = result.RulesDatabaseSet[start_add_rules + best_index]; result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(best); Console.WriteLine(Pull_of_systems.Count()); GC.Collect(); // result.UnlaidProtectionFix(); result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
public override SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf config) { SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { throw new System.FormatException("Что то не то с входными данными"); } OptimizeTermShrinkAndRotateConf Config = config as OptimizeTermShrinkAndRotateConf; count_shrink = Config.OTSARCountShrinkVars; size_shrink = Config.OTSARCountShrinkTerm; List <int> Varians_of_run_system = new List <int>(); for (int i = 0; i < Approximate.CountFeatures; i++) { int count_terms_for_var = Approximate.RulesDatabaseSet[0].TermsSet.FindAll(x => x.NumVar == i).Count; if (i < count_shrink) { Varians_of_run_system.Add(count_terms_for_var - size_shrink); } else { Varians_of_run_system.Add(count_terms_for_var); } } Varians_of_run_system.Sort(); TypeTermFuncEnum type_of_term = Approximate.RulesDatabaseSet[0].TermsSet[0].TermFuncType; Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { Approximate.RulesDatabaseSet.Clear(); GeneratorRulesEveryoneWithEveryone.InitRulesEveryoneWithEveryone(result, type_of_term, Pull_of_systems[i].ToArray()); Systems_ready_to_test.Add(Approximate.RulesDatabaseSet[0]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[0])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(Systems_ready_to_test[best_index]); Console.WriteLine(Pull_of_systems.Count()); result.RulesDatabaseSet[0].TermsSet.Trim(); // result.UnlaidProtectionFix(); return(result); }
public override SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf config) { theFuzzySystem = Approximate; if (theFuzzySystem.RulesDatabaseSet.Count == 0) { throw new System.FormatException("Что то не то с входными данными"); } OptimizeTermShrinkHardCoreConf Config = config as OptimizeTermShrinkHardCoreConf; count_shrink = Config.OTSHCCountShrinkTerm; for (int i = 0; i < Approximate.CountFeatures; i++) { int count_terms_for_var = Approximate.RulesDatabaseSet[0].TermsSet.FindAll(x => x.NumVar == i).Count; if (count_terms_for_var >= count_shrink) { int shrinkcounter = count_shrink; List <int> Varians_of_cut = new List <int>(); for (int j = 0; j < count_terms_for_var; j++) { if (shrinkcounter > 0) { Varians_of_cut.Add(0); } else { Varians_of_cut.Add(1); } shrinkcounter--; } Generate_all_variant_in_pool(Varians_of_cut); for (int j = 0; j < Pull_of_systems.Count; j++) { KnowlegeBaseSARules current = MakeCut(Approximate.RulesDatabaseSet[0], Pull_of_systems[j], i); Systems_ready_to_test.Add(current); errors_of_systems.Add(theFuzzySystem.approxLearnSamples(current)); } Pull_of_systems.Clear(); } } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); theFuzzySystem.RulesDatabaseSet[0] = Systems_ready_to_test[best_index]; return(theFuzzySystem); }
public override SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf config) { start_add_rules = Approximate.RulesDatabaseSet.Count; SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { throw new System.FormatException("Что то не то с входными данными"); } OptimizeRullesShrinkConf Config = config as OptimizeRullesShrinkConf; count_Shrink_rule = Config.ORSCCountShrinkRules; int count_of_swith_off = count_Shrink_rule; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++) { Varians_of_run_system.Add(1); } for (int i = 0; i < count_of_swith_off; i++) { Varians_of_run_system[i] = 0; } Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { KnowlegeBaseSARules temp_rules = new KnowlegeBaseSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]); temp_rules.TrimTerms(); result.RulesDatabaseSet.Add(temp_rules); result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]); errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[start_add_rules + i])); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); KnowlegeBaseSARules best = result.RulesDatabaseSet[start_add_rules + best_index]; result.RulesDatabaseSet.Clear(); result.RulesDatabaseSet.Add(best); Console.WriteLine(Pull_of_systems.Count()); result.RulesDatabaseSet[0].TermsSet.Trim(); // result.UnlaidProtectionFix(); return(result); }
public override SAFuzzySystem Generate(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, IGeneratorConf config) { Random rand = new Random(); SAFuzzySystem result = Approximate; if (result.RulesDatabaseSet.Count == 0) { KnowlegeBaseSARules temp_rules = new KnowlegeBaseSARules(); result.RulesDatabaseSet.Add(temp_rules); } type_term = ((GeneratorRullesSimpleRandomConfig)config).RSRTypeFunc; stable_terms = (int)((GeneratorRullesSimpleRandomConfig)config).RSRConstant; count_rules = ((GeneratorRullesSimpleRandomConfig)config).RSRCountRules; for (int j = 0; j < count_rules; j++) { int[] order = new int[result.CountFeatures]; TypeTermFuncEnum temp_type_term; if (stable_terms == 0) { temp_type_term = type_term; } else { temp_type_term = Generator_type_term(); } List <Term> temp_term_list = new List <Term>(); for (int k = 0; k < result.CountFeatures; k++) { double[] parametrs = new double[Term.CountParamsinSelectedTermType(temp_type_term)]; switch (temp_type_term) { case TypeTermFuncEnum.Треугольник: parametrs[0] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[1] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[2] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); Array.Sort(parametrs); break; case TypeTermFuncEnum.Гауссоида: parametrs[0] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[1] = (rand.NextDouble() + 0.01) * 0.5 * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); break; case TypeTermFuncEnum.Парабола: parametrs[0] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[1] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); Array.Sort(parametrs); break; case TypeTermFuncEnum.Трапеция: parametrs[0] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[1] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[2] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); parametrs[3] = result.LearnSamplesSet.InputAttributes[k].Min + rand.NextDouble() * (result.LearnSamplesSet.InputAttributes[k].Max - result.LearnSamplesSet.InputAttributes[k].Min); Array.Sort(parametrs); break; } Term temp_term = new Term(parametrs, temp_type_term, k); result.RulesDatabaseSet[0].TermsSet.Add(temp_term); temp_term_list.Add(temp_term); order[k] = result.RulesDatabaseSet[0].TermsSet.Count - 1; } double DoubleOutput = KNNConsequent.NearestApprox(result, temp_term_list); SARule temp_Rule = new SARule(result.RulesDatabaseSet[0].TermsSet, order, DoubleOutput); result.RulesDatabaseSet[0].RulesDatabase.Add(temp_Rule); } result.RulesDatabaseSet[0].TermsSet.Trim(); result.UnlaidProtectionFix(result.RulesDatabaseSet[0]); GC.Collect(); return(result); }
public override FuzzySystem.SingletoneApproximate.SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf conf) { Mnk_lib.Mnk_class Mnk_me = new Mnk_lib.Mnk_class(); double [,,] Extracted_rules = extract_Rules(Approximate.RulesDatabaseSet[0]); double [,] Extracted_Samples = extract_Sample_table(Approximate.LearnSamplesSet); double [] Extracted_Samples_out = extract_Sample_table_Out(Approximate.LearnSamplesSet); int count_rules = Approximate.RulesDatabaseSet[0].RulesDatabase.Count; int count_samples = Approximate.LearnSamplesSet.CountSamples; int count_Vars = Approximate.LearnSamplesSet.CountVars; double [] New_consq = new double[count_rules]; TypeTermFuncEnum type_Func = Approximate.RulesDatabaseSet[0].TermsSet[0].TermFuncType; int type_func = (int)type_Func; Mnk_me.mnk_R(Extracted_rules, count_rules, type_func, Extracted_Samples, Extracted_Samples_out, count_samples, count_Vars, out New_consq); SAFuzzySystem Result = Approximate; double result_before = Result.approxLearnSamples(Result.RulesDatabaseSet[0]); double [] Back_consq = Result.RulesDatabaseSet[0].all_conq_of_rules; Result.RulesDatabaseSet[0].all_conq_of_rules = New_consq; double result_after = Result.approxLearnSamples(Result.RulesDatabaseSet[0]); if (result_before < result_after) { Result.RulesDatabaseSet[0].all_conq_of_rules = Back_consq; } GC.Collect(); Result.RulesDatabaseSet[0].TermsSet.Trim(); return(Result); }
public override FuzzySystem.SingletoneApproximate.SAFuzzySystem TuneUpFuzzySystem(FuzzySystem.SingletoneApproximate.SAFuzzySystem Approximate, ILearnAlgorithmConf conf) { result = Approximate; Init(conf); for (int i = 0; i < count_iterate; i++) { oneIterate(result); } Final(); result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }