Пример #1
0
        public static void writeAboutTable(XmlWriter writer, SampleSet samplesSet, IFuzzySystem Classifier)
        {
            writer.WriteStartElement("Table");
            writer.WriteAttributeString("Name", samplesSet.FileName);
            if (samplesSet == Classifier.LearnSamplesSet)
            {
                writer.WriteAttributeString("Type", "Training");
            }
            else
            {
                writer.WriteAttributeString("Type", "Testing");
            }
            writer.WriteAttributeString("Output", samplesSet.OutputAttribute.Name);
            writer.WriteStartElement("Attributes");
            writer.WriteAttributeString("Count", XmlConvert.ToString(samplesSet.CountVars + 1));
            for (int i = 0; i < samplesSet.CountVars; i++)
            {
                writeAboutAttribute(writer, samplesSet.InputAttributes[i]);
            }
            writeAboutAttribute(writer, samplesSet.OutputAttribute);
            writer.WriteEndElement();
            writeAboutRows(writer, samplesSet);


            writer.WriteEndElement();
        }
Пример #2
0
 public IFuzzySystem UniversalMethod(IFuzzySystem FSystem, ILearnAlgorithmConf conf)
 {
     init(FSystem, conf);
     for (int m = 0; m < max_Features; m++)
     {
         for (int i = 0; i < FSystem.CountFeatures; i++)
         {
             if (BestSolute[i] == true)
             {
                 continue;
             }
             test.Add(BestSolute.Clone() as bool[]);
             test[test.Count - 1][i]  = true;
             FSystem.AcceptedFeatures = test[test.Count - 1];
             Errors.Add(FSystem.ErrorLearnSamples(FSystem.AbstractRulesBase()[0]));
         }
         int best = Errors.IndexOf(Errors.Min());
         BestSolute = test[best].Clone() as bool[];
         FSystem.AcceptedFeatures = BestSolute;
         Storage.Add(new FeatureSelectionModel(FSystem, BestSolute));
         test.Clear();
         Errors.Clear();
     }
     Storage = FeatureSelectionModel.Distinct(Storage);
     FeatureSelectionModel.Sort(Storage, SortWay);
     return(FSystem);
 }
Пример #3
0
        private void save_FS(IFuzzySystem FS, string Name_alg)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string file_name = DateTime.Now.ToLongDateString() + " " + DateTime.Now.TimeOfDay.ToString("hh','mm','ss") + " (" + Thread.CurrentThread.ManagedThreadId.ToString() + ") {" + Name_alg + "}.ufs";

            writeIFuzzySystemUFS(FS, path + file_name);
        }
Пример #4
0
        private void BrowseB_Click(object sender, EventArgs e)
        {
            if (openFSDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = openFSDialog.FileName;
                if (File.Exists(fileName))
                {
                    tempTable = BaseUFSLoader.LoadLearnFromUFS(fileName);

                    temptestTable = BaseUFSLoader.LoadTestFromUFS(fileName);

                    FSystem = BaseUFSLoader.LoadUFS(fileName, out TSystem);

                    switch (TSystem)
                    {
                    case FuzzySystemRelisedList.TypeSystem.PittsburghClassifier:
                    {
                        PCFS = FSystem as PCFuzzySystem;

                        break;
                    }

                    case FuzzySystemRelisedList.TypeSystem.Singletone:
                    {
                        SAFS = FSystem as SAFuzzySystem;
                        break;
                    }

                    case FuzzySystemRelisedList.TypeSystem.TakagiSugenoApproximate:
                    {
                        TSAFS = FSystem as TSAFuzzySystem;

                        break;
                    }
                    }


                    NamesOfTerms = new String[getCountVars()][];
                    indexofTerm  = new int[getCountVars()][];
                    makeNamesforAll();

                    FeatureCB.Items.Clear();
                    for (int i = 0; i < getCountVars(); i++)
                    {
                        FeatureCB.Items.Add(getNameAttribute(i));
                    }
                    FeatureCB.SelectedIndex = 0;
                    MakeRulesB.Enabled      = true;
                    RulesRTB.Text           = "";
                }
            }
        }
Пример #5
0
        public IFuzzySystem UniversalMethod(IFuzzySystem FSystem, ILearnAlgorithmConf config)
        {
            init(FSystem, config);


            ////////////////////////////////////////////////////////////////////////////////////Первоначальная генерация
            for (int u = 0; u < MCount; u++)
            {
                ///Создаем частицу
                for (int i = 0; i < max_Features; i++)
                {
                    if (rand.NextDouble() > 0.5)
                    {
                        Solute[i] = true;
                    }
                    else
                    {
                        Solute[i] = false;
                    }
                }
                ///Проверяем, есть ли признаки. Если частица пуста, рандомный признак становится единицей
                if (Solute.Count(x => x == true) == 0)
                {
                    BestSolute[rand.Next(BestSolute.Count())] = true;
                }
                ;

                //Заносим частицу в популяцию
                test.Add(Solute.Clone() as bool[]);
                //Заносим признаки в классификатор
                FSystem.AcceptedFeatures = test[test.Count - 1];
                Errors.Add(FSystem.ErrorLearnSamples(FSystem.AbstractRulesBase()[0]));

                if (Errors[u] < Ebest)
                {
                    Ebest = Errors[u];

                    BestSolute = test[u].Clone() as bool[];
                    Console.WriteLine("Найдена частица с ошибкой E=" + Errors[u]);
                    Storage.Add(new FeatureSelectionModel(FSystem, BestSolute));
                }
                Console.WriteLine(Errors[u]);
            }
            /////////////////////////////////////////// Сгенерировали первоначальные частицы, ура!

            algoritm();
            Storage = FeatureSelectionModel.Distinct(Storage);
            FeatureSelectionModel.Sort(Storage, SortWay);
            FSystem.AcceptedFeatures = BestSolute;
            return(FSystem);
        }
Пример #6
0
        public void init(IFuzzySystem FSystem, ILearnAlgorithmConf conf)
        {
            GreedyChoiceConfigMinus Config = conf as GreedyChoiceConfigMinus;

            SortWay    = Config.GCCSortWay;
            Storage    = new List <FeatureSelectionModel>(FSystem.CountFeatures);
            test       = new List <bool[]>();
            Errors     = new List <double>();
            BestSolute = new bool[FSystem.AcceptedFeatures.Count()];
            for (int i = 0; i < FSystem.CountFeatures; i++)
            {
                BestSolute[i] = true;
            }
        }
Пример #7
0
        public IFuzzySystem Universal(IFuzzySystem FS, IGeneratorConf config)

        {
            ShrinkFeatures = ((SimpleShrinkFeatureConf)config).ShrinkFeature;
            string[] shouldShrink = ShrinkFeatures.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < shouldShrink.Length; i++)
            {
                int a;
                int.TryParse(shouldShrink[i], out a);

                FS.AcceptedFeatures[a - 1] = false;
            }
            return(FS);
        }
Пример #8
0
        public void init(IFuzzySystem FSystem, ILearnAlgorithmConf conf)
        {
            GreedyChoiceConfigPlus Config = conf as GreedyChoiceConfigPlus;

            max_Features = Config.GCCMaxVars > FSystem.AcceptedFeatures.Length? FSystem.AcceptedFeatures.Length: Config.GCCMaxVars;
            SortWay      = Config.GCCSortWay;
            test         = new List <bool[]>();
            Errors       = new List <double>();
            Storage      = new List <FeatureSelectionModel>();
            BestSolute   = new bool[FSystem.AcceptedFeatures.Count()];
            for (int i = 0; i < FSystem.CountFeatures; i++)
            {
                BestSolute[i] = false;
            }
        }
Пример #9
0
        string makeNameFeatures(IFuzzySystem FSystem, bool[] Source)
        {
            string temp  = String.Empty;
            string temp2 = String.Empty;

            for (int i = 0; i < Source.Count(); i++)
            {
                if (Source[i])
                {
                    temp  += FSystem.LearnSamplesSet.InputAttributes[i].Name + ", ";
                    temp2 += $"{i + 1}, ";
                }
            }
            return(temp + Environment.NewLine + temp2);
        }
Пример #10
0
        private string ErrorInfoPC(IFuzzySystem FS)
        {
            PCFuzzySystem IFS = FS as PCFuzzySystem;

            if (IFS.RulesDatabaseSet.Count < 1)
            {
                return("Точность нечеткой системы недоступна");
            }
            classLearnResult.Add(IFS.ClassifyLearnSamples(IFS.RulesDatabaseSet[0]));
            classTestResult.Add(IFS.ClassifyTestSamples(IFS.RulesDatabaseSet[0]));
            classErLearn.Add(IFS.ErrorLearnSamples(IFS.RulesDatabaseSet[0]));
            classErTest.Add(IFS.ErrorTestSamples(IFS.RulesDatabaseSet[0]));

            return("Точностью на обучающей выборке  " + classLearnResult[classLearnResult.Count - 1].ToString() + " , Точность на тестовой выборке  " + classTestResult[classTestResult.Count - 1].ToString() + " " + Environment.NewLine +
                   "Ошибкой на обучающей выборке  " + classErLearn[classErLearn.Count - 1].ToString() + " , Ошибкой на тестовой выборке  " + classErTest[classErTest.Count - 1].ToString() + " " + Environment.NewLine);
        }
Пример #11
0
        public static void writeAboutObservation(XmlWriter writer, IFuzzySystem Classifier)
        {
            writer.WriteStartElement("Observations");
            if (Classifier.TestSamplesSet != null)
            {
                writer.WriteAttributeString("CountTable", XmlConvert.ToString(2));
                writeAboutTable(writer, Classifier.LearnSamplesSet, Classifier);
                writeAboutTable(writer, Classifier.TestSamplesSet, Classifier);
            }
            else
            {
                writer.WriteAttributeString("CountTable", XmlConvert.ToString(1));
                writeAboutTable(writer, Classifier.LearnSamplesSet, Classifier);
            }


            writer.WriteEndElement();
        }
Пример #12
0
        public static IFuzzySystem LoadUFS(string FileName, out FuzzySystemRelisedList.TypeSystem TypeFS)
        {
            IFuzzySystem result = null;

            TypeFS = FuzzySystemRelisedList.TypeSystem.PittsburghClassifier;
            XmlDocument Source = new XmlDocument();

            Source.Load(FileName);
            XmlNode temp       = Source.SelectSingleNode("FuzzySystem");
            string  typestring = temp.Attributes.GetNamedItem("Type").Value.ToLowerInvariant();

            switch (typestring)
            {
            case "approximatortakagisugeno":
            {
                TSAFuzzySystem TSAFS = new TSAFuzzySystem(LoadLearnFromUFS(Source), LoadTestFromUFS(Source));
                TSAFS.loadUFS(Source);
                result = TSAFS;
                TypeFS = FuzzySystemRelisedList.TypeSystem.TakagiSugenoApproximate;
                break;
            }

            case "approximatorsingleton":
            {
                SAFuzzySystem SAFS = new SAFuzzySystem(LoadLearnFromUFS(Source), LoadTestFromUFS(Source));
                SAFS.loadUFS(Source);
                result = SAFS;
                TypeFS = FuzzySystemRelisedList.TypeSystem.Singletone;
                break;
            }

            case "classifierpittsburgh":
            {
                PCFuzzySystem PCFS = new PCFuzzySystem(LoadLearnFromUFS(Source), LoadTestFromUFS(Source));
                PCFS.loadUFS(Source);
                result = PCFS;
                TypeFS = FuzzySystemRelisedList.TypeSystem.PittsburghClassifier;
                break;
            }
            }

            return(result);
        }
Пример #13
0
 public FeatureSelectionModel(IFuzzySystem Fsystem, bool[] FeaturesSource)
 {
     bool[] temp = Fsystem.AcceptedFeatures;
     Features = FeaturesSource;
     Fsystem.AcceptedFeatures = Features;
     Error     = Fsystem.ErrorLearnSamples(Fsystem.AbstractRulesBase()[0]);
     ErrorTest = Fsystem.ErrorTestSamples(Fsystem.AbstractRulesBase()[0]);
     Fsystem.AcceptedFeatures = temp;
     if (Fsystem is PCFuzzySystem)
     {
         Accuracy     = 100.0 - Error;
         AccuracyTest = 100.0 - ErrorTest;
     }
     else
     {
         Error     = Fsystem.RMSEtoMSEforLearn(Error);
         ErrorTest = Fsystem.RMSEtoMSEforTest(ErrorTest);
     }
     Info = makeNameFeatures(Fsystem, Features);
 }
Пример #14
0
        public void init(IFuzzySystem FSystem, ILearnAlgorithmConf conf)
        {
            theFuzzySystem = FSystem;
            grbin_conf Config = conf as grbin_conf;

            Ebest         = Config.GSAErrorBest;
            Ebest1        = Ebest;
            iterMax       = Config.GSAMInter;
            MCount        = Config.GSAMCount;
            G0            = Config.GSAG0;
            alpha         = Config.GSAAlpha;
            epsilon       = Config.GSAEpsilon;
            open_Features = Config.GSAMaxVars;
            max_Features  = FSystem.CountFeatures;
            test          = new List <bool[]>();
            Errors        = new List <double>();
            BestSolute    = new bool[FSystem.AcceptedFeatures.Count()];
            GoodSolute    = new bool[FSystem.AcceptedFeatures.Count()];
            Solute        = new bool[FSystem.AcceptedFeatures.Count()];
            Storage       = new List <FeatureSelectionModel>();
            SortWay       = Config.GSASortWay;
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        private void make_Log(Log_line EventCall, IFuzzySystem FS = null, string name_Alg = "", DateTime TimerValue = new DateTime(), TimeSpan TimerSpan = new TimeSpan())
        {
            switch (EventCall)
            {
            case Log_line.Start:
            {
                LOG += Environment.NewLine + "(" + TimerValue.ToString() + ")" + " Начало построения системы" + Environment.NewLine;

                break;
            }

            case Log_line.StartGenerate:
            {
                LOG += "(" + TimerValue.ToString() + ")" + " Начата генерация системы { " + FS.LearnSamplesSet.FileName + " ;  " + FS.TestSamplesSet.FileName + " }" + 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:
            {
                LOG += "(" + DateTime.Now.ToString() + ")" + " Сгенерирована система сложностью " + FS.ValueComplexity(FS.AbstractRulesBase()[0]).ToString() + Environment.NewLine + " Количество правил " + FS.ValueRuleCount(FS.AbstractRulesBase()[0]).ToString() + Environment.NewLine + showErrorInfo(FS) + "";
                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:
            {
                LOG += "(" + DateTime.Now.ToString() + ")" + " оптимизированная система сложностью " + FS.ValueComplexity(FS.AbstractRulesBase()[0]).ToString() + Environment.NewLine + " Количество правил " + FS.ValueRuleCount(FS.AbstractRulesBase()[0]).ToString() + Environment.NewLine + showErrorInfo(FS) + "";
                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; }
            }
        }
Пример #18
0
        public IFuzzySystem TuneUpFuzzySystem(IFuzzySystem Approximate, ILearnAlgorithmConf conf)
        {
            SAFuzzySystem toRunSystem = Approximate as SAFuzzySystem;

            return(TuneUpFuzzySystem(toRunSystem, conf));
        }
Пример #19
0
 private void writeSAtoUFS(IFuzzySystem FS, string fileName)
 {
     SAFSUFSWriter.saveToUFS(FS as SAFuzzySystem, fileName);
 }
        public IFuzzySystem Generate(IFuzzySystem Classifier, IGeneratorConf config)
        {
            PCFuzzySystem toRunFuzzySystem = Classifier as PCFuzzySystem;

            return(Generate(toRunFuzzySystem, config));
        }
        public IFuzzySystem Generate(IFuzzySystem Approximate, IGeneratorConf config)
        {
            SAFuzzySystem toRunFuzzySystem = Approximate as SAFuzzySystem;

            return(Generate(toRunFuzzySystem, config));
        }
Пример #22
0
 private void writePCtoUFS(IFuzzySystem FS, string fileName)
 {
     PCFSUFSWriter.saveToUFS(FS as PCFuzzySystem, fileName);
 }