Exemplo n.º 1
0
        public OutLookersBeeParams(KnowlegeBaseTSARules theSource, KnowlegeBaseTSARules Best, BeeParamsAlgorithm parrent, Random rand)
            : base(theSource, parrent)
        {
            for (int i = 0; i < PositionOfBee.TermsSet.Count; i++)
            {
                double [] Params = PositionOfBee.TermsSet[i].Parametrs;
                for (int j = 0; j < Params.Count(); j++)
                {
                    int Choose = rand.Next(2);
                    switch (Choose)
                    {
                    case 0: { Params[j] = Best.TermsSet[i].Parametrs[j] + Math.Abs(Best.TermsSet[i].Parametrs[j] - Params[j]) * rand.NextDouble(); } break;

                    case 1: { Params[j] = Best.TermsSet[i].Parametrs[j] - Math.Abs(Best.TermsSet[i].Parametrs[j] - Params[j]) * rand.NextDouble(); } break;
                    }
                }
                PositionOfBee.TermsSet[i].Parametrs = Params;
            }

            double[] consq = PositionOfBee.all_conq_of_rules;
            for (int i = 0; i < consq[i]; i++)
            {
                int choose = rand.Next(2);
                switch (choose)
                {
                case 0: { consq[i] = Best.all_conq_of_rules[i] + Math.Abs(Best.all_conq_of_rules[i] - consq[i]) * rand.NextDouble(); } break;

                case 1: { consq[i] = Best.all_conq_of_rules[i] - Math.Abs(Best.all_conq_of_rules[i] - consq[i]) * rand.NextDouble(); } break;
                }
            }
            PositionOfBee.all_conq_of_rules = consq;
            getGoodsImproove();
        }
Exemplo n.º 2
0
 public HiveParams(BeeParamsAlgorithm Parrent, KnowlegeBaseTSARules Best)
 {
     theParrent  = Parrent;
     hostArchive = new List <BeeParams>();
     hostArchive.Add(new BeeParams(Best, Parrent));
     hostArchive[0].getGoodsImproove();
 }
Exemplo n.º 3
0
 public KnowlegeBaseTSARulesWithError(KnowlegeBaseTSARules source, List <bool> used_rules = null) : base(source, used_rules)
 {
     if (source is KnowlegeBaseTSARulesWithError)
     {
         error = ((KnowlegeBaseTSARulesWithError)source).error;
     }
 }
Exemplo n.º 4
0
        private TSAFuzzySystem BreakCrossTerm(TSAFuzzySystem Approx, int Feature, int indexATerm, int indexBterm, int dataBase)
        {
            TSAFuzzySystem       result     = Approx;
            KnowlegeBaseTSARules DataSet    = result.RulesDatabaseSet[dataBase];
            List <Term>          soureTerms = DataSet.TermsSet.Where(x => x.NumVar == Feature).ToList();
            Term ATerm = soureTerms[indexATerm];
            Term BTerm = soureTerms[indexBterm];

            Term Left  = ATerm;
            Term Right = BTerm;

            if (ATerm.Pick > BTerm.Pick)
            {
                Left  = BTerm;
                Right = ATerm;
            }



            double border = (Left.Max + Right.Min) / 2;

            Left.Max  = border;
            Right.Min = border;

            result.RulesDatabaseSet[dataBase] = DataSet;


            return(result);
        }
Exemplo n.º 5
0
        //нахождение расстояния ощущения (соседства)
        private double distneihbor(KnowlegeBaseTSARules x)
        {
            double sum = 0, dneihbor;

            for (int j = 0; j < Population.Length; j++)
            {
                if (x != Population[j])
                {
                    sum += Distance(x, Population[j]);
                }

                /*
                 #if debug
                 * //вывод значение суммы расстояний между переменными
                 * Console.Write("Значение суммы для расчета расстояния ощущения = ");
                 * Console.WriteLine(sum);
                 #endif
                 */
            }
            dneihbor = sum * (1.0 / (1.5 * Population.Length));

            /*
             * //вывод значение dneihbor соседей
             * Console.Write("Значение dneihbor для расчета расстояния ощущения = ");
             * Console.WriteLine(dneihbor);
             */

            return(dneihbor);
        }
