public static List <KnowlegeBaseSARules> SelectBest(this List <KnowlegeBaseSARules> Source, SAFuzzySystem Approx, int CountBest)
 {
     KnowlegeBaseSARules[] result = new KnowlegeBaseSARules[CountBest];
     Source.ToArray().SortRules(Approx).ToList().CopyTo(0, result, 0, CountBest);
     return(result.ToList());
 }
Ejemplo n.º 2
0
        public override SAFuzzySystem TuneUpFuzzySystem(SAFuzzySystem Approximate, ILearnAlgorithmConf conf)
        {
            PSOBacterySearchConf CurrentConf = conf as PSOBacterySearchConf;

            count_iteration = CurrentConf.PSOSCCountIteration;
            c1             = CurrentConf.PSOSCC1;
            c2             = CurrentConf.PSOSCC2;
            w              = 1;
            count_particle = CurrentConf.PSOSCPopulationSize;
            sendBactery    = CurrentConf.PSOBacteryHOCountGet;
            sendPSO        = CurrentConf.PSOBacteryHOCountSend;
            interPSOtoSend = CurrentConf.PSOBacteryHOCountChange;
            result         = Approximate;

            X         = new KnowlegeBaseSARules[count_particle];
            V         = new KnowlegeBaseSARules[count_particle];
            Pi        = new KnowlegeBaseSARules[count_particle];
            Pg        = new KnowlegeBaseSARules();
            Errors    = new double[count_particle];
            OldErrors = new double[count_particle];
            rnd       = new Random();


            preIterate(result);
            int trySend     = 0;
            int counterIter = 0;

            for (int i = 0; i < count_iteration; i++)
            {
                oneIterate(result);
                counterIter++;
                if (counterIter == interPSOtoSend)
                {
                    Pi = sortSolution(Pi);
                    savetoUFS(Pi.ToList(), 0, sendPSO, trySend);
                    BacteryRunner();
                    trySend++;

                    List <KnowlegeBaseSARules> tempRes = loadDatabase().ToList();

                    int size = tempRes.Count;
                    for (int p = tempRes.Count - 1; p >= 0; p--)
                    {
                        X[p] = tempRes[0];

                        double newError = Approximate.approxLearnSamples(X[p]);

                        if (newError < Errors[p])
                        {
                            Pi[p]        = new KnowlegeBaseSARules(X[p]);
                            OldErrors[p] = Errors[p];
                            Errors[p]    = newError;

                            if (minError > newError)
                            {
                                minError = newError;
                                Pg       = new KnowlegeBaseSARules(X[p]);
                            }
                        }

                        tempRes.RemoveAt(0);
                    }

                    counterIter = 0;
                }
            }
            result.RulesDatabaseSet[0].TermsSet.Trim();
            return(result);
        }