protected override void Evolve(EvaluatorBase evaluator)
        {
            var offspringPopulationSize          = Parameters.OffspringPopulationSize;
            var numberOfParentsSolutionsToSelect = Parameters.NumberOfParentsSolutionsToSelect;

            for (var i = 0; i < offspringPopulationSize; i++)
            {
                var parentsPopulation = new Solution[numberOfParentsSolutionsToSelect];

                for (var j = 0; j < numberOfParentsSolutionsToSelect; j++)
                {
                    parentsPopulation[j] = ParentsSelector.Select(BasePopulation);
                }

                OffspringPopulation[i] = StdDeviationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]);
                OffspringPopulation[i] = RotationsRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]);
                OffspringPopulation[i] = ObjectRecombiner.Recombine(parentsPopulation, OffspringPopulation[i]);

                OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]);
                OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]);
                OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]);

                OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]);
            }

            BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation);
        }
コード例 #2
0
        //public IBenchmark Benchmark { get; set; }
        //public IPopulationGenerator PopulationGenerator { get; set; }
        //public IEvaluator Evaluator { get; set; }
        //public ILogger Logger { get; set; }
        //public IMutator ObjectMutator { get; set; }
        //public IMutator StdDeviationsMutator { get; set; }
        //public IMutationRuleSupervisor MutationRuleSupervisor { get; set; }
        //public IParentsSelector ParentsSelector { get; set; }
        //public ISurvivorsSelector SurvivorsSelector { get; set; }
        //public IPointsGenerator PositivePointsGenerator { get; set; }
        //public IPointsGenerator NegativePointsGenerator { get; set; }
        //public ExperimentParameters ExperimentParameters { get; set; }
        //public Solution[] BasePopulation { get; set; }
        //public Solution[] OffspringPopulation { get; set; }
        //public Solution[] InitialPopulation { get; set; }

        //public override void SynthesizeModel(Point[] trainingPoints)
        //{
        //    var offspringPopulationSize = ExperimentParameters.OffspringPopulationSize;
        //    var numberOfGenerations = ExperimentParameters.NumberOfGenerations;

        //    BasePopulation = PopulationGenerator.GeneratePopulation(ExperimentParameters);

        //    for (var i = 0; i < offspringPopulationSize; i++)
        //        OffspringPopulation[i] = new Solution(ExperimentParameters);

        //    InitialPopulation = BasePopulation.DeepCopyByExpressionTree();

        //    for (var i = 0; i < numberOfGenerations; i++)
        //    {
        //        for (var j = 0; j < offspringPopulationSize; j++)
        //        {
        //            OffspringPopulation[j] = ParentsSelector.Select(BasePopulation)[0];

        //            OffspringPopulation[j] = StdDeviationsMutator.Mutate(OffspringPopulation[j]);
        //            OffspringPopulation[j] = ObjectMutator.Mutate(OffspringPopulation[j]);

        //            OffspringPopulation[j].FitnessScore = Evaluator.Evaluate(OffspringPopulation[j]);
        //        }
        //        BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation);
        //    }
        //}

        protected override void Evolve(int offspringPopulationSize)
        {
            for (var j = 0; j < offspringPopulationSize; j++)
            {
                OffspringPopulation[j] = ParentsSelector.Select(BasePopulation)[0];

                OffspringPopulation[j] = StdDeviationsMutator.Mutate(OffspringPopulation[j]);
                OffspringPopulation[j] = ObjectMutator.Mutate(OffspringPopulation[j]);

                OffspringPopulation[j].FitnessScore = Evaluator.Evaluate(OffspringPopulation[j]);
            }
            BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation);
        }
        protected override void Evolve(EvaluatorBase evaluator)
        {
            var offspringPopulationSize = Parameters.OffspringPopulationSize;

            for (var i = 0; i < offspringPopulationSize; i++)
            {
                OffspringPopulation[i] = ParentsSelector.Select(BasePopulation);

                OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]);
                OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]);

                OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]);
            }

            BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation);
        }
        //HACKS TODO
        protected override void Evolve(EvaluatorBase evaluator)
        {
            var offspringPopulationSize = Parameters.OffspringPopulationSize;

            //var stdDevsMutationTime = TimeSpan.Zero;
            //var rotationsMutationTime = TimeSpan.Zero;
            //var objectMutationTime = TimeSpan.Zero;
            //var evaluationTime = TimeSpan.Zero;

            //var stoper = new Stopwatch();

            for (var i = 0; i < offspringPopulationSize; i++)
            {
                OffspringPopulation[i] = ParentsSelector.Select(BasePopulation);

                if (Parameters.TrackEvolutionSteps)
                {
                    CurrentMutation = new MutationStep(ParentsSelector.LastSelectedParentIndex, OffspringPopulation[i]);
                }

                //stoper.Restart();
                OffspringPopulation[i] = StdDeviationsMutator.Mutate(OffspringPopulation[i]);
                //stoper.Stop();
                //stdDevsMutationTime += stoper.Elapsed;

                //stoper.Restart();
                OffspringPopulation[i] = RotationsMutator.Mutate(OffspringPopulation[i]);
                //stoper.Stop();
                //rotationsMutationTime += stoper.Elapsed;

                //stoper.Restart();
                OffspringPopulation[i] = ObjectMutator.Mutate(OffspringPopulation[i]);
                //stoper.Stop();
                //objectMutationTime += stoper.Elapsed;

                //stoper.Restart();
                OffspringPopulation[i].FitnessScore = evaluator.Evaluate(OffspringPopulation[i]);
                //stoper.Stop();
                //evaluationTime += stoper.Elapsed;

                if (Parameters.TrackEvolutionSteps)
                {
                    CurrentMutation.Offspring = OffspringPopulation[i].DeepCopyByExpressionTree();
                    CurrentEvolutionStep.Mutations.Add(CurrentMutation);
                }
            }

            //stoper.Restart();
            BasePopulation = SurvivorsSelector.Select(BasePopulation, OffspringPopulation);
            //stoper.Stop();

            //Statistics.MeanSurvivorsSelectionTime += stoper.Elapsed;
            //Statistics.MeanStdDevsMutationTime += TimeSpan.FromTicks(stdDevsMutationTime.Ticks / offspringPopulationSize);
            //Statistics.MeanRotationsMutationTime += TimeSpan.FromTicks(rotationsMutationTime.Ticks / offspringPopulationSize);
            //Statistics.MeanObjectMutationTime += TimeSpan.FromTicks(objectMutationTime.Ticks / offspringPopulationSize);
            //Statistics.MeanEvaluationTime += TimeSpan.FromTicks(evaluationTime.Ticks / offspringPopulationSize);

            if (Parameters.TrackEvolutionSteps)
            {
                CurrentEvolutionStep.NewPopulation = BasePopulation.DeepCopyByExpressionTree();
            }
        }