private string ErrorInfoTSA(IFuzzySystem FS) { TSAFuzzySystem IFS = FS as TSAFuzzySystem; 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])); // Console.WriteLine($"Time\t{IFS.sw.ElapsedMilliseconds} {Environment.NewLine }Ticks\t{IFS.sw.ElapsedTicks}"); 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); }
private static void writeAboutEstimates(XmlWriter writer, TSAFuzzySystem 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(); }
public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approx, ILearnAlgorithmConf conf) // Здесь ведется оптимизация вашим алгоритмом { theFuzzySystem = Approx; iterMax = ((gsa_conf)conf).Количество_итераций; MCount = ((gsa_conf)conf).Количество_частиц; G0 = ((gsa_conf)conf).Гравитационная_постоянная; alpha = ((gsa_conf)conf).Коэффициент_уменьшения; epsilon = ((gsa_conf)conf).Малая_константа; X = new KnowlegeBaseTSARules[MCount]; Errors = new double[MCount]; mass = new double[MCount]; double ErrorBest; KnowlegeBaseTSARules BestSolution; double minValue; int iminIndex; KnowlegeBaseTSARules temp_c_Rule = new KnowlegeBaseTSARules(theFuzzySystem.RulesDatabaseSet[0]); X[0] = temp_c_Rule; Errors[0] = theFuzzySystem.RMSEtoMSEforLearn(theFuzzySystem.approxLearnSamples(X[0])); double ErrorZero = Errors[0]; ErrorBest = ErrorZero; BestSolution = temp_c_Rule; //number = X[0].TermsSet.Count * X[0].TermsSet[0].Parametrs.Count(); R = new double[MCount][, , ]; speed = new double[MCount, X[0].TermsSet.Count, X[0].TermsSet[0].Parametrs.Count()]; for (int i = 0; i < MCount; i++) { R[i] = new double[MCount, X[0].TermsSet.Count, X[0].TermsSet[0].Parametrs.Count()]; } RR = new double[MCount, MCount]; a = new double[MCount, X[0].TermsSet.Count, X[0].TermsSet[0].Parametrs.Count()]; for (int i = 1; i < MCount; i++) { temp_c_Rule = new KnowlegeBaseTSARules(theFuzzySystem.RulesDatabaseSet[0]); X[i] = temp_c_Rule; for (int j = 0; j < X[i].TermsSet.Count; j++) { for (int k = 0; k < X[i].TermsSet[j].Parametrs.Count(); k++) { X[i].TermsSet[j].Parametrs[k] = GaussRandom.Random_gaussian(rand, X[i].TermsSet[j].Parametrs[k], 0.1 * (X[i].TermsSet[j].Parametrs[k])) + theFuzzySystem.LearnSamplesSet.InputAttributes[X[i].TermsSet[j].NumVar].Scatter * 0.05; } } theFuzzySystem.RulesDatabaseSet.Add(X[i]); theFuzzySystem.UnlaidProtectionFix(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]); Errors[i] = theFuzzySystem.RMSEtoMSEforLearn(theFuzzySystem.approxLearnSamples(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1])); X[i] = theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]; theFuzzySystem.RulesDatabaseSet.Remove(X[i]); } for (int iter = 0; iter < iterMax; iter++) { //g(t) = G(0)*e^(-a*t/T); G = G0 * Math.Pow(Math.E, ((-1) * alpha * iter / iterMax)); /* if (iter >= 100) { * Console.WriteLine("Wait"); * }*/ algorithm(); for (int r = 0; r < MCount; r++) { theFuzzySystem.RulesDatabaseSet.Add(X[r]); theFuzzySystem.UnlaidProtectionFix(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]); Errors[r] = theFuzzySystem.RMSEtoMSEforLearn(theFuzzySystem.approxLearnSamples(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1])); X[r] = theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]; theFuzzySystem.RulesDatabaseSet.Remove(X[r]); } minValue = Errors.Min(); iminIndex = Errors.ToList().IndexOf(minValue); if (minValue < ErrorBest) { ErrorBest = minValue; BestSolution = new KnowlegeBaseTSARules(X[iminIndex]); } } if (ErrorBest < ErrorZero) { theFuzzySystem.RulesDatabaseSet[0] = BestSolution; } return(theFuzzySystem); }
private void weight() { double sum = 0; double worst = mass[0]; double best = mass[0]; int[] index = new Int32[MCount]; int count = 0; for (int i = 1; i < MCount; i++) { mass[i] = Errors[i]; if (mass[i] > worst) { worst = mass[i]; } if (mass[i] < best) { best = mass[i]; } } for (int i = 0; i < MCount; i++) { if (mass[i] == worst) { count++; index[count - 1] = i; } } if (count > 1) { for (int i = 1; i < count; i++) { ///X[index[i]] = ; int f = index[i]; KnowlegeBaseTSARules temp_c_Rule = new KnowlegeBaseTSARules(theFuzzySystem.RulesDatabaseSet[0]); temp_c_Rule = new KnowlegeBaseTSARules(theFuzzySystem.RulesDatabaseSet[0]); X[f] = temp_c_Rule; for (int j = 0; j < X[f].TermsSet.Count; j++) { for (int k = 0; k < X[f].TermsSet[j].Parametrs.Count(); k++) { X[f].TermsSet[j].Parametrs[k] = GaussRandom.Random_gaussian(rand, X[f].TermsSet[j].Parametrs[k], 0.1 * (X[f].TermsSet[j].Parametrs[k])) + theFuzzySystem.LearnSamplesSet.InputAttributes[X[f].TermsSet[j].NumVar].Scatter * 0.05; } } theFuzzySystem.RulesDatabaseSet.Add(X[f]); theFuzzySystem.UnlaidProtectionFix(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]); Errors[f] = theFuzzySystem.RMSEtoMSEforLearn(theFuzzySystem.approxLearnSamples(theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1])); X[f] = theFuzzySystem.RulesDatabaseSet[theFuzzySystem.RulesDatabaseSet.Count - 1]; theFuzzySystem.RulesDatabaseSet.Remove(X[f]); mass[f] = Errors[f]; if (mass[f] > worst) { i--; } } } for (int i = 0; i < MCount; i++) { mass[i] = (mass[i] - worst) / (best - worst); sum = sum + mass[i]; } for (int i = 0; i < MCount; i++) { mass[i] = mass[i] / sum; } }