public override SAFuzzySystem TuneUpFuzzySystem(SAFuzzySystem Approx, ILearnAlgorithmConf conf) { result = Approx; List <int[]> groups = new List <int[]>(); Init(conf); SetPopulation(); Population = ListSingletonApproximateTool.SortRules(Population, result); 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; /*StringBuilder sb = new StringBuilder(); * sb.AppendLine("sep=.");*/ for (int i = 1; i <= MaxIter; i++) { Console.Clear(); Console.WriteLine((double)i * 100 / MaxIter + "%"); 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; } //sb.AppendLine((result.RMSEtoMSEforLearn(result.approxLearnSamples(Population[0]))).ToString() + "." + (result.RMSEtoMSEforTest(result.approxTestSamples(Population[0]))).ToString()); } /*FileStream file1 = new FileStream("F:\\Table.scv", FileMode.Create); * StreamWriter writer = new StreamWriter(file1); * writer.Write(sb); * writer.Close(); * file1.Close();*/ Console.WriteLine(ToString(true)); Console.WriteLine("Итер - " + BestIter + " MSET - " + BestMSETest + " MSEL - " + BestMSELearn); result.RulesDatabaseSet[0] = Population[0]; return(result); }
public override SAFuzzySystem TuneUpFuzzySystem(SAFuzzySystem Approx, ILearnAlgorithmConf conf) { result = Approx; Init(conf); HeadLeader = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); VelocityVector = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); VelocityVectorLL = new KnowlegeBaseSARules(result.RulesDatabaseSet[0]); VelocityVectorHL = new KnowlegeBaseSARules(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 <KnowlegeBaseSARules, KnowlegeBaseSARules>(); foreach (var Particle in Population) { ParticlesBest.Add(Particle, Universal); } LocalLeaders = new KnowlegeBaseSARules[numberOfLocalLeaders]; Console.WriteLine(LocalLeaders.Length); ExplorerParticles = new KnowlegeBaseSARules[numberOfAllParts - numberOfAimlessParts - numberOfLocalLeaders - 1]; Console.WriteLine(ExplorerParticles.Length); AimlessParticles = new KnowlegeBaseSARules[numberOfAimlessParts]; Console.WriteLine(AimlessParticles.Length); while (iter < MaxIter) { Population = ListSingletonApproximateTool.SortRules(Population, result); SetRoles(); ChangeExplorersPositions(); ChangeAimlessPositions(); DiscardRoles(); iter++; Console.WriteLine("Iteration: " + iter.ToString()); Console.WriteLine(result.RMSEtoMSEforLearn(result.approxLearnSamples(Population[0]))); Console.WriteLine(result.RMSEtoMSEforTest(result.approxTestSamples(Population[0]))); Console.WriteLine(result.approxLearnSamples(Population[numberOfLocalLeaders + 1])); } result.RulesDatabaseSet[0] = Population[0]; return(result); }
private void addApproxValue(SAFuzzySystem Approx) { double Value = Approx.approxLearnSamples(Approx.RulesDatabaseSet[0]); ValueLGoodsRMSE.Add(Value); ValueLGoodsMSE.Add(Approx.RMSEtoMSEforLearn(Value)); Value = Approx.approxTestSamples(Approx.RulesDatabaseSet[0]); ValueTGoodsRMSE.Add(Value); ValueTGoodsMSE.Add(Approx.RMSEtoMSEforTest(Value)); Value = Approx.getComplexit(); ValueComplexityFull.Add(Value); Value = Approx.getRulesCount(); ValueComplexityRules.Add(Value); Value = Approx.getNormalIndex(); ValueInterpretyNominal.Add(Value); Value = Approx.getIndexReal(); ValueInterpretyReal.Add(Value); }
private string ErrorInfoSA(IFuzzySystem FS) { SAFuzzySystem IFS = FS as SAFuzzySystem; if (IFS.RulesDatabaseSet.Count < 1) { return("Точность нечеткой системы недоступна"); } approxLearnResult.Add(IFS.approxLearnSamples(IFS.RulesDatabaseSet[0])); approxTestResult.Add(IFS.approxTestSamples(IFS.RulesDatabaseSet[0])); approxLearnResultMSE.Add(IFS.RMSEtoMSEforLearn(approxLearnResult[approxLearnResult.Count - 1])); approxTestResultMSE.Add(IFS.RMSEtoMSEforTest(approxTestResult[approxTestResult.Count - 1])); approxLearnResultMSEdiv2.Add(IFS.RMSEtoMSEdiv2forLearn(approxLearnResult[approxLearnResult.Count - 1])); approxTestResultMSEdiv2.Add(IFS.RMSEtoMSEdiv2forTest(approxTestResult[approxTestResult.Count - 1])); return("Точностью на обучающей выборке(RSME) " + approxLearnResult [approxLearnResult.Count - 1].ToString() + " , Точность на тестовой выборке(RMSE) " + approxTestResult[approxTestResult.Count - 1].ToString() + " " + Environment.NewLine + "Точностью на обучающей выборке(MSE) " + approxLearnResultMSE[approxLearnResultMSE.Count - 1].ToString() + " , Точность на тестовой выборке(MSE) " + approxTestResultMSE[approxTestResultMSE.Count - 1].ToString() + " " + Environment.NewLine + "Точностью на обучающей выборке(MSE/2) " + approxLearnResultMSEdiv2[approxLearnResultMSEdiv2.Count - 1].ToString() + " , Точность на тестовой выборке(MSE/2) " + approxTestResultMSEdiv2[approxTestResultMSEdiv2.Count - 1].ToString() + " " + Environment.NewLine); }
protected override void make_Log(Log_line EventCall, SAFuzzySystem FS = null, string name_Alg = "", DateTime TimerValue = new DateTime(), TimeSpan TimerSpan = new TimeSpan()) { switch (EventCall) { case Log_line.Start: { LOG += "(" + TimerValue.ToString() + ")" + " Начало построения системы" + Environment.NewLine; break; } case Log_line.StartGenerate: { LOG += "(" + TimerValue.ToString() + ")" + " Начата генерация системы" + Environment.NewLine; break; } case Log_line.StartOptimaze: { LOG += "(" + DateTime.Now.ToString() + ")" + " Начата оптимизация системы" + Environment.NewLine; break; } case Log_line.PreGenerate_log: { LOG += "(" + DateTime.Now.ToString() + ")" + " Генерация алгоритмом " + name_Alg.ToString() + Environment.NewLine; break; } case Log_line.PostGenerate_log: { double LearnResult = FS.approxLearnSamples(); double TestResult = FS.approxTestSamples(); double LearnResultMSE = FS.RMSEtoMSEforLearn(LearnResult); double TestResultMSE = FS.RMSEtoMSEforTest(TestResult); double LearnResultMSEdiv2 = FS.RMSEtoMSEdiv2forLearn(LearnResult); double TestResultMSEdiv2 = FS.RMSEtoMSEdiv2forTest(TestResult); LOG += "(" + DateTime.Now.ToString() + ")" + " Сгенерирована система сложностью " + FS.ValueComplexity().ToString() + Environment.NewLine + "Точностью на обучающей выборке(RSME) " + LearnResult.ToString() + ", Точность на тестовой выборке(RMSE) " + TestResult.ToString() + Environment.NewLine + "Точностью на обучающей выборке(MSE) " + LearnResultMSE.ToString() + ", Точность на тестовой выборке(MSE) " + TestResultMSE.ToString() + Environment.NewLine + "Точностью на обучающей выборке(MSE/2) " + LearnResultMSEdiv2.ToString() + ", Точность на тестовой выборке(MSE/2) " + TestResultMSEdiv2.ToString() + Environment.NewLine; LOG += "Использован " + name_Alg.ToString() + Environment.NewLine; break; } case Log_line.PreOptimaze_log: { LOG += "(" + DateTime.Now.ToString() + ")" + " Оптимизация алгоритмом " + name_Alg.ToString() + Environment.NewLine; break; } case Log_line.PostOptimaze_log: { double LearnResult = FS.approxLearnSamples(); double TestResult = FS.approxTestSamples(); double LearnResultMSE = FS.RMSEtoMSEforLearn(LearnResult); double TestResultMSE = FS.RMSEtoMSEforTest(TestResult); double LearnResultMSEdiv2 = FS.RMSEtoMSEdiv2forLearn(LearnResult); double TestResultMSEdiv2 = FS.RMSEtoMSEdiv2forTest(TestResult); LOG += "(" + DateTime.Now.ToString() + ")" + " оптимизированная система сложностью " + FS.ValueComplexity().ToString() + Environment.NewLine + "Точностью на обучающей выборке(RMSE) " + LearnResult.ToString() + ", Точность на тестовой выборке(RMSE) " + TestResult.ToString() + Environment.NewLine + "Точностью на обучающей выборке(MSE) " + LearnResultMSE.ToString() + ", Точность на тестовой выборке(MSE) " + TestResultMSE.ToString() + Environment.NewLine + "Точностью на обучающей выборке(MSE/2) " + LearnResultMSEdiv2.ToString() + ", Точность на тестовой выборке(MSE/2) " + TestResultMSEdiv2.ToString() + Environment.NewLine; LOG += "Использован " + name_Alg.ToString() + Environment.NewLine; break; } case Log_line.EndCircle: { LOG += "(" + DateTime.Now.ToString() + ")" + " Время построения системы" + TimerSpan.TotalSeconds.ToString() + Environment.NewLine; break; } case Log_line.End: { LOG += "(" + DateTime.Now.ToString() + ")" + " Время построения всех систем" + TimerSpan.TotalSeconds.ToString() + Environment.NewLine; break; } default: { LOG += "Не верный вызов" + Environment.NewLine; break; } } }
protected static void writeAboutEstimates(XmlWriter writer, SAFuzzySystem Approximate) { writer.WriteStartElement("Estimates"); if (Approximate.TestSamplesSet != null) { writer.WriteAttributeString("Count", XmlConvert.ToString(22)); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.LearnSamplesSet.FileName); writer.WriteAttributeString("Type", "RMSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.approxLearnSamples(Approximate.RulesDatabaseSet[0]))); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.LearnSamplesSet.FileName); writer.WriteAttributeString("Type", "MSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.RMSEtoMSEforLearn(Approximate.approxLearnSamples(Approximate.RulesDatabaseSet[0])))); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.TestSamplesSet.FileName); writer.WriteAttributeString("Type", "RMSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.approxTestSamples(Approximate.RulesDatabaseSet[0]))); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.TestSamplesSet.FileName); writer.WriteAttributeString("Type", "MSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.RMSEtoMSEforTest(Approximate.approxTestSamples(Approximate.RulesDatabaseSet[0])))); writer.WriteEndElement(); } else { writer.WriteAttributeString("Count", XmlConvert.ToString(20)); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.LearnSamplesSet.FileName); writer.WriteAttributeString("Type", "RMSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.approxLearnSamples(Approximate.RulesDatabaseSet[0]))); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Table", Approximate.LearnSamplesSet.FileName); writer.WriteAttributeString("Type", "MSE"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.RMSEtoMSEforLearn(Approximate.approxLearnSamples(Approximate.RulesDatabaseSet[0])))); writer.WriteEndElement(); } writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GIBNormal"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGIBNormal())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GIBSumStraigh"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGIBSumStrait())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GIBSumReverse"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGIBSumReverse())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GICNormal"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGICNormal())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GICSumStraigh"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGICSumStraigth())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GICSumReverse"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGICSumReverce())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GISNormal"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGISNormal())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GISSumStraigh"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGISSumStraigt())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "GISSumReverce"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getGISSumReverce())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "LindisNormal"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getLindisNormal())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "LindisSumStraigh"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getLindisSumStraight())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "LindisSumReverse"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getLindisSumReverse())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "NormalIndex"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getNormalIndex())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "RealIndex"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getIndexReal())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "SumStraigthIndex"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getIndexSumStraigt())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "SumReverseIndex"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getIndexSumReverse())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "ComplexitIt"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getComplexit())); writer.WriteEndElement(); writer.WriteStartElement("Estimate"); writer.WriteAttributeString("Type", "CountRules"); writer.WriteAttributeString("Value", XmlConvert.ToString(Approximate.getRulesCount())); writer.WriteEndElement(); writer.WriteEndElement(); }