Exemplo n.º 6
0
        //нахождение расстояния ощущения (соседства)
        private List <int> countneihbors(KnowlegeBaseTSARules x)
        {
            double     border   = distneihbor(x);
            List <int> neihbors = new List <int>();

            /*
             * //вывод значение дистанции соседа
             * for (int g = 0; g < Population.Length; g++)
             * {
             *  Console.Write("Знаение distneihbor = ");
             *  Console.WriteLine(distneihbor(x));
             * }
             */

            for (int j = 0; j < Population.Length; j++)
            {
                if (x != Population[j])
                {
                    if (Distance(x, Population[j]) < border)
                    {
                        neihbors.Add(j);
                    }
                }
            }

            return(neihbors);
        }
Exemplo n.º 7
0
        protected void EvalXi(double[][] X, double[] Y, KnowlegeBaseTSARules knowlegeBaseA)
        {
            EvalDividerXi(X, Y, knowlegeBaseA);

            // foreach dataVector in dataSet
            for (int i = 0; i < m; i++)
            {
                double[] x = X[i];   // result.Learn_Samples_set.Data_Rows[s].Input_Attribute_Value;

                // foreach rule in base.rules
                for (int j = 0; j < R; j++)
                {
                    double mul = 1;

                    // foreach term in rule.terms
                    foreach (Term term in knowlegeBaseA.RulesDatabase[j].ListTermsInRule)
                    {
                        mul *= term.LevelOfMembership(x);
                        if (Math.Abs(mul - 0) < EPSILON)
                        {
                            break;
                        }
                    }

                    xiValue[i][j] = mul / dividerXi[i];
                }
            }
        }
Exemplo n.º 8
0
        //нахождение расстояния между крилями
        private double Distance(KnowlegeBaseTSARules x, KnowlegeBaseTSARules y)
        {
            double dist, sum = 0;

            for (int i = 0; i < x.TermsSet.Count; i++)
            {
                for (int j = 0; j < x.TermsSet[i].Parametrs.Length; j++)
                {
                    sum += Math.Pow(x.TermsSet[i].Parametrs[j] - y.TermsSet[i].Parametrs[j], 2);
                }
            }
            for (int i = 0; i < x.RulesDatabase.Count; i++)
            {
                sum += Math.Pow(x.RulesDatabase[i].IndependentConstantConsequent - y.RulesDatabase[i].IndependentConstantConsequent, 2);
            }
            dist = Math.Sqrt(sum);

            /*
             #if debug
             *  //вывод значение dist соседа
             *  Console.Write("Значение dist = ");
             *  Console.WriteLine(dist);
             #endif
             */
            return(dist);
        }
Exemplo n.º 9
0
        public void GetDots(TSAFuzzySystem approx, KnowlegeBaseTSARules knowlegeBase)
        {
            // Dots (COMPLETE, BUT DOUBLECHECK WHEN DEBUGGING)
            var inputs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered()
                         .Select(dataRow => dataRow.InputAttributeValue).ToList();
            var localDots = inputs.AsParallel().AsOrdered()
                            .Where(InBetweenTheLimits).ToList();
            //  var strs = new List<string[]>(localDots.Count);
            //  for (int i = 0; i < strs.Capacity; i++)
            //    strs.Add(new[] { string.Empty });

            var rezs = approx.LearnSamplesSet.DataRows.AsParallel().AsOrdered()
                       .Where(row => localDots.Contains(row.InputAttributeValue))
                       .Select(dataRow => dataRow.DoubleOutput).ToList();

            List <SampleSet.RowSample> rows = localDots.Select((t, i) => new SampleSet.RowSample(t, null, rezs[i], null)).ToList();

            var samples = new SampleSet("1.dat", rows, approx.LearnSamplesSet.InputAttributes, approx.LearnSamplesSet.OutputAttribute);

            system = new TSAFuzzySystem(samples, samples);

            var usedRules = GetRules(knowlegeBase);

            system.RulesDatabaseSet.Add(new KnowlegeBaseTSARules(knowlegeBase, null));
        }
Exemplo n.º 10
0
        public virtual void Init(ILearnAlgorithmConf conf)
        {
            currentConf     = conf as GeneticConf;
            fullFuzzySystem = result;
            step            = 0;
            errorAfter      = 0;
            errorBefore     = result.approxLearnSamples(result.RulesDatabaseSet[0]);
            backUp          = result.RulesDatabaseSet[0];

            initFunc = new initFuncType(localInit);
            if (currentConf.GENCTypeInit == GeneticConf.Alg_Init_Type.Глобальный)
            {
                initFunc = new initFuncType(globalInit);
            }

            crossoverFunc = new crossoverFuncType(unifiedCrossover);
            if (currentConf.GENCTypeCrossover == GeneticConf.Alg_Crossover_Type.Многоточечный)
            {
                crossoverFunc = new crossoverFuncType(pointsCrossover);
            }

            selectionFunc = new selectionFuncType(rouletteSelection);
            if (currentConf.GENCTypeSelection == GeneticConf.Alg_Selection_Type.Случайный)
            {
                selectionFunc = new selectionFuncType(randomSelection);
            }
            if (currentConf.GENCTypeSelection == GeneticConf.Alg_Selection_Type.Элитарный)
            {
                selectionFunc = new selectionFuncType(eliteSelection);
            }
            fullInit(); // Здесь проходит инициализация
        }
Exemplo n.º 11
0
        private List <bool> GetRules(KnowlegeBaseTSARules knowlegeBase)
        {
            //rules = approx.RulesDatabaseSet[0].Rules_Database.Where(
            //    rule =>
            //    {
            //        bool answer = true;
            //        foreach (var term in rule.Term_of_Rule_Set)
            //        {
            //            if (!terms.Contains(term))
            //                answer = false;
            //        }
            //        return answer;
            //    }
            //    ).ToList();

            List <bool> answer = new List <bool>();

            foreach (var rule in knowlegeBase.RulesDatabase)
            {
                bool tmp = true;
                foreach (var term in rule.ListTermsInRule)
                {
                    if (!terms.Contains(term))
                    {
                        tmp = false;
                    }
                }

                answer.Add(tmp);
            }

            return(answer);
        }
Exemplo n.º 12
0
        KnowlegeBaseTSARules unifiedCrossover(KnowlegeBaseTSARules parent1, KnowlegeBaseTSARules parent2)
        {
            double b = (currentConf.GENCPopabilityCrossover / 100);
            KnowlegeBaseTSARules child;

            child = new KnowlegeBaseTSARules(parent1);
            for (int i = 0; i < parent1.TermsSet.Count; i++)
            //Parallel.For(0, parent1.TermsSet.Count, i =>
            {
                if (b > allRandom.NextDouble())
                {
                    child.TermsSet[i].Parametrs = parent2.TermsSet[i].Parametrs;
                }
                //});
            }


            double[] tempMassiveCh = child.all_conq_of_rules.Clone() as double[];
            double[] tempMassiveP2 = parent2.all_conq_of_rules.Clone() as double[];
            for (int i = 0; i < tempMassiveCh.Count(); i++)
            //Parallel.For(0, parent1.all_conq_of_rules.Count(), i =>
            {
                if (b > allRandom.NextDouble())
                {
                    tempMassiveCh[i] = tempMassiveP2[i];
                }
            }
            child.all_conq_of_rules = tempMassiveCh;
            //});
            return(child);
        }
Exemplo n.º 13
0
        public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approximate, ILearnAlgorithmConf conf)
        {
            BacteryAlgorithmConfig Config = conf as BacteryAlgorithmConfig;

            sendBactery    = Config.BFOCountSolution;
            interPSOtoSend = Config.BFOCountIteration;
            result         = Approximate;


            if (result.RulesDatabaseSet.Count < 1)
            {
                throw new InvalidDataException("Нечеткая система не проинициализированна");
            }
            KnowlegeBaseTSARules backSave = new KnowlegeBaseTSARules(result.RulesDatabaseSet[0]);
            double backResult             = result.approxLearnSamples(result.RulesDatabaseSet[0]);

            savetoUFS(result.RulesDatabaseSet, 0, 0, 0);
            BacteryRunner();
            KnowlegeBaseTSARules[] solutions = loadDatabase();
            solutions = sortSolution(solutions);
            if (solutions.Count() < 1)
            {
                result.RulesDatabaseSet[0] = backSave; return(result);
            }
            result.RulesDatabaseSet[0] = solutions[0];
            double newResult = result.approxLearnSamples(result.RulesDatabaseSet[0]);

            if (newResult > backResult)
            {
                result.RulesDatabaseSet[0] = backSave;
            }

            result.RulesDatabaseSet[0].TermsSet.Trim();
            return(result);
        }
Exemplo n.º 14
0
 public ScoreListElem(ScoreListElem Source)
 {
     Alg      = Source.Alg.Clone() as string;
     Res      = new KnowlegeBaseTSARules(Source.Res);
     MaxError = Source.MaxError;
     Error    = Source.Error;
 }
Exemplo n.º 15
0
        public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approximate, ILearnAlgorithmConf conf)
        {
            if (Approximate.RulesDatabaseSet.Count == 0)
            {
                throw new InvalidOperationException("Нечеткая система не была корректно инициализированна");
            }
            KnowlegeBaseTSARules newBase = new KnowlegeBaseTSARules(Approximate.RulesDatabaseSet[0]);


            double result_before = Approximate.approxLearnSamples(newBase);

            foreach (TSARule Rule in newBase.RulesDatabase)
            {
                double [] coefficient = null;
                double    Value       = LSMWeghtReqursiveSimple.EvaluteConsiquent(Approximate, Rule.ListTermsInRule, out coefficient);
                Rule.IndependentConstantConsequent = Value;
                Rule.IndependentConstantConsequent = Value;
                Rule.RegressionConstantConsequent  = coefficient;
            }

            double result_after = Approximate.approxLearnSamples(newBase);

            if (result_before > result_after)
            {
                Approximate.RulesDatabaseSet[0] = newBase;
            }
            GC.Collect();
            Approximate.RulesDatabaseSet[0].TermsSet.Trim();
            return(Approximate);
        }
Exemplo n.º 16
0
        protected void EvalDividerXi(double[][] X, double[] Y, KnowlegeBaseTSARules knowlegeBaseA)
        {
            double sum, mul;

            // foreach dataVector in dataSet
            for (int i = 0; i < m; i++)
            {
                sum = 0;
                double[] x = X[i]; // result.Learn_Samples_set.Data_Rows[s].Input_Attribute_Value;

                // foreach rule in base.Rules
                foreach (TSARule rule in knowlegeBaseA.RulesDatabase)
                {
                    mul = 1;

                    // foreach term in rule.terms
                    foreach (Term term in rule.ListTermsInRule)
                    {
                        mul *= term.LevelOfMembership(x);
                        if (Math.Abs(mul - 0) < EPSILON)
                        {
                            break;
                        }
                    }

                    sum += mul;
                }

                dividerXi[i] = sum;
            }
        }
 public static void Inject(this KnowlegeBaseTSARules[] Destination, int indexStartDestination, KnowlegeBaseTSARules[] Source, int indexStartSource, int CountIjected, TSAFuzzySystem Approx)
 {
     Destination = Destination.SortRules(Approx);
     for (int i = 0; i < CountIjected; i++)
     {
         Destination[i + indexStartDestination] = new KnowlegeBaseTSARules(Source[i + indexStartSource]);
     }
 }
Exemplo n.º 18
0
        public override TSAFuzzySystem Generate(TSAFuzzySystem Approximate, IGeneratorConf config)
        {
            start_add_rules = Approximate.RulesDatabaseSet.Count;
            TSAFuzzySystem result = Approximate;

            if (result.RulesDatabaseSet.Count == 0)
            {
                AbstractNotSafeGenerator tempGen = new GeneratorRulesEveryoneWithEveryone();
                result = tempGen.Generate(result, config);

                GC.Collect();
            }



            Request_count_rules = ((RullesShrinkConf)config).RSCCountRules;
            max_count_rules     = ((RullesShrinkConf)config).RSCMaxRules;
            count_slices        = ((RullesShrinkConf)config).IEWECountSlice;
            min_count_rules     = ((RullesShrinkConf)config).RSCMinRules;
            type_term           = ((RullesShrinkConf)config).IEWEFuncType;

            int         count_of_swith_off    = ((RullesShrinkConf)config).RSCMaxRules - Request_count_rules;
            List <byte> Varians_of_run_system = new List <byte>();

            for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++)
            {
                Varians_of_run_system.Add(1);
            }
            for (int i = 0; i < count_of_swith_off; i++)
            {
                Varians_of_run_system[i] = 0;
            }
            Generate_all_variant_in_pool(Varians_of_run_system);
            for (int i = 0; i < Pull_of_systems.Count; i++)
            {
                KnowlegeBaseTSARules temp_rules = new  KnowlegeBaseTSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]);
                temp_rules.TrimTerms();

                result.RulesDatabaseSet.Add(temp_rules);
                result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]);
                errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet [start_add_rules + i]));
            }

            int best_index            = errors_of_systems.IndexOf(errors_of_systems.Min());
            KnowlegeBaseTSARules best = result.RulesDatabaseSet[start_add_rules + best_index];

            result.RulesDatabaseSet.Clear();
            result.RulesDatabaseSet.Add(best);
            Console.WriteLine(Pull_of_systems.Count());



            GC.Collect();
//            result.UnlaidProtectionFix();
            result.RulesDatabaseSet[0].TermsSet.Trim();
            return(result);
        }
Exemplo n.º 19
0
        public static List <BeeParams> FlyScout(int countofBee, Random rand, KnowlegeBaseTSARules Source, BeeParamsAlgorithm parrent)
        {
            List <BeeParams> result = new List <BeeParams>();

            for (int i = 0; i < countofBee; i++)
            {
                result.Add(new ScoutParams(Source, parrent, rand));
            }

            return(result);
        }
Exemplo n.º 20
0
 public virtual void WJVector_gen(int j)
 {
     WJVector = new KnowlegeBaseTSARules(monkey[j]);
     for (int k = 0; k < monkey[j].TermsSet.Count; k++)
     {
         for (int q = 0; q < monkey[j].TermsSet[k].CountParams; q++)
         {
             WJVector.TermsSet[k].Parametrs[q] += 2 * (StaticRandom.NextDouble() - 0.5) * watch_jump_parameter;
         }
     }
 }
 public KnowlegeBaseTSARulesWithError(KnowlegeBaseTSARules source, List <bool> used_rules = null) : base(source, used_rules)
 {
     if (source is KnowlegeBaseTSARulesWithError)
     {
         error = ((KnowlegeBaseTSARulesWithError)source).error;
         if (((KnowlegeBaseTSARulesWithError)source).RulesAcceptedFeatures != null)
         {
             RulesAcceptedFeatures = ((KnowlegeBaseTSARulesWithError)source).RulesAcceptedFeatures.ToArray().ToList();
         }
     }
 }
Exemplo n.º 22
0
        private TSAFuzzySystem UniTerm(TSAFuzzySystem Approx, int Feature, int indexATerm, int indexBterm, int dataBase)
        {
            TSAFuzzySystem       result     = Approx;
            KnowlegeBaseTSARules DataSet    = result.RulesDatabaseSet[dataBase];
            List <Term>          soureTerms = DataSet.TermsSet.Where(x => x.NumVar == Feature).ToList();
            Term   ATerm   = soureTerms[indexATerm];
            Term   BTerm   = soureTerms[indexBterm];
            double newPick = (ATerm.Pick + BTerm.Pick) / 2;
            double newMin  = ATerm.Min;

            if (BTerm.Min < newMin)
            {
                newMin = BTerm.Min;
            }
            double newMax = ATerm.Max;

            if (BTerm.Max > newMax)
            {
                newMax = BTerm.Max;
            }

            Term uniTerm = new Term(ATerm);

            uniTerm.Pick = newPick;
            uniTerm.Min  = newMin;
            uniTerm.Max  = newMax;

            DataSet.TermsSet.Add(uniTerm);

            List <TSARule> toChangeArules = DataSet.RulesDatabase.Where(x => x.ListTermsInRule.Contains(ATerm)).ToList();

            for (int i = 0; i < toChangeArules.Count(); i++)
            {
                int indexofA = toChangeArules[i].ListTermsInRule.IndexOf(ATerm);
                toChangeArules[i].ListTermsInRule[indexofA] = uniTerm;
            }
            DataSet.TermsSet.Remove(ATerm);


            List <TSARule> toChangeBrules = DataSet.RulesDatabase.Where(x => x.ListTermsInRule.Contains(BTerm)).ToList();

            for (int i = 0; i < toChangeBrules.Count(); i++)
            {
                int indexofB = toChangeBrules[i].ListTermsInRule.IndexOf(BTerm);
                toChangeBrules[i].ListTermsInRule[indexofB] = uniTerm;
            }
            DataSet.TermsSet.Remove(BTerm);

            result.RulesDatabaseSet[dataBase] = DataSet;


            return(result);
        }
Exemplo n.º 23
0
        public virtual void oneIterate(TSAFuzzySystem result)
        {
            for (int j = 0; j < count_particle; j++)
            {
                w = 1 / (1 + Math.Exp(-(Errors[j] - OldErrors[j]) / 0.01));
                for (int k = 0; k < X[j].TermsSet.Count; k++)
                {
                    for (int q = 0; q < X[j].TermsSet[k].CountParams; q++)
                    {
                        double bp = Pi[j].TermsSet[k].Parametrs[q];
                        V[j].TermsSet[k].Parametrs[q] = V[j].TermsSet[k].Parametrs[q] * w + c1 * rnd.NextDouble() * (bp - X[j].TermsSet[k].Parametrs[q]) +
                                                        c2 * rnd.NextDouble() * (Pg.TermsSet[k].Parametrs[q] - X[j].TermsSet[k].Parametrs[q]);
                        X[j].TermsSet[k].Parametrs[q] += V[j].TermsSet[k].Parametrs[q];
                    }
                }
                double[] bf  = new double[V[j].all_conq_of_rules.Length];
                double[] bfw = new double[V[j].all_conq_of_rules.Length];
                for (int k = 0; k < V[j].all_conq_of_rules.Length; k++)
                {
                    bfw[k] = V[j].all_conq_of_rules[k] * w + c1 * rnd.NextDouble() * (Pi[j].all_conq_of_rules[k] - X[j].all_conq_of_rules[k]) +
                             c2 * rnd.NextDouble() * (Pg.all_conq_of_rules[k] - X[j].all_conq_of_rules[k]);
                    double sw = X[j].all_conq_of_rules[k] + bfw[k];
                    bf[k] = sw;
                }
                X[j].all_conq_of_rules = bf;
                V[j].all_conq_of_rules = bfw;
                double newError = 0;
                result.RulesDatabaseSet.Add(X[j]);
                int  temp_index = result.RulesDatabaseSet.Count - 1;
                bool success    = true;
                try
                {
                    newError = result.approxLearnSamples(result.RulesDatabaseSet[temp_index]);
                }
                catch (Exception)
                {
                    success = false;
                }
                result.RulesDatabaseSet.RemoveAt(temp_index);
                if (success && (newError < Errors[j]))
                {
                    OldErrors[j] = Errors[j];
                    Errors[j]    = newError;

                    Pi[j] = new KnowlegeBaseTSARules(X[j]);
                }
                if (minError > newError)
                {
                    minError = newError;
                    Pg       = new KnowlegeBaseTSARules(X[j]);
                }
            }
        }
Exemplo n.º 24
0
        public override TSAFuzzySystem Generate(TSAFuzzySystem Approximate, IGeneratorConf config)
        {
            type_alg            = ((kMeanRulesGeneratorConfig)config).KMRGTypeAlg;
            count_rules         = ((kMeanRulesGeneratorConfig)config).KMRGCountRules;
            type_func           = ((kMeanRulesGeneratorConfig)config).KMRGTypeFunc;
            nebulisation_factor = ((kMeanRulesGeneratorConfig)config).KMRGExponentialWeight;
            Max_iteration       = ((kMeanRulesGeneratorConfig)config).KMRGIteraton;
            need_precision      = ((kMeanRulesGeneratorConfig)config).KMRGAccuracy;


            Approxk_mean_base K_Agl = null;

            switch (type_alg)
            {
            case Type_k_mean_algorithm.GathGeva: K_Agl = new Approxk_mean_Gath_Geva(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;

            case Type_k_mean_algorithm.GustafsonKessel: K_Agl = new Approxk_mean_Gustafson_kessel(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;

            case Type_k_mean_algorithm.FCM: K_Agl = new Approxk_mean_base(Approximate.LearnSamplesSet, Max_iteration, need_precision, count_rules, nebulisation_factor); break;
            }
            K_Agl.Calc();

            KnowlegeBaseTSARules New_Rules = new KnowlegeBaseTSARules();

            for (int i = 0; i < count_rules; i++)
            {
                int []      order_terms = new int [Approximate.LearnSamplesSet.CountVars];
                List <Term> term_set    = new List <Term>();
                for (int j = 0; j < Approximate.LearnSamplesSet.CountVars; j++)
                {
                    Term temp_term = Term.MakeTerm(K_Agl.Centroid_cordinate_S[i][j], Math.Sqrt(Calc_distance_for_member_ship_function_for_Clust(i, j, K_Agl)) * 3, type_func, j);
                    term_set.Add(temp_term);
                }
                New_Rules.ConstructNewRule(term_set, Approximate);
            }

            TSAFuzzySystem Result = Approximate;

            if (Result.RulesDatabaseSet.Count > 0)
            {
                Result.RulesDatabaseSet[0] = New_Rules;
            }
            else
            {
                Result.RulesDatabaseSet.Add(New_Rules);
            }
            Result.UnlaidProtectionFix(Result.RulesDatabaseSet[0]);
            GC.Collect();
            Result.RulesDatabaseSet[0].TermsSet.Trim();
            return(Result);
        }
Exemplo n.º 25
0
        public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approximate, ILearnAlgorithmConf config)
        {
            theFuzzySystem = Approximate;
            if (theFuzzySystem.RulesDatabaseSet.Count == 0)
            {
                throw new System.FormatException("Что то не то с входными данными");
            }
            OptimizeTermShrinkHardCoreConf Config = config as OptimizeTermShrinkHardCoreConf;

            count_shrink = Config.OTSHCCountShrinkTerm;


            for (int i = 0; i < Approximate.CountFeatures; i++)
            {
                int count_terms_for_var = Approximate.RulesDatabaseSet[0].TermsSet.FindAll(x => x.NumVar == i).Count;

                if (count_terms_for_var >= count_shrink)
                {
                    int        shrinkcounter  = count_shrink;
                    List <int> Varians_of_cut = new List <int>();
                    for (int j = 0; j < count_terms_for_var; j++)
                    {
                        if (shrinkcounter > 0)
                        {
                            Varians_of_cut.Add(0);
                        }
                        else
                        {
                            Varians_of_cut.Add(1);
                        }
                        shrinkcounter--;
                    }
                    Generate_all_variant_in_pool(Varians_of_cut);


                    for (int j = 0; j < Pull_of_systems.Count; j++)
                    {
                        KnowlegeBaseTSARules current = MakeCut(Approximate.RulesDatabaseSet[0], Pull_of_systems[j], i);
                        Systems_ready_to_test.Add(current);
                        errors_of_systems.Add(theFuzzySystem.approxLearnSamples(current));
                    }
                    Pull_of_systems.Clear();
                }
            }

            int best_index = errors_of_systems.IndexOf(errors_of_systems.Min());

            theFuzzySystem.RulesDatabaseSet[0] = Systems_ready_to_test[best_index];

            return(theFuzzySystem);
        }
Exemplo n.º 26
0
        public override TSAFuzzySystem TuneUpFuzzySystem(TSAFuzzySystem Approximate, ILearnAlgorithmConf config)
        {
            start_add_rules = Approximate.RulesDatabaseSet.Count;
            TSAFuzzySystem result = Approximate;

            if (result.RulesDatabaseSet.Count == 0)
            {
                throw new System.FormatException("Что то не то с входными данными");
            }



            OptimizeRullesShrinkConf Config = config as OptimizeRullesShrinkConf;

            count_Shrink_rule = Config.ORSCCountShrinkRules;

            int         count_of_swith_off    = count_Shrink_rule;
            List <byte> Varians_of_run_system = new List <byte>();

            for (int i = 0; i < Approximate.RulesDatabaseSet[0].RulesDatabase.Count; i++)
            {
                Varians_of_run_system.Add(1);
            }
            for (int i = 0; i < count_of_swith_off; i++)
            {
                Varians_of_run_system[i] = 0;
            }
            Generate_all_variant_in_pool(Varians_of_run_system);
            for (int i = 0; i < Pull_of_systems.Count; i++)
            {
                KnowlegeBaseTSARules temp_rules = new  KnowlegeBaseTSARules(result.RulesDatabaseSet[0], Pull_of_systems[i]);
                temp_rules.TrimTerms();

                result.RulesDatabaseSet.Add(temp_rules);
                result.UnlaidProtectionFix(result.RulesDatabaseSet[start_add_rules + i]);
                errors_of_systems.Add(result.approxLearnSamples(result.RulesDatabaseSet[start_add_rules + i]));
            }

            int best_index            = errors_of_systems.IndexOf(errors_of_systems.Min());
            KnowlegeBaseTSARules best = result.RulesDatabaseSet[start_add_rules + best_index];

            result.RulesDatabaseSet.Clear();
            result.RulesDatabaseSet.Add(best);
            Console.WriteLine(Pull_of_systems.Count());



            result.RulesDatabaseSet[0].TermsSet.Trim();
//            result.UnlaidProtectionFix();
            return(result);
        }
Exemplo n.º 27
0
        void fullInit()
        {
            populationMassive = new KnowlegeBaseTSARules[currentConf.GENCPopulationSize];
            childrenMassive   = new KnowlegeBaseTSARules[currentConf.GENCCountChild];

            for (int i = 0; i < currentConf.GENCPopulationSize; i++)
            {
                populationMassive[i] = new KnowlegeBaseTSARules(fullFuzzySystem.RulesDatabaseSet[0]);
            }



            //Parallel.For(1, (currentConf.Особей_в_популяции - 1), i =>
            for (int i = 1; i < currentConf.GENCPopulationSize; i++)
            {
                double[] tempMassive = new double[populationMassive[i].all_conq_of_rules.Count()];
                //Parallel.For(0, (populationMassive[i].all_conq_of_rules.Count() - 1), j =>

                for (int j = 0; j < populationMassive[i].all_conq_of_rules.Count(); j++)
                {
                    tempMassive[j] = initFunc(populationMassive[i].all_conq_of_rules[j],
                                              currentConf.GENCScateDeverceInit,
                                              fullFuzzySystem.LearnSamplesSet.OutputAttribute.Max,
                                              fullFuzzySystem.LearnSamplesSet.OutputAttribute.Min);
                }
                populationMassive[i].all_conq_of_rules = tempMassive;
                //});


                for (int j = 0; j < populationMassive[i].TermsSet.Count; j++)
                //Parallel.For(0, populationMassive[i].TermsSet.Count, j =>
                {
                    tempMassive = populationMassive[i].TermsSet[j].Parametrs.Clone() as double[];
                    for (int u = 0; u < populationMassive[i].TermsSet[j].Parametrs.Count(); u++)
                    //Parallel.For(0, populationMassive[i].TermsSet[j].Parametrs.Count(), u =>
                    {
                        tempMassive[u] = initFunc(tempMassive[u],
                                                  currentConf.GENCScateDeverceInit,
                                                  fullFuzzySystem.LearnSamplesSet.InputAttributes[populationMassive[i].TermsSet[j].NumVar].Max,
                                                  fullFuzzySystem.LearnSamplesSet.InputAttributes[populationMassive[i].TermsSet[j].NumVar].Min);
                        //    result.LearnSamplesSet.InputAttributeMax(fuzzyRulesDatabaseMassive[i].TermsSet[j].Max)

                        //  fuzzyRulesDatabaseMassive[i].TermsSet[j] .Parametrs[u]
                        //});
                    }
                    populationMassive[i].TermsSet[j].Parametrs = tempMassive;
                }
                //});
            }
            //});
        }
Exemplo n.º 28
0
        public void init_first(KnowlegeBaseTSARules base_rule, Random rand, FuzzySystem.FuzzyAbstract.learn_algorithm.conf.ESConfig.Type_init prm_init)
        {
            bool the_first = true;

            int count_ready = 0;

            do
            {
                the_popualate.Add(new Individ(base_rule, Data, count_vars, the_first, rand, prm_init));

                count_ready++;
                the_first = false;
            } while (count_ready < size_populate);
        }
Exemplo n.º 29
0
        public void fullCrossover()
        {
            //     childrenMassive = new KnowlegeBaseSARules[currentConf.Количество_генерируемых_потомков];


            //Parallel.For(0, currentConf.Количество_генерируемых_потомков, i =>
            for (int i = 0; i < currentConf.GENCCountChild; i++)
            {
                int a = allRandom.Next(populationMassive.Count());
                int b = allRandom.Next(populationMassive.Count());
                childrenMassive[i] = new KnowlegeBaseTSARules(crossoverFunc(populationMassive[a], populationMassive[b]));
            }
            //});
        }
Exemplo n.º 30
0
        /// <summary>
        /// Step 1
        /// </summary>
        /// <param name="Classifier"></param>
        /// <param name="config"></param>

        protected virtual void init(TSAFuzzySystem Approx, ACOSearchConf config)
        {
            ACO_iterationCount       = config.ACOCountIteration;
            ACO_antCount             = config.ACOCountAnt;
            ACO_decisionArchiveCount = config.ACODescisionArchiveSize;
            ACO_q       = config.ACOQ;
            ACO_xi      = config.ACOXi;
            result      = Approx;
            colonyCount = result.RulesDatabaseSet[0].TermsSet.Count;
            colonyList  = new List <Colony>();
            newSolution = new KnowlegeBaseTSARules(result.RulesDatabaseSet[0]);

            //    current_database = result.RulesDatabaseSet.Count -1;

            baseError = result.approxLearnSamples(newSolution);
        }