public override a_Fuzzy_System Generate(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_generator_conf config) { a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { result.Init_Rules_everyone_with_everyone(config); } count_shrink = ((Term_shrink_and_rotate_conf)config).Число_параметров_для_уменьшения_термов; size_shrink = ((Term_shrink_and_rotate_conf)config).Значение_уменьшения_термов; type_func = ((Term_shrink_and_rotate_conf)config).Функция_принадлежности; count_slices = ((Term_shrink_and_rotate_conf)config).Количество_термов_для_каждого_признака; List <int> Varians_of_run_system = new List <int>(); for (int i = 0; i < Approximate.Count_Vars; i++) { int count_terms_for_var = Approximate.Rulles_Database_Set[0].Terms_Set.FindAll(x => x.Number_of_Input_Var == 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(); Type_Term_Func_Enum type_of_term = Approximate.Rulles_Database_Set[0].Terms_Set[0].Term_Func_Type; Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { Approximate.Rulles_Database_Set.Clear(); Approximate.Init_Rules_everyone_with_everyone(type_of_term, Pull_of_systems[i].ToArray()); Systems_ready_to_test.Add(Approximate.Rulles_Database_Set[0]); errors_of_systems.Add(result.approx_Learn_Samples(0)); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); result.Rulles_Database_Set.Clear(); result.Rulles_Database_Set.Add(Systems_ready_to_test[best_index]); Console.WriteLine(Pull_of_systems.Count()); GC.Collect(); // result.unlaid_protection_fix(); return(result); }
public override a_Fuzzy_System TuneUpFuzzySystem(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_learn_algorithm_conf config) { a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { throw new System.FormatException("Что то не то с входными данными"); } Optimize_Term_shrink_and_rotate_conf Config = config as Optimize_Term_shrink_and_rotate_conf; count_shrink = Config.Число_параметров_для_уменьшения_термов; size_shrink = Config.Значение_уменьшения_термов; List <int> Varians_of_run_system = new List <int>(); for (int i = 0; i < Approximate.Count_Vars; i++) { int count_terms_for_var = Approximate.Rulles_Database_Set[0].Terms_Set.FindAll(x => x.Number_of_Input_Var == 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(); Type_Term_Func_Enum type_of_term = Approximate.Rulles_Database_Set[0].Terms_Set[0].Term_Func_Type; Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { Approximate.Rulles_Database_Set.Clear(); Approximate.Init_Rules_everyone_with_everyone(type_of_term, Pull_of_systems[i].ToArray()); Systems_ready_to_test.Add(Approximate.Rulles_Database_Set[0]); errors_of_systems.Add(result.approx_Learn_Samples(0)); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); result.Rulles_Database_Set.Clear(); result.Rulles_Database_Set.Add(Systems_ready_to_test[best_index]); Console.WriteLine(Pull_of_systems.Count()); // result.unlaid_protection_fix(); return(result); }
public override a_Fuzzy_System Generate(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_generator_conf config) { start_add_rules = Approximate.Count_Rulles_Databases; a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { result.Init_Rules_everyone_with_everyone(config); } Request_count_rules = ((Rulles_shrink_conf)config).Нужно_Правил; max_count_rules = ((Rulles_shrink_conf)config).Максимально_Правил; count_slices = ((Rulles_shrink_conf)config).Количество_термов_для_каждого_признака; min_count_rules = ((Rulles_shrink_conf)config).Минимально_Правил; type_term = ((Rulles_shrink_conf)config).Функция_принадлежности; int count_of_swith_off = ((Rulles_shrink_conf)config).Максимально_Правил - Request_count_rules; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.Rulles_Database_Set[0].Rules_Database.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++) { Knowlege_base_ARules temp_rules = new Knowlege_base_ARules(result.Rulles_Database_Set[0], Pull_of_systems[i]); temp_rules.trim_not_used_Terms(); result.Rulles_Database_Set.Add(temp_rules); result.unlaid_protection_fix(start_add_rules + i); errors_of_systems.Add(result.approx_Learn_Samples(start_add_rules + i)); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); Knowlege_base_ARules best = result.Rulles_Database_Set[start_add_rules + best_index]; result.Rulles_Database_Set.Clear(); result.Rulles_Database_Set.Add(best); Console.WriteLine(Pull_of_systems.Count()); GC.Collect(); // result.unlaid_protection_fix(); return(result); }
public override a_Fuzzy_System TuneUpFuzzySystem(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_learn_algorithm_conf config) { start_add_rules = Approximate.Count_Rulles_Databases; a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { throw new System.FormatException("Что то не то с входными данными"); } Optimize_Rulles_shrink_conf Config = config as Optimize_Rulles_shrink_conf; Request_count_rules = ((Rulles_shrink_conf)config).Нужно_Правил; max_count_rules = ((Rulles_shrink_conf)config).Максимально_Правил; min_count_rules = ((Rulles_shrink_conf)config).Минимально_Правил; int count_of_swith_off = Config.Максимально_Правил - Request_count_rules; List <byte> Varians_of_run_system = new List <byte>(); for (int i = 0; i < Approximate.Rulles_Database_Set[0].Rules_Database.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++) { Knowlege_base_ARules temp_rules = new Knowlege_base_ARules(result.Rulles_Database_Set[0], Pull_of_systems[i]); temp_rules.trim_not_used_Terms(); result.Rulles_Database_Set.Add(temp_rules); result.unlaid_protection_fix(start_add_rules + i); errors_of_systems.Add(result.approx_Learn_Samples(start_add_rules + i)); } int best_index = errors_of_systems.IndexOf(errors_of_systems.Min()); Knowlege_base_ARules best = result.Rulles_Database_Set[start_add_rules + best_index]; result.Rulles_Database_Set.Clear(); result.Rulles_Database_Set.Add(best); Console.WriteLine(Pull_of_systems.Count()); // result.unlaid_protection_fix(); return(result); }
public void constuct__and_add_the_Rule(List <Term> terms, a_Fuzzy_System FS) { ARule Result; int[] order_of_terms = new int[terms.Count()]; for (int i = 0; i < terms.Count(); i++) { order_of_terms[i] = terms_set.Count; terms_set.Add(terms[i]); } double kons_Value = FS.Nearest_Approx(terms_set); Result = new ARule(terms_set, order_of_terms, kons_Value); arules_database.Add(Result); }
public override Fuzzy_system.Approx_Singletone.a_Fuzzy_System TuneUpFuzzySystem(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_learn_algorithm_conf conf) { count_iteration = ((Term_Config_PSO_Search_conf)conf).Количество_итераций; c1 = ((Term_Config_PSO_Search_conf)conf).Коэффициент_c1; c2 = ((Term_Config_PSO_Search_conf)conf).Коэффициент_c2; w = 1; count_particle = ((Term_Config_PSO_Search_conf)conf).Особей_в_популяции; a_Fuzzy_System result = Approximate; Knowlege_base_ARules[] X = new Knowlege_base_ARules[count_particle]; Knowlege_base_ARules[] V = new Knowlege_base_ARules[count_particle]; Knowlege_base_ARules[] Pi = new Knowlege_base_ARules[count_particle]; Knowlege_base_ARules Pg = new Knowlege_base_ARules(); double[] Errors = new double[count_particle]; double[] OldErrors = new double[count_particle]; double minError = 0; Random rnd = new Random(); for (int i = 0; i < count_particle; i++) { Knowlege_base_ARules temp_c_Rule = new Knowlege_base_ARules(result.Rulles_Database_Set[0]); X[i] = temp_c_Rule; Errors[i] = result.approx_Learn_Samples(0); OldErrors[i] = Errors[i]; Pi[i] = new Knowlege_base_ARules(X[i]); V[i] = new Knowlege_base_ARules(X[i]); // for (int j = 0; j < V[i].Terms_Set.Count; j++) { for (int k = 0; k < Member_Function.Count_Params_For_Term(V[i].Terms_Set[j].Term_Func_Type); k++) { if (i == 0) { V[i].Terms_Set[j].Parametrs[k] = 0; } else { V[i].Terms_Set[j].Parametrs[k] = rnd.NextDouble() - 0.5; } } double[] bf = new double[V[i].all_conq_of_rules.Length]; for (int k = 0; k < V[i].all_conq_of_rules.Length; k++) { if (i == 0) { bf[k] = 1; } else { bf[k] = rnd.NextDouble() / 200; } } V[i].all_conq_of_rules = bf; } } Pg = new Knowlege_base_ARules(result.Rulles_Database_Set[0]); minError = Errors[0]; for (int i = 0; i < count_iteration; i++) { for (int j = 0; j < count_particle; j++) { w = 1 / (1 + Math.Exp(-(Errors[j] - OldErrors[j]) / 0.01)); for (int k = 0; k < X[j].Terms_Set.Count; k++) { for (int q = 0; q < Member_Function.Count_Params_For_Term(X[j].Terms_Set[k].Term_Func_Type); q++) { double bp = Pi[j].Terms_Set[k].Parametrs[q]; V[j].Terms_Set[k].Parametrs[q] = V[j].Terms_Set[k].Parametrs[q] * w + c1 * rnd.NextDouble() * (bp - X[j].Terms_Set[k].Parametrs[q]) + c2 * rnd.NextDouble() * (Pg.Terms_Set[k].Parametrs[q] - X[j].Terms_Set[k].Parametrs[q]); X[j].Terms_Set[k].Parametrs[q] += V[j].Terms_Set[k].Parametrs[q]; } } double[] bf = new double[V[j].all_conq_of_rules.Length]; double[] bfw = new double[V[j].all_conq_of_rules.Length]; for (int k = 0; k < V[j].all_conq_of_rules.Length; k++) { bfw[k] = V[j].all_conq_of_rules[k] * w + c1 * rnd.NextDouble() * (Pi[j].all_conq_of_rules[k] - X[j].all_conq_of_rules[k]) + c2 * rnd.NextDouble() * (Pg.all_conq_of_rules[k] - X[j].all_conq_of_rules[k]); double sw = X[j].all_conq_of_rules[k] + bfw[k]; if (sw > 0 && sw <= 2) { bf[k] = sw; } else { bf[k] = X[j].all_conq_of_rules[k]; bfw[k] = V[j].all_conq_of_rules[k]; } } X[j].all_conq_of_rules = bf; V[j].all_conq_of_rules = bfw; double newError = 0; result.Rulles_Database_Set.Add(X[j]); int temp_index = result.Rulles_Database_Set.Count - 1; bool success = true; try { newError = result.approx_Learn_Samples(temp_index); } catch (Exception) { success = false; } result.Rulles_Database_Set.RemoveAt(temp_index); if (success && (newError > Errors[j])) { OldErrors[j] = Errors[j]; Errors[j] = newError; Pi[j] = new Knowlege_base_ARules(X[j]); } if (minError < newError) { minError = newError; Pg = new Knowlege_base_ARules(X[j]); } } } result.Rulles_Database_Set[0] = Pg; GC.Collect(); return(result); }
public override Fuzzy_system.Approx_Singletone.a_Fuzzy_System TuneUpFuzzySystem(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_learn_algorithm_conf conf) { Mnk_lib.Mnk_class Mnk_me = new Mnk_lib.Mnk_class(); double [,,] Extracted_rules = extract_Rules(Approximate.Rulles_Database_Set[0]); double [,] Extracted_Samples = extract_Sample_table(Approximate.Learn_Samples_set); double [] Extracted_Samples_out = extract_Sample_table_Out(Approximate.Learn_Samples_set); int count_rules = Approximate.Count_Rules(); int count_samples = Approximate.Learn_Samples_set.Count_Samples; int count_Vars = Approximate.Learn_Samples_set.Count_Vars; double [] New_consq = new double[count_rules]; Type_Term_Func_Enum type_Func = Approximate.Rulles_Database_Set[0].Terms_Set[0].Term_Func_Type; 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); a_Fuzzy_System Result = Approximate; double result_before = Result.approx_Learn_Samples(0); double [] Back_consq = Result.Rulles_Database_Set[0].all_conq_of_rules; Result.Rulles_Database_Set[0].all_conq_of_rules = New_consq; double result_after = Result.approx_Learn_Samples(0); if (result_before < result_after) { Result.Rulles_Database_Set[0].all_conq_of_rules = Back_consq; } GC.Collect(); return(Result); }
public override a_Fuzzy_System Generate(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_generator_conf config) { Random rand = new Random(); a_Fuzzy_System result = Approximate; if (result.Count_Rulles_Databases == 0) { Knowlege_base_ARules temp_rules = new Knowlege_base_ARules(); result.Rulles_Database_Set.Add(temp_rules); } type_term = ((Generator_Rulles_simple_random_conf)config).Функция_принадлежности; stable_terms = (int)((Generator_Rulles_simple_random_conf)config).Тип_Термов; count_rules = ((Generator_Rulles_simple_random_conf)config).Количество_правил; for (int j = 0; j < count_rules; j++) { int[] order = new int[result.Count_Vars]; Type_Term_Func_Enum 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.Count_Vars; k++) { double[] parametrs = new double[Member_Function.Count_Params_For_Term(temp_type_term)]; switch (temp_type_term) { case Type_Term_Func_Enum.Треугольник: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; case Type_Term_Func_Enum.Гауссоида: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = (rand.NextDouble() + 0.01) * 0.5 * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); break; case Type_Term_Func_Enum.Парабола: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; case Type_Term_Func_Enum.Трапеция: parametrs[0] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[1] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[2] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); parametrs[3] = result.Learn_Samples_set.Attribute_Min(k) + rand.NextDouble() * (result.Learn_Samples_set.Attribute_Max(k) - result.Learn_Samples_set.Attribute_Min(k)); Array.Sort(parametrs); break; } Term temp_term = new Term(parametrs, temp_type_term, k); result.Rulles_Database_Set[0].Terms_Set.Add(temp_term); temp_term_list.Add(temp_term); order[k] = result.Rulles_Database_Set[0].Terms_Set.Count - 1; } double approx_Value = result.Nearest_Approx(temp_term_list); ARule temp_Rule = new ARule(result.Rulles_Database_Set[0].Terms_Set, order, approx_Value); result.Rulles_Database_Set[0].Rules_Database.Add(temp_Rule); } result.unlaid_protection_fix(); GC.Collect(); return(result); }
public override Fuzzy_system.Approx_Singletone.a_Fuzzy_System TuneUpFuzzySystem(Fuzzy_system.Approx_Singletone.a_Fuzzy_System Approximate, Abstract_learn_algorithm_conf conf) { count_populate = ((Es_Config)conf).Особей_в_популяции; count_child = ((Es_Config)conf).Потомки; count_iterate = ((Es_Config)conf).Количество_итераций; coef_t1 = ((Es_Config)conf).Коэффициент_t1; coef_t2 = ((Es_Config)conf).Коэффициент_t2; param_crossover = ((Es_Config)conf).Вероятность_скрещивания; alg_cross = ((Es_Config)conf).Алгоритм_Скрещивания; type_init = ((Es_Config)conf).Алгоритм_Инициализации; count_Multipoint = ((Es_Config)conf).Точек_Скрещивания; type_mutate = ((Es_Config)conf).Алгоритм_Мутации; b_ro = ((Es_Config)conf).Изменение_РО; a_Fuzzy_System result = Approximate; Population main_pop = new Population(count_populate, count_child, result.Count_Vars, result.Learn_Samples_set); main_pop.init_first(result.Rulles_Database_Set[0], rand, type_init); for (int i = 0; i < count_iterate; i++) { double inparam = 0; switch (alg_cross) { case Individ.Alg_crossover.Унифицированный: inparam = param_crossover; break; case Individ.Alg_crossover.Многоточечный: inparam = count_Multipoint; break; } main_pop.select_parents_and_crossover(rand, alg_cross, inparam); main_pop.mutate_all(rand, coef_t1, coef_t2, type_mutate, b_ro); main_pop.union_parent_and_child(); main_pop.Calc_Error(result); main_pop.select_global(); } result.Rulles_Database_Set[0] = main_pop.get_best_database(); GC.Collect(); return(result); }