Esempio n. 1
0
        private void calculateVHL(KnowlegeBasePCRules Explorer, KnowlegeBasePCRules ExplorerBestPosition)
        {
            KnowlegeBasePCRules part1 = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);
            KnowlegeBasePCRules part2 = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);

            for (int i = 0; i < part1.TermsSet.Count; i++)
            {
                for (int j = 0; j < part1.TermsSet[i].Parametrs.Length; j++)
                {
                    part1.TermsSet[i].Parametrs[j] = (ExplorerBestPosition.TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * AGlobal * rand.NextDouble();
                    //
                }
            }

            for (int i = 0; i < part2.TermsSet.Count; i++)
            {
                for (int j = 0; j < part2.TermsSet[i].Parametrs.Length; j++)
                {
                    part2.TermsSet[i].Parametrs[j] = (HeadLeader.TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * BGlobal * rand.NextDouble();
                    //
                }
            }

            for (int i = 0; i < VelocityVectorHL.TermsSet.Count; i++)
            {
                for (int j = 0; j < VelocityVectorHL.TermsSet[i].Parametrs.Length; j++)
                {
                    VelocityVectorHL.TermsSet[i].Parametrs[j] = (part1.TermsSet[i].Parametrs[j] + part2.TermsSet[i].Parametrs[j]);
                    //
                }
            }
        }
Esempio n. 2
0
        protected void InitRulesBySamples(PCFuzzySystem Classifier, TypeTermFuncEnum typeFunc)
        {
            if ((Classifier.RulesDatabaseSet == null) || (Classifier.RulesDatabaseSet.Count == 0))
            {
                KnowlegeBasePCRules temp_rules = new KnowlegeBasePCRules();
                Classifier.RulesDatabaseSet.Add(temp_rules);
            }

            for (int i = 0; i < Classifier.CountClass; i++)
            {
                if (!ExistClassFeatureMax(i) || !ExistClassFeatureMin(i))
                {
                    continue;
                }
                int[] order_terms = new int[Classifier.CountFeatures];

                for (int j = 0; j < Classifier.CountFeatures; j++)
                {
                    if (Classifier.AcceptedFeatures[j] == false)
                    {
                        continue;
                    }


                    double[] paramerts = new double[Term.CountParamsinSelectedTermType(typeFunc)];
                    switch (typeFunc)
                    {
                    case TypeTermFuncEnum.Треугольник:
                        paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        paramerts[2] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        paramerts[1] = (paramerts[0] + paramerts[2]) / 2;
                        break;

                    case TypeTermFuncEnum.Гауссоида:
                        paramerts[0] = (max_for_class[i][j] +
                                        min_for_class[i][j]) / 2;
                        paramerts[1] = (paramerts[0] - min_for_class[i][j]) / 3;      // rule of 3g
                        break;

                    case TypeTermFuncEnum.Парабола:
                        paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        paramerts[1] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        break;

                    case TypeTermFuncEnum.Трапеция:
                        paramerts[0] = min_for_class[i][j] - 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        paramerts[3] = max_for_class[i][j] + 0.001 * (max_for_class[i][j] - min_for_class[i][j]);
                        paramerts[1] = paramerts[0] + 0.4 * (paramerts[3] - paramerts[0]);
                        paramerts[2] = paramerts[0] + 0.6 * (paramerts[3] - paramerts[0]);
                        break;
                    }
                    Term temp_term = new Term(paramerts, typeFunc, j);
                    Classifier.RulesDatabaseSet[0].TermsSet.Add(temp_term);
                    order_terms[j] = Classifier.RulesDatabaseSet[0].TermsSet.Count - 1;
                }
                PCRule temp_Rule = new PCRule(Classifier.RulesDatabaseSet[0].TermsSet, order_terms,
                                              Classifier.LearnSamplesSet.OutputAttribute.LabelsValues[i], 1);
                Classifier.RulesDatabaseSet[0].RulesDatabase.Add(temp_Rule);
            }
        }
Esempio n. 3
0
        public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classifier, ILearnAlgorithmConf conf)
        {
            BacteryAlgorithmConfig Config = conf as BacteryAlgorithmConfig;

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


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

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

            if (newResult > backResult)
            {
                result.RulesDatabaseSet[0] = backSave;
            }
            result.RulesDatabaseSet[0].TermsSet.Trim();
            return(result);
        }
Esempio n. 4
0
        private int findNearestLocalLeader(KnowlegeBasePCRules Explorer, int p_i)
        {
            int    index   = 0;
            double minimum = 999999999999;

            for (int k = 0; k < numberOfLocalLeaders; k++)
            {
                double distance = 0;
                for (int i = 0; i < LocalLeaders[p_i][k].TermsSet.Count; i++)
                {
                    for (int j = 0; j < LocalLeaders[p_i][k].TermsSet[i].Parametrs.Length; j++)
                    {
                        distance += Math.Pow(Explorer.TermsSet[i].Parametrs[j] - LocalLeaders[p_i][k].TermsSet[i].Parametrs[j], 2);
                    }
                }
                //for (int i = 0; i < Explorer.RulesDatabase.Count; i++)
                //{
                //  distance += Math.Pow(Explorer.RulesDatabase[i].Cons_DoubleOutput - LocalLeaders[k].RulesDatabase[i].Cons_DoubleOutput, 2);
                //}
                distance = Math.Sqrt(distance);
                if (distance < minimum)
                {
                    minimum = distance;
                    index   = k;
                }
            }
            return(index);
        }
Esempio n. 5
0
        //нахождение расстояния между крилями
        private double Distance(KnowlegeBasePCRules x, KnowlegeBasePCRules 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].Cons_DoubleOutput - y.RulesDatabase[i].Cons_DoubleOutput, 2);
            //}
            dist = Math.Sqrt(sum);

            /*
             #if debug
             *  //вывод значение dist соседа
             *  Console.Write("Значение dist = ");
             *  Console.WriteLine(dist);
             #endif
             */
            return(dist);
        }
Esempio n. 6
0
        private PCFuzzySystem BreakCrossTerm(PCFuzzySystem Classifier, int Feature, int indexATerm, int indexBterm, int dataBase)
        {
            PCFuzzySystem       result     = Classifier;
            KnowlegeBasePCRules 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);
        }
Esempio n. 7
0
        KnowlegeBasePCRules unifiedCrossover(KnowlegeBasePCRules parent1, KnowlegeBasePCRules parent2)
        {
            double b = (currentConf.GENCPopabilityCrossover / 100);
            KnowlegeBasePCRules child;

            child = new KnowlegeBasePCRules(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.Weigths.Clone() as double[];
            double[] tempMassiveP2 = parent2.Weigths.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.Weigths = tempMassiveCh;
            //});
            return(child);
        }
Esempio n. 8
0
 public virtual void preIterate(PCFuzzySystem Classify, ILearnAlgorithmConf conf)
 {
     result = Classify;
     Init(conf);
     HeadLeader       = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);
     VelocityVector   = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);
     VelocityVectorLL = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);
     VelocityVectorHL = new KnowlegeBasePCRules(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 <KnowlegeBasePCRules, KnowlegeBasePCRules>();
     foreach (var Particle in Population)
     {
         ParticlesBest.Add(Particle, Universal);
     }
     LocalLeaders      = new KnowlegeBasePCRules[numberOfLocalLeaders];
     ExplorerParticles = new KnowlegeBasePCRules[numberOfAllParts - numberOfAimlessParts - numberOfLocalLeaders - 1];
     AimlessParticles  = new KnowlegeBasePCRules[numberOfAimlessParts];
     iter       = 0;
     Population = ListPittsburgClassifierTool.SortRules(Population, result);
 }
Esempio n. 9
0
        //нахождение расстояния ощущения (соседства)
        private List <int> countneihbors(KnowlegeBasePCRules 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);
        }
Esempio n. 10
0
        public void GetDots(PCFuzzySystem approx, KnowlegeBasePCRules 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 PCFuzzySystem(samples, samples);

            var usedRules = GetRules(knowlegeBase);

            system.RulesDatabaseSet.Add(new KnowlegeBasePCRules(knowlegeBase, null));
        }
Esempio n. 11
0
        private void calculateVLL(KnowlegeBasePCRules Explorer, KnowlegeBasePCRules ExplorerBestPosition, int index, int p_i)
        {
            KnowlegeBasePCRules part1 = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);
            KnowlegeBasePCRules part2 = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);

            for (int i = 0; i < part1.TermsSet.Count; i++)
            {
                for (int j = 0; j < part1.TermsSet[i].Parametrs.Length; j++)
                {
                    part1.TermsSet[i].Parametrs[j] = (ExplorerBestPosition.TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * ALocal * rand.NextDouble();
                }
            }

            for (int i = 0; i < part2.TermsSet.Count; i++)
            {
                for (int j = 0; j < part2.TermsSet[i].Parametrs.Length; j++)
                {
                    part2.TermsSet[i].Parametrs[j] = (LocalLeaders[p_i][index].TermsSet[i].Parametrs[j] - Explorer.TermsSet[i].Parametrs[j]) * BLocal * rand.NextDouble();
                }
            }

            for (int i = 0; i < VelocityVectorLL[p_i].TermsSet.Count; i++)
            {
                for (int j = 0; j < VelocityVectorLL[p_i].TermsSet[i].Parametrs.Length; j++)
                {
                    VelocityVectorLL[p_i].TermsSet[i].Parametrs[j] = (part1.TermsSet[i].Parametrs[j] + part2.TermsSet[i].Parametrs[j]);
                }
            }
        }
Esempio n. 12
0
        private void ChangeExplorerPositions(int i, int p_i)
        {
            KnowlegeBasePCRules temp = new KnowlegeBasePCRules();

            temp = ExplorerParticles[p_i][i];
            for (int k = 0; k < temp.TermsSet.Count; k++)
            {
                for (int j = 0; j < temp.TermsSet[k].Parametrs.Length; j++)
                {
                    temp.TermsSet[k].Parametrs[j] += VelocityVector[p_i].TermsSet[k].Parametrs[j];
                }
            }

            if (result.ClassifyLearnSamples(ExplorerParticles[p_i][i]) < result.ClassifyLearnSamples(ParticlesBest[p_i][ExplorerParticles[p_i][i]]))
            {
                ParticlesBest[p_i].Remove(ExplorerParticles[p_i][i]);
                ParticlesBest[p_i].Add(temp, ExplorerParticles[p_i][i]);
            }
            else
            {
                KnowlegeBasePCRules tmp = new KnowlegeBasePCRules();
                tmp = ParticlesBest[p_i][ExplorerParticles[p_i][i]];
                ParticlesBest[p_i].Remove(ExplorerParticles[p_i][i]);
                ParticlesBest[p_i].Add(temp, tmp);
            }
            ExplorerParticles[p_i][i] = temp;
        }
Esempio n. 13
0
        //нахождение расстояния ощущения (соседства)
        private double distneihbor(KnowlegeBasePCRules 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 / (5.0 * Population.Length));

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

            return(dneihbor);
        }
Esempio n. 14
0
        private List <KnowlegeBasePCRules> SetPopulation(List <KnowlegeBasePCRules> Population)
        {
            KnowlegeBasePCRules TempRule = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);

            Population.Add(TempRule);
            Universal = TempRule;
            for (int i = 1; i < numberOfAllParts; i++)
            {
                Population.Add(new KnowlegeBasePCRules(TempRule));
                for (int j = 0; j < Population[i].TermsSet.Count; j++)
                {
                    for (int k = 0; k < Population[i].TermsSet[j].Parametrs.Length; k++)
                    {
                        Population[i].TermsSet[j].Parametrs[k] = GaussRandom.Random_gaussian(rand, Population[i].TermsSet[j].Parametrs[k], 0.1 * Population[i].TermsSet[j].Parametrs[k]);
                    }
                }
                result.UnlaidProtectionFix(Population[i]);
            }
            Universal = new KnowlegeBasePCRules(TempRule);
            for (int i = 0; i < Universal.TermsSet.Count; i++)
            {
                for (int j = 0; j < Universal.TermsSet[i].Parametrs.Length; j++)
                {
                    Universal.TermsSet[i].Parametrs[j] = GaussRandom.Random_gaussian(rand, Universal.TermsSet[i].Parametrs[j], 0.1 * Universal.TermsSet[i].Parametrs[j]);
                }
            }

            return(Population);
        }
 public static void Inject(this KnowlegeBasePCRules[] Destination, int indexStartDestination, KnowlegeBasePCRules[] Source, int indexStartSource, int CountIjected, PCFuzzySystem Classifier)
 {
     Destination = Destination.SortRules(Classifier);
     for (int i = 0; i < CountIjected; i++)
     {
         Destination[i + indexStartDestination] = new KnowlegeBasePCRules(Source[i + indexStartSource]);
     }
 }
Esempio n. 16
0
        public virtual void oneIterate(PCFuzzySystem 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].Weigths.Length];
                double[] bfw = new double[V[j].Weigths.Length];
                for (int k = 0; k < V[j].Weigths.Length; k++)
                {
                    bfw[k] = V[j].Weigths[k] * w + c1 * rnd.NextDouble() * (Pi[j].Weigths[k] - X[j].Weigths[k]) +
                             c2 * rnd.NextDouble() * (Pg.Weigths[k] - X[j].Weigths[k]);
                    double sw = X[j].Weigths[k] + bfw[k];
                    if (sw > 0 && sw <= 2)
                    {
                        bf[k] = sw;
                    }
                    else
                    {
                        bf[k]  = X[j].Weigths[k];
                        bfw[k] = V[j].Weigths[k];
                    }
                }
                X[j].Weigths = bf;
                V[j].Weigths = bfw;
                double newError = 0;
                bool   success  = true;
                try
                {
                    newError = result.ClassifyLearnSamples(X[j]);
                }
                catch (Exception)
                {
                    success = false;
                }
                if (success && (newError > Errors[j]))
                {
                    OldErrors[j] = Errors[j];
                    Errors[j]    = newError;

                    Pi[j] = new KnowlegeBasePCRules(X[j]);
                }
                if (minError < newError)
                {
                    minError = newError;
                    Pg       = new KnowlegeBasePCRules(X[j]);
                }
            }
        }
Esempio n. 17
0
        public override PCFuzzySystem Generate(PCFuzzySystem Classifier, IGeneratorConf config)
        {
            start_add_rules = Classifier.RulesDatabaseSet.Count;
            PCFuzzySystem result = Classifier;

            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 < Classifier.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++)
            {
                KnowlegeBasePCRules temp_rules = new  KnowlegeBasePCRules(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.ErrorLearnSamples(result.RulesDatabaseSet[start_add_rules + i]));
            }

            int best_index           = errors_of_systems.IndexOf(errors_of_systems.Min());
            KnowlegeBasePCRules 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);
        }
Esempio n. 18
0
 public virtual void WJVector_gen(int j)
 {
     WJVector = new KnowlegeBasePCRules(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;
         }
     }
 }
Esempio n. 19
0
        private PCFuzzySystem UniTerm(PCFuzzySystem Classifier, int Feature, int indexATerm, int indexBterm, int dataBase)
        {
            PCFuzzySystem       result     = Classifier;
            KnowlegeBasePCRules 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 <PCRule> 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 <PCRule> 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);
        }
Esempio n. 20
0
        private void ChangeAimlessPosition(KnowlegeBasePCRules Aimless, int p_i)
        {
            KnowlegeBasePCRules GlobalRand = new KnowlegeBasePCRules(result.RulesDatabaseSet[0]);

            SSVector_gen(p_i);
            for (int i = 0; i < Aimless.TermsSet.Count; i++)
            {
                for (int j = 0; j < Aimless.TermsSet[i].Parametrs.Length; j++)
                {
                    Aimless.TermsSet[i].Parametrs[j] = ((rand.NextDouble() * 1.5 + 0.5) * (SSVector[p_i].TermsSet[i].Parametrs[j]));
                }
            }
        }
Esempio n. 21
0
        public virtual void Final()
        {
            KnowlegeBasePCRules best = main_pop.get_best_database();
            double errorBest         = result.ErrorLearnSamples(best);
            double currentError      = result.ErrorLearnSamples(result.RulesDatabaseSet[0]);

            if (currentError > errorBest)
            {
                result.RulesDatabaseSet[0] = main_pop.get_best_database();
            }
            result.RulesDatabaseSet[0] = main_pop.get_best_database();
            GC.Collect();
        }
Esempio n. 22
0
        private double Distance(KnowlegeBasePCRules x, KnowlegeBasePCRules y)
        {
            double 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);
                }
            }
            return(sum);
        }
        public override PCFuzzySystem Generate(PCFuzzySystem Classifier, 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;


            Classifierk_mean_base K_Agl = null;

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

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

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

            KnowlegeBasePCRules New_Rules = new KnowlegeBasePCRules();

            for (int i = 0; i < count_rules; i++)
            {
                int []      order_terms = new int [Classifier.LearnSamplesSet.CountVars];
                List <Term> term_set    = new List <Term>();
                for (int j = 0; j < Classifier.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, Classifier);
            }

            PCFuzzySystem Result = Classifier;

            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);
        }
Esempio n. 24
0
        void fullInit()
        {
            populationMassive = new KnowlegeBasePCRules[currentConf.GENCPopulationSize];
            childrenMassive   = new KnowlegeBasePCRules[currentConf.GENCCountChild];

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



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

                for (int j = 0; j < populationMassive[i].Weigths.Count(); j++)
                {
                    tempMassive[j] = initFunc(populationMassive[i].Weigths[j],
                                              currentConf.GENCScateDeverceInit,
                                              fullFuzzySystem.LearnSamplesSet.OutputAttribute.Max,
                                              fullFuzzySystem.LearnSamplesSet.OutputAttribute.Min);
                }
                populationMassive[i].Weigths = 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;
                }
                //});
            }
            //});
        }
Esempio n. 25
0
        public void init_first(KnowlegeBasePCRules 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);
        }
Esempio n. 26
0
        public override PCFuzzySystem TuneUpFuzzySystem(PCFuzzySystem Classifier, ILearnAlgorithmConf config)
        {
            start_add_rules = Classifier.RulesDatabaseSet.Count;
            PCFuzzySystem result = Classifier;

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



            OptimizeRullesShrinkConf Config = config as OptimizeRullesShrinkConf;

            Request_shrink_Rule = Config.ORSCCountShrinkRules;
            int         count_of_swith_off    = Request_shrink_Rule;
            List <byte> Varians_of_run_system = new List <byte>();

            for (int i = 0; i < Classifier.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++)
            {
                KnowlegeBasePCRules temp_rules = new  KnowlegeBasePCRules(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.ErrorLearnSamples(result.RulesDatabaseSet[start_add_rules + i]));
            }

            int best_index           = errors_of_systems.IndexOf(errors_of_systems.Min());
            KnowlegeBasePCRules 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);
        }
Esempio n. 27
0
        /// <summary>
        /// Step 1
        /// </summary>
        /// <param name="Classifier"></param>
        /// <param name="config"></param>

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

            basePrecission = result.ClassifyLearnSamples(newSolution);
        }
Esempio n. 28
0
        //расчитыавем значение X с крышкой
        public KnowlegeBasePCRules CalcXroof(KnowlegeBasePCRules xi, KnowlegeBasePCRules xj)
        {
            var Xroof = new KnowlegeBasePCRules(xi);

            for (int t = 0; t < Xroof.TermsSet.Count; t++)
            {
                for (int p = 0; p < Xroof.TermsSet[t].CountParams; p++)
                {
                    Xroof.TermsSet[t].Parametrs[p] = (xj.TermsSet[t].Parametrs[p] - xi.TermsSet[t].Parametrs[p]) / (Math.Sqrt(Math.Pow((xj.TermsSet[t].Parametrs[p] - xi.TermsSet[t].Parametrs[p]), 2) + Math.Pow((xi.TermsSet[t].Parametrs[p] - xj.TermsSet[t].Parametrs[p]), 2)) + e);
                }
            }

            return(Xroof);
        }
Esempio 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 KnowlegeBasePCRules(crossoverFunc(populationMassive[a], populationMassive[b]));
            }
            //});
        }
Esempio n. 30
0
 private void SetRoles()
 {
     HeadLeader = Population[0];
     for (int i = 1; i <= numberOfLocalLeaders; i++)
     {
         LocalLeaders[i - 1] = Population[i];
     }
     for (int i = numberOfAllParts - numberOfAimlessParts; i < numberOfAllParts; i++)
     {
         AimlessParticles[i - numberOfAllParts + numberOfAimlessParts] = Population[i];
     }
     for (int i = numberOfLocalLeaders + 1; i < numberOfAllParts - numberOfAimlessParts; i++)
     {
         ExplorerParticles[i - numberOfLocalLeaders - 1] = Population[i];
     }
 }