Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }