private void ChangeExplorerPositions(int i) { KnowlegeBaseTSARules temp = new KnowlegeBaseTSARules(); temp = ExplorerParticles[i]; for (int k = 0; k < temp.TermsSet.Count; k++) { for (int j = 0; j < temp.TermsSet[k].Parametrs.Length; j++) { temp.TermsSet[k].Parametrs[j] += VelocityVector.TermsSet[k].Parametrs[j]; } } if (result.approxLearnSamples(ExplorerParticles[i]) < result.approxLearnSamples(ParticlesBest[ExplorerParticles[i]])) { ParticlesBest.Remove(ExplorerParticles[i]); ParticlesBest.Add(temp, ExplorerParticles[i]); } else { KnowlegeBaseTSARules tmp = new KnowlegeBaseTSARules(); tmp = ParticlesBest[ExplorerParticles[i]]; ParticlesBest.Remove(ExplorerParticles[i]); ParticlesBest.Add(temp, tmp); } ExplorerParticles[i] = temp; }
private KnowlegeBaseTSARules[] SortRules(KnowlegeBaseTSARules[] Source) { double[] keys = new double[Source.Count()]; KnowlegeBaseTSARules[] tempSol = Source.Clone() as KnowlegeBaseTSARules[]; for (int i = 0; i < Source.Count(); i++) { keys[i] = result.approxLearnSamples(Source[i]); } Array.Sort(keys, tempSol); return(Source); }
public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approximate, ILearnAlgorithmConf Conf) { result = Approximate; List <int[]> groups = new List <int[]>(); Init(Conf); SetPopulation(); Population = SortRules(Population); NS = new int[Nsr]; NS = SetNS(Population, Nsr); groups = GroupStream(); double BestMSETest = result.RMSEtoMSEforTest(result.approxTestSamples(Population[0])); double BestMSELearn = result.RMSEtoMSEforLearn(result.approxLearnSamples(Population[0])); int BestIter = 0; for (int i = 1; i <= MaxIter; i++) { Console.WriteLine(i + " - Итерация"); Population = SetNextPosition(groups, Population); Population = Replacement(groups, Population); if (flag) { Evaporation(groups.Last());//Испарение } if (BestMSETest > result.RMSEtoMSEforTest(result.approxTestSamples(Population[0]))) { BestMSETest = result.RMSEtoMSEforTest(result.approxTestSamples(Population[0])); BestMSELearn = result.RMSEtoMSEforLearn(result.approxLearnSamples(Population[0])); BestIter = i; } } Console.WriteLine(ToString(true)); Console.WriteLine("Итер - " + BestIter + " MSET - " + BestMSETest + " MSEL - " + BestMSELearn); result.RulesDatabaseSet[0] = Population[0]; return(result); }
public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approx, ILearnAlgorithmConf conf) { result = Approx; Init(conf); HeadLeader = new KnowlegeBaseTSARules(result.RulesDatabaseSet[0]); VelocityVector = new KnowlegeBaseTSARules(result.RulesDatabaseSet[0]); VelocityVectorLL = new KnowlegeBaseTSARules(result.RulesDatabaseSet[0]); VelocityVectorHL = new KnowlegeBaseTSARules(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 <KnowlegeBaseTSARules, KnowlegeBaseTSARules>(); foreach (var Particle in Population) { ParticlesBest.Add(Particle, Universal); } LocalLeaders = new KnowlegeBaseTSARules[numberOfLocalLeaders]; ExplorerParticles = new KnowlegeBaseTSARules[numberOfAllParts - numberOfAimlessParts - numberOfLocalLeaders - 1]; AimlessParticles = new KnowlegeBaseTSARules[numberOfAimlessParts]; iter = 0; while (iter < MaxIter) { Population = ListTakagiSugenoApproximateTool.SortRules(Population, result); SetRoles(); ChangeExplorersPositions(); ChangeAimlessPositions(); DiscardRoles(); if (iter == (MaxIter - 1) || iter == 0) { Console.WriteLine("Iteration: " + (iter + 1).ToString()); Console.WriteLine(Math.Round(result.RMSEtoMSEforLearn(result.approxLearnSamples(Population[0])), 3)); Console.WriteLine(Math.Round(result.RMSEtoMSEforTest(result.approxTestSamples(Population[0])), 3)); } iter++; } result.RulesDatabaseSet[0] = Population[0]; return(result); }