当前位置: 首页>>代码示例>>C#>>正文


C# Population.GetTop方法代码示例

本文整理汇总了C#中Population.GetTop方法的典型用法代码示例。如果您正苦于以下问题:C# Population.GetTop方法的具体用法?C# Population.GetTop怎么用?C# Population.GetTop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Population的用法示例。


在下文中一共展示了Population.GetTop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EvaluateProbe


//.........这里部分代码省略.........
                        listaRecomendacao[j] = tupla;
                    }

                    list_of_predictions.Add(listaRecomendacao);

                }

                //Usar o melhor
                double maiorMapping = 0;
                int idMaiorMapping = 0;

                //Testar cada individual
                for (int k = 0; k < list_of_predictions.Count; k++)
                {
                    int[] prediction_probe = (from t in list_of_predictions[k] select t.Item1).ToArray();

                    double resultado = PrecisionAndRecall.AP(prediction_probe, correct_items);

                    if (resultado > maiorMapping)
                    {
                        maiorMapping = resultado;
                        idMaiorMapping = k;

                    }

                }

                //Set global so Fitness itens can see.
                list_prediction_probes = list_of_predictions;
                correct_items_global = correct_items;

                //Algortimo Genetico
                /*   //  Crossover		= 80%
                   //  Mutation		=  5%
                   //  Population size = 100
                   //  Generations		= 2000
                   //  Genome size		= 2
                   GA ga = new GA(0.8, 0.05, 40, 400, list_prediction_probes.Count);

                   ga.FitnessFunction = new GAFunction(Fitness);

                   //ga.FitnessFile = @"H:\fitness.csv";
                   ga.Elitism = true;
                   ga.Go();

                   double[] values;
                   double fitness;
                   ga.GetBest(out values, out fitness);*/

                //create the GA using an initialised population and user defined Fitness Function
                const double crossoverProbability = 0.85;
                const double mutationProbability = 0.08;
                const int elitismPercentage = 5;

                //create a Population of random chromosomes of length 44
                var population = new Population(40, list_of_predictions.Count * 10, false, false);

                //create the genetic operators
                var elite = new Elite(elitismPercentage);
                var crossover = new Crossover(crossoverProbability, true)
                {
                    CrossoverType = CrossoverType.DoublePoint
                };
                var mutation = new BinaryMutate(mutationProbability, true);

                //create the GA itself
                var ga = new GeneticAlgorithm(population, CalculateFitness);

                //add the operators to the ga process pipeline
                ga.Operators.Add(elite);
                ga.Operators.Add(crossover);
                ga.Operators.Add(mutation);

                //run the GA
                ga.Run(Terminate);

                var best = population.GetTop(1)[0];
                double rangeConst = 1 / (System.Math.Pow(2, 10) - 1);
                ga_weights[original] = new List<double>();

                for (int i = 0; i < list_prediction_probes.Count; i++)
                {
                    string str = best.ToBinaryString((i * 10), 10);
                    Int64 convertInt32 = Convert.ToInt32(str, 2);

                    double x = (convertInt32 * rangeConst);

                    ga_weights[original].Add(x);
                }

                best_alg[original] = idMaiorMapping;
                num_users++;

                if (num_users % 10 == 0)
                    Console.Error.Write(".");
                if (num_users % 100 == 0)
                    Console.Error.WriteLine("");

            }
        }
开发者ID:wendelad,项目名称:RecSys,代码行数:101,代码来源:Ensemble.cs

示例2: Invoke

        public void Invoke(Population currentPopulation, 
			ref Population newPopulation, FitnessFunction fitnesFunctionDelegate)
        {
            //take top 3
            var num = 3;
            var min = System.Math.Min (num, currentPopulation.Solutions.Count);

            var best = currentPopulation.GetTop (min);
            var cutoff = best [min-1].Fitness;
            var genecount = best [0].Genes.Count;
            try
            {

                var config_vars = (ConfigVars)best[rand.Next(0,min-1)].Genes [rand.Next(0,genecount-1)].ObjectValue;
                var index = rand.Next(0, config_vars.vars.Count-1);
                var key = config_vars.vars. ElementAt(index).Key;
                newPopulation.Solutions.Clear();
                foreach (var chromosome in currentPopulation.Solutions) {
                    if (chromosome.Fitness < cutoff) {
                        foreach (var gene in chromosome.Genes) {
                            var target_config_vars = (ConfigVars)gene.ObjectValue;
                            target_config_vars.vars [key] = config_vars.vars [key];
                        }
                    }
                    newPopulation.Solutions.Add (chromosome);
                }

                _invoked++;
            }
            catch(Exception e) {
                Console.WriteLine ("OOPS! " + e.Message + " " + e.StackTrace);
            }
        }
开发者ID:chrisdk2015,项目名称:LeanOptimization,代码行数:33,代码来源:Program.cs


注:本文中的Population.GetTop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。