public override int Run(string[] args) { Console.WriteLine("Start"); fill_params(args); Console.WriteLine("Params get \nfile tra {0} \nfile name tst {1} ", file_learn, file_test); Class_learn_set = new SampleSet(file_learn); Class_learn_set = new SampleSet(file_learn); Console.WriteLine("Tra create"); Class_test_set = new SampleSet(file_test); Console.WriteLine("Tst create"); conf = new InitBySamplesConfig(); conf.Init(Class_learn_set.CountVars); fill_conf(); Console.WriteLine("Conf Filed"); Class_Pittsburg = new PCFuzzySystem(Class_learn_set, Class_test_set); Console.WriteLine("Classifier created"); generator = new GeneratorRulesBySamples(); Class_Pittsburg = generator.Generate(Class_Pittsburg, conf); // GeneratorRulesBySamples.InitRulesBySamples(Class_Pittsburg, func); // SingletoneApproximate = generator.Generate(SingletoneApproximate, conf); Console.WriteLine("Gereration complite"); PCFSUFSWriter.saveToUFS(Class_Pittsburg, file_out); Console.WriteLine("Saved"); return(1); }
public static double getLindisSumReverse(this PCFuzzySystem source, int indexDataBase = 0) { double result = 0.0; if (source != null) { double temp = 0.0; for (int i = 0; i < source.CountFeatures; i++) { temp = 0.0; List <Term> termList = source.RulesDatabaseSet[indexDataBase].TermsSet.Where(x => x.NumVar == i).ToList(); if (termList.Count() <= 1) { temp = 0.0; } else { for (int j = 0; j < termList.Count; j++) { for (int k = j + 1; k < termList.Count; k++) { temp += 1 - TermOnterpreting.getIndexByLinds(termList[j], termList[k], termList); } } } result += temp; } result = result / (double)source.CountFeatures; } return(result); }
public override int Run(string[] args) { Console.WriteLine("Start"); fill_params(args); Console.WriteLine("Params get \nfile in {0} \n", file_in); Class_learn_set = BaseUFSLoader.LoadLearnFromUFS(file_in); Console.WriteLine("Tra load"); Class_test_set = BaseUFSLoader.LoadTestFromUFS(file_in); Console.WriteLine("Tst load"); conf = new PSOBacterySearchConf(); conf.Init(Class_learn_set.CountVars); conf.loadParams(confParams); Console.WriteLine("Conf Filed"); Class_Pittsburg = new PCFuzzySystem(Class_learn_set, Class_test_set); Class_Pittsburg = PCFSUFSLoader.loadUFS(Class_Pittsburg, file_in); Console.WriteLine("Classifier created"); optimaze = new Term_config_PSO_Bactery(); Class_Pittsburg = optimaze.TuneUpFuzzySystem(Class_Pittsburg, conf); Console.WriteLine("Optimization complite"); PCFSUFSWriter.saveToUFS(Class_Pittsburg, file_out); Console.WriteLine("Saved"); return(1); }
public static double getGISSumReverce(this PCFuzzySystem source, double goodsForArea = 0, int indexDataBase = 0) { double result = 0.0; if (goodsForArea == 0) { goodsForArea = FuzzyCore.Properties.Settings.Default.Pareto_simpler_UnionTerms_bySqarePercent * 0.01; } if (source != null) { double temp = 0.0; for (int i = 0; i < source.CountFeatures; i++) { temp = 0.0; List <Term> termList = source.RulesDatabaseSet[indexDataBase].TermsSet.Where(x => x.NumVar == i).ToList(); if (termList.Count() <= 1) { temp = 0.0; } else { for (int j = 0; j < termList.Count; j++) { for (int k = j + 1; k < termList.Count; k++) { temp += 1 - TermOnterpreting.getIndexByAreaTerms(termList[j], termList[k], goodsForArea); } } } result += temp; } result = result / source.CountFeatures; } return(result); }
public static double getGICSumStraigth(this PCFuzzySystem source, int indexDataBase = 0) { double result = 0.0; if (source != null) { double temp = 0; for (int i = 0; i < source.CountFeatures; i++) { temp = 0; List <Term> termList = source.RulesDatabaseSet[indexDataBase].TermsSet.Where(x => x.NumVar == i).ToList(); if (termList.Count() <= 1) { temp = 1; } else { for (int j = 0; j < termList.Count; j++) { for (int k = j + 1; k < termList.Count; k++) { temp += TermOnterpreting.getIndexByCentersClose(termList[j], termList[k], termList.Count(), source.LearnSamplesSet.InputAttributes[i].Scatter); } } } result += temp; } result = result / source.CountFeatures; } return(result); }
private static void writeAboutVariblesAndTerms(XmlWriter writer, PCFuzzySystem Classifier) { writer.WriteStartElement("Variables"); writer.WriteAttributeString("Count", XmlConvert.ToString(Classifier.CountFeatures)); for (int i = 0; i < Classifier.CountFeatures; i++) { if (Classifier.AcceptedFeatures[i] == false) { continue; } writer.WriteStartElement("Variable"); writer.WriteAttributeString("Name", Classifier.LearnSamplesSet.InputAttributes[i].Name); writer.WriteAttributeString("Min", XmlConvert.ToString(Classifier.LearnSamplesSet.InputAttributes[i].Min)); writer.WriteAttributeString("Max", XmlConvert.ToString(Classifier.LearnSamplesSet.InputAttributes[i].Max)); List <Term> terms_for_varrible = Classifier.RulesDatabaseSet[0].TermsSet.Where(x => x.NumVar == i).ToList(); writer.WriteStartElement("Terms"); writer.WriteAttributeString("Count", XmlConvert.ToString(terms_for_varrible.Count)); foreach (var term in terms_for_varrible) { BaseUFSWriter.writeAboutTerm(writer, Classifier.RulesDatabaseSet[0].TermsSet.IndexOf(term), term); } writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
private static void writeAboutRules(XmlWriter writer, PCFuzzySystem Classifier) { writer.WriteStartElement("Rules"); writer.WriteAttributeString("Count", XmlConvert.ToString(Classifier.RulesDatabaseSet[0].RulesDatabase.Count)); foreach (PCRule rule in Classifier.RulesDatabaseSet[0].RulesDatabase) { writer.WriteStartElement("Rule"); writer.WriteStartElement("Antecedent"); writer.WriteAttributeString("Count", XmlConvert.ToString(rule.ListTermsInRule.Count)); foreach (Term term in rule.ListTermsInRule) { writer.WriteStartElement("Pair"); writer.WriteAttributeString("Variable", Classifier.LearnSamplesSet.InputAttributes[term.NumVar].Name); writer.WriteAttributeString("Term", XmlConvert.ToString(Classifier.RulesDatabaseSet[0].TermsSet.IndexOf(term))); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("Consequent"); writer.WriteAttributeString("Class", rule.LabelOfClass); writer.WriteAttributeString("CF", XmlConvert.ToString(rule.CF)); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); }
public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classifier, ILearnAlgorithmConf conf) { PCFuzzySystem result = Classifier; double minValue = 5; int minFeature = 0; int minATerm = 0; int minBTerm = 1; int indexDatabase = 0; for (int i = 0; i < result.CountFeatures; i++) { List <Term> soureceByFeature = result.RulesDatabaseSet[indexDatabase].TermsSet.Where(x => x.NumVar == i).ToList(); for (int j = 0; j < soureceByFeature.Count(); j++) { for (int k = j + 1; k < soureceByFeature.Count(); k++) { double temp = TermOnterpreting.getIndexByLinds(soureceByFeature[j], soureceByFeature[k], soureceByFeature); if (temp < minValue) { minValue = temp; minATerm = j; minBTerm = k; minFeature = i; } } } } result = BreakCrossTerm(result, minFeature, minATerm, minBTerm, indexDatabase); result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
private PCFuzzySystem BreakCrossTerm(PCFuzzySystem Classifier, int Feature, int indexATerm, int indexBterm, int dataBase) { PCFuzzySystem result = Classifier; KnowlegeBasePCRules DataSet = result.RulesDatabaseSet[dataBase]; List <Term> soureTerms = DataSet.TermsSet.Where(x => x.NumVar == Feature).ToList(); Term ATerm = soureTerms[indexATerm]; Term BTerm = soureTerms[indexBterm]; Term Left = ATerm; Term Right = BTerm; if (ATerm.Pick > BTerm.Pick) { Left = BTerm; Right = ATerm; } double border = (Left.Max + Right.Min) / 2; Left.Max = border; Right.Min = border; result.RulesDatabaseSet[dataBase] = DataSet; return(result); }
public double PointYDifference(SampleSet.RowSample Point, PCFuzzySystem Approx) { //!!!!! double diff = Point.StringOutput.Equals(Approx.classifyBase(Point.InputAttributeValue, Approx.RulesDatabaseSet[0]), StringComparison.OrdinalIgnoreCase) ? 1.0 : 0.0; return(diff); }
public virtual void preIterate(PCFuzzySystem Classify, ILearnAlgorithmConf conf) { result = Classify; Init(conf); HeadLeader = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]); VelocityVector = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]); VelocityVectorLL = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]); VelocityVectorHL = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]); for (int i = 0; i < VelocityVector.TermsSet.Count; i++) { for (int j = 0; j < VelocityVector.TermsSet[i].Parametrs.Length; j++) { VelocityVector.TermsSet[i].Parametrs[j] = 0; VelocityVectorLL.TermsSet[i].Parametrs[j] = 0; VelocityVectorHL.TermsSet[i].Parametrs[j] = 0; } } SetPopulation(); ParticlesBest = new Dictionary <KnowlegeBasePCRules, KnowlegeBasePCRules>(); foreach (var Particle in Population) { ParticlesBest.Add(Particle, Universal); } LocalLeaders = new KnowlegeBasePCRules[numberOfLocalLeaders]; ExplorerParticles = new KnowlegeBasePCRules[numberOfAllParts - numberOfAimlessParts - numberOfLocalLeaders - 1]; AimlessParticles = new KnowlegeBasePCRules[numberOfAimlessParts]; iter = 0; Population = ListPittsburgClassifierTool.SortRules(Population, result); }
public void GetDots(PCFuzzySystem approx, KnowlegeBasePCRules knowlegeBase) { // Dots (COMPLETE, BUT DOUBLECHECK WHEN DEBUGGING) var inputs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered() .Select(dataRow => dataRow.InputAttributeValue).ToList(); var localDots = inputs.AsParallel().AsOrdered() .Where(InBetweenTheLimits).ToList(); // var strs = new List<string[]>(localDots.Count); // for (int i = 0; i < strs.Capacity; i++) // strs.Add(new[] { string.Empty }); var rezs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered() .Where(row => localDots.Contains(row.InputAttributeValue)) .Select(dataRow => dataRow.DoubleOutput).ToList(); List <SampleSet.RowSample> rows = localDots.Select((t, i) => new SampleSet.RowSample(t, null, rezs[i], null)).ToList(); var samples = new SampleSet("1.dat", rows, approx.LearnSamplesSet.InputAttributes, approx.LearnSamplesSet.OutputAttribute); system = new PCFuzzySystem(samples, samples); var usedRules = GetRules(knowlegeBase); system.RulesDatabaseSet.Add(new KnowlegeBasePCRules(knowlegeBase, null)); }
public static PCFuzzySystem loadUFS(this PCFuzzySystem Classifier, string fileName) { XmlDocument Source = new XmlDocument(); Source.Load(fileName); return(Classifier.loadUFS(Source)); }
public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Approximate, ILearnAlgorithmConf conf) { PCFuzzySystem result = (PCFuzzySystem)Approximate; return(result); }
public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classifier, ILearnAlgorithmConf conf) { result = Classifier; groups = new List <int[]>(); Init(conf); SetPopulation(); Population = SortRules(Population); NS = new int[m]; for (int i = 0; i < m; i++) { NS[i] = (N - 1) / m; } cur_iter = 0; while (cur_iter < iter) { groups = GroupStream(); if (p_one > rand.NextDouble()) { ChooseOneCluster(); } else { ChooseTwoClusters(); } Population = ListPittsburgClassifierTool.SortRules(Population, result); Console.WriteLine(cur_iter + " - Итерация"); Console.WriteLine("Обуч. выборка = " + result.ErrorLearnSamples(Population[0])); Console.WriteLine("Тест. выборка = " + result.ErrorTestSamples(Population[0])); cur_iter++; } Population = ListPittsburgClassifierTool.SortRules(Population, result); result.RulesDatabaseSet[0] = Population[0]; return(result); }
public double Calc_Error(PCFuzzySystem error_checker) { Individ temp_Best = null; double min_error = double.PositiveInfinity; foreach (Individ indiv in the_popualate) { indiv.calc_Error(error_checker); if (min_error > indiv.error) { min_error = indiv.error; temp_Best = indiv; } } if (temp_Best != null) { if (best_individ != null) { if (temp_Best.error < best_individ.error) { best_individ = temp_Best; } } else { best_individ = temp_Best; } } return(min_error); }
//основные вычисления public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classify, ILearnAlgorithmConf conf) { preIterate(Classify, conf); //запуск итераций for (it = 1; it <= iter; it++) { oneIterate(); double y = it; if (y % 10 == 0 & y != 0) { Console.WriteLine(it); for (int p_i = 0; p_i < numberOfPopulations; p_i++) { Console.WriteLine(bestError[p_i]); } } } for (int j = 0; j < Populations.Count; j++) { Console.WriteLine("Популяция №" + j + ":"); Console.WriteLine("Обуч: " + Math.Round(result.ClassifyLearnSamples(BEST[j]), 2)); Console.WriteLine("Тест: " + Math.Round(result.ClassifyTestSamples(BEST[j]), 2)); } if (result.RulesDatabaseSet.Count == 1) { result.RulesDatabaseSet.Clear(); } for (int i = 0; i < Populations.Count; i++) { result.RulesDatabaseSet.Add(BEST[i]); } //Возвращаем результат return(result); }
public override void oneIterate(PCFuzzySystem result) { if (HybrideOcean == null) { HybrideOcean = new PittsburgHybride(result); } base.oneIterate(result); counterGet++; countterSend++; if (countterSend == BorderSend) { countterSend = 0; HybrideOcean.Store(chooseDiscovers(countDiscovers), this.ToString()); } if (counterGet == BorderGet) { counterGet = 0; Outsiders = HybrideOcean.Get(countOutsiders, PittsburgHybride.goodness.best, PittsburgHybride.islandStrategy.All); assimilateOutSiders(); } }
public PCFuzzySystem TuneUpFuzzySystem(PittsburgHybride Ocean, PCFuzzySystem Approximate, ILearnAlgorithmConf conf) { HybrideOcean = Ocean; base.TuneUpFuzzySystem(Approximate, conf); Ocean.Store(chooseDiscovers(1), this.ToString()); return(result); }
public PCFuzzySystem TuneUpFuzzySystem(PittsburgHybride Ocean, PCFuzzySystem Classifier, ILearnAlgorithmConf conf) { HybrideOcean = Ocean; base.TuneUpFuzzySystem(Classifier, conf); Ocean.Store(chooseDiscovers(1), this.ToString()); return(fullFuzzySystem); }
private double Entrophy(PCFuzzySystem result) { int m = result.LearnSamplesSet.CountSamples; List <double> probability = new List <double>(); for (int j = 0; j < result.LearnSamplesSet.OutputAttribute.LabelsValues.Count; j++) { int counter = 0; for (int i = 0; i < result.LearnSamplesSet.DataRows.Count; i++) { if (result.LearnSamplesSet.DataRows[i].StringOutput == result.LearnSamplesSet.OutputAttribute.LabelsValues[j]) { counter++; } } probability.Add(Convert.ToDouble(counter) / Convert.ToDouble(m)); } double entrophy = 0; for (int i = 0; i < probability.Count; i++) { if (probability[i] != 0) { entrophy += probability[i] * Math.Log(probability[i], 2); } } entrophy *= -1; return(entrophy); }
protected void InitRulesBySamples(PCFuzzySystem Classifier, TypeTermFuncEnum typeFunc) { if ((Classifier.RulesDatabaseSet == null) || (Classifier.RulesDatabaseSet.Count == 0)) { KnowlegeBasePCRules temp_rules = new KnowlegeBasePCRules(); Classifier.RulesDatabaseSet.Add(temp_rules); } for (int i = 0; i < Classifier.CountClass; i++) { if (!ExistClassFeatureMax(i) || !ExistClassFeatureMin(i)) { continue; } int[] order_terms = new int[Classifier.CountFeatures]; for (int j = 0; j < Classifier.CountFeatures; j++) { if (Classifier.AcceptedFeatures[j] == false) { continue; } double[] paramerts = new double[Term.CountParamsinSelectedTermType(typeFunc)]; switch (typeFunc) { case TypeTermFuncEnum.Треугольник: paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]); paramerts[2] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[i][j]); paramerts[1] = (paramerts[0] + paramerts[2]) / 2; break; case TypeTermFuncEnum.Гауссоида: paramerts[0] = (max_for_class[i][j] + min_for_class[i][j]) / 2; paramerts[1] = (paramerts[0] - min_for_class[i][j]) / 3; // rule of 3g break; case TypeTermFuncEnum.Парабола: paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]); paramerts[1] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[i][j]); break; case TypeTermFuncEnum.Трапеция: paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]); paramerts[3] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[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, typeFunc, j); Classifier.RulesDatabaseSet[0].TermsSet.Add(temp_term); order_terms[j] = Classifier.RulesDatabaseSet[0].TermsSet.Count - 1; } PCRule temp_Rule = new PCRule(Classifier.RulesDatabaseSet[0].TermsSet, order_terms, Classifier.LearnSamplesSet.OutputAttribute.LabelsValues[i], 1); Classifier.RulesDatabaseSet[0].RulesDatabase.Add(temp_Rule); } }
public virtual void preIterate(PCFuzzySystem Classify, ILearnAlgorithmConf conf) { result = new PCFuzzySystem(Classify.LearnSamplesSet, Classify.TestSamplesSet); result.RulesDatabaseSet.Add(new KnowlegeBasePCRules(Classify.RulesDatabaseSet[0])); rand = new Random(); //Инициализируем параметры Init(conf); //Инициализируем и зануляем вектора алгоритма HeadLeader = new List <KnowlegeBasePCRules>(); VelocityVector = new List <KnowlegeBasePCRules>(); VelocityVectorLL = new List <KnowlegeBasePCRules>(); VelocityVectorHL = new List <KnowlegeBasePCRules>(); SSVector = new List <KnowlegeBasePCRules>(); for (int i = 0; i < numberOfPopulations; i++) { HeadLeader.Add(new KnowlegeBasePCRules(result.RulesDatabaseSet[0])); VelocityVector.Add(new KnowlegeBasePCRules(result.RulesDatabaseSet[0])); VelocityVectorLL.Add(new KnowlegeBasePCRules(result.RulesDatabaseSet[0])); VelocityVectorHL.Add(new KnowlegeBasePCRules(result.RulesDatabaseSet[0])); SSVector.Add(new KnowlegeBasePCRules(result.RulesDatabaseSet[0])); } for (int p_i = 0; p_i < numberOfPopulations; p_i++) { for (int i = 0; i < VelocityVector[p_i].TermsSet.Count; i++) { for (int j = 0; j < VelocityVector[p_i].TermsSet[i].Parametrs.Length; j++) { HeadLeader[p_i].TermsSet[i].Parametrs[j] = 0; VelocityVector[p_i].TermsSet[i].Parametrs[j] = 0; VelocityVectorLL[p_i].TermsSet[i].Parametrs[j] = 0; VelocityVectorHL[p_i].TermsSet[i].Parametrs[j] = 0; } } } //Создаем популяции и архив лучших положений каждой частицы Populations = new List <List <KnowlegeBasePCRules> >(); for (int i = 0; i < numberOfPopulations; i++) { Populations.Add(SetPopulation(new List <KnowlegeBasePCRules>())); } ParticlesBest = new List <Dictionary <KnowlegeBasePCRules, KnowlegeBasePCRules> >(); for (int p_i = 0; p_i < Populations.Count; p_i++) { ParticlesBest.Add(new Dictionary <KnowlegeBasePCRules, KnowlegeBasePCRules>()); foreach (var Particle in Populations[p_i]) { ParticlesBest[p_i].Add(Particle, Universal); } } //Инициализируем роли частиц LocalLeaders = new List <KnowlegeBasePCRules[]>(); ExplorerParticles = new List <KnowlegeBasePCRules[]>(); AimlessParticles = new List <KnowlegeBasePCRules[]>(); for (int p_i = 0; p_i < Populations.Count; p_i++) { LocalLeaders.Add(new KnowlegeBasePCRules[numberOfLocalLeaders]); ExplorerParticles.Add(new KnowlegeBasePCRules[numberOfAllParts - numberOfAimlessParts - numberOfLocalLeaders - 1]); AimlessParticles.Add(new KnowlegeBasePCRules[numberOfAimlessParts]); } }
private double Entrophy(PCFuzzySystem result, int x, int level) { int m = result.LearnSamplesSet.CountSamples; List <double> probability = new List <double>(); for (int j = 1; j <= level; j++) { int counter = 0; for (int i = 0; i < result.LearnSamplesSet.DataRows.Count; i++) { if (result.LearnSamplesSet.DataRows[i].InputAttributeValue[x] == j) { counter++; } } probability.Add(Convert.ToDouble(counter) / Convert.ToDouble(m)); } double entrophy = 0; for (int i = 0; i < probability.Count; i++) { if (probability[i] != 0) { entrophy += probability[i] * Math.Log(probability[i], 2); } } entrophy *= -1; return(entrophy); }
public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classify, ILearnAlgorithmConf conf) { preIterate(Classify, conf); //Оптимизируем параметры iter = 1; while (iter <= MaxIter) { if (iter % changeParts == 0) { swapParticles(); } oneIterate(); } //Выводим точность классификации для лучшей частицы из каждой популяции for (int j = 0; j < Populations.Count; j++) { Populations[j] = ListPittsburgClassifierTool.SortRules(Populations[j], result); Console.WriteLine("Популяция №" + j + ":"); Console.WriteLine("Обуч: " + Math.Round(result.ClassifyLearnSamples(Populations[j][0]), 2)); Console.WriteLine("Тест: " + Math.Round(result.ClassifyTestSamples(Populations[j][0]), 2)); } //Находим самое лучшее решение из всех популяций List <KnowlegeBasePCRules> BestPopulation = new List <KnowlegeBasePCRules>(); for (int i = 0; i < numberOfPopulations; i++) { BestPopulation.Add(Populations[i][0]); } BestPopulation = ListPittsburgClassifierTool.SortRules(BestPopulation, result); result.RulesDatabaseSet[0] = BestPopulation[0]; //Возвращаем результат return(result); }
public override PCFuzzySystem Generate(PCFuzzySystem Classifier, IGeneratorConf config) { PCFuzzySystem result = Classifier; 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 < Classifier.CountFeatures; i++) { int count_terms_for_var = Classifier.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 = Classifier.RulesDatabaseSet[0].TermsSet[0].TermFuncType; Generate_all_variant_in_pool(Varians_of_run_system); for (int i = 0; i < Pull_of_systems.Count; i++) { Classifier.RulesDatabaseSet.Clear(); GeneratorRulesEveryoneWithEveryone.InitRulesEveryoneWithEveryone(Classifier, type_of_term, Pull_of_systems[i].ToArray()); Systems_ready_to_test.Add(Classifier.RulesDatabaseSet[0]); errors_of_systems.Add(result.ErrorLearnSamples(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 PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classifier, ILearnAlgorithmConf conf) { BacteryAlgorithmConfig Config = conf as BacteryAlgorithmConfig; sendBactery = Config.BFOCountSolution; interPSOtoSend = Config.BFOCountIteration; result = Classifier; if (result.RulesDatabaseSet.Count < 1) { throw new InvalidDataException("Нечеткая система не проинициализированна"); } KnowlegeBasePCRules backSave = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]); double backResult = result.ErrorLearnSamples(result.RulesDatabaseSet[0]); savetoUFS(result.RulesDatabaseSet, 0, 0, 0); BacteryRunner(); KnowlegeBasePCRules[] solutions = loadDatabase(); solutions = sortSolution(solutions); if (solutions.Count() < 1) { result.RulesDatabaseSet[0] = backSave; return(result); } result.RulesDatabaseSet[0] = solutions[0]; double newResult = result.ErrorLearnSamples(result.RulesDatabaseSet[0]); if (newResult > backResult) { result.RulesDatabaseSet[0] = backSave; } result.RulesDatabaseSet[0].TermsSet.Trim(); return(result); }
public region2(List <region_side> sides, PCFuzzySystem approx, List <input_space> variable_spaces) { this.sides = new List <region_side>(sides.Count); this.sides.AddRange(sides); this.approx = approx; get_dots(approx.LearnSamplesSet.DataRows); this.variable_spaces = variable_spaces; }
public double getGoodsImproove(PCFuzzySystem FS, double baseValue) { thePositionOfBee = checkAndCorrect(thePositionOfBee); FS.AcceptedFeatures = thePositionOfBee; accuracy = FS.ClassifyLearnSamples(FS.RulesDatabaseSet[0]); goods = accuracy - baseValue; return(goods); }
public virtual void oneIterate(PCFuzzySystem result) { 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].TermsSet.Count; k++) { for (int q = 0; q < X[j].TermsSet[k].CountParams; q++) { double bp = Pi[j].TermsSet[k].Parametrs[q]; V[j].TermsSet[k].Parametrs[q] = V[j].TermsSet[k].Parametrs[q] * w + c1 * rnd.NextDouble() * (bp - X[j].TermsSet[k].Parametrs[q]) + c2 * rnd.NextDouble() * (Pg.TermsSet[k].Parametrs[q] - X[j].TermsSet[k].Parametrs[q]); X[j].TermsSet[k].Parametrs[q] += V[j].TermsSet[k].Parametrs[q]; } } double[] bf = new double[V[j].Weigths.Length]; double[] bfw = new double[V[j].Weigths.Length]; for (int k = 0; k < V[j].Weigths.Length; k++) { bfw[k] = V[j].Weigths[k] * w + c1 * rnd.NextDouble() * (Pi[j].Weigths[k] - X[j].Weigths[k]) + c2 * rnd.NextDouble() * (Pg.Weigths[k] - X[j].Weigths[k]); double sw = X[j].Weigths[k] + bfw[k]; if (sw > 0 && sw <= 2) { bf[k] = sw; } else { bf[k] = X[j].Weigths[k]; bfw[k] = V[j].Weigths[k]; } } X[j].Weigths = bf; V[j].Weigths = bfw; double newError = 0; bool success = true; try { newError = result.ClassifyLearnSamples(X[j]); } catch (Exception) { success = false; } if (success && (newError > Errors[j])) { OldErrors[j] = Errors[j]; Errors[j] = newError; Pi[j] = new KnowlegeBasePCRules(X[j]); } if (minError < newError) { minError = newError; Pg = new KnowlegeBasePCRules(X[j]); } } }