/// <summary>
        /// Initializes a new instance of the <see cref="DifferentialEvolutionStrategy{TInstance, TResult}"/> class.
        /// </summary>
        /// <param name="configuration">Options used for this instance.</param>
        /// <param name="parameterTree">Provides the tunable parameters.</param>
        /// <param name="genomeBuilder">Responsible for creation, modification and crossover of genomes.
        /// Needs to be compatible with the given parameter tree and configuration.</param>
        /// <param name="genomeSorter">
        /// An <see cref="IActorRef" /> to a <see cref="GenomeSorter{TInstance,TResult}" />.
        /// </param>
        /// <param name="targetRunResultStorage">
        /// An <see cref="IActorRef" /> to a <see cref="ResultStorageActor{TInstance,TResult}" />
        /// which knows about all executed target algorithm runs and their results.
        /// </param>
        public DifferentialEvolutionStrategy(
            AlgorithmTunerConfiguration configuration,
            ParameterTree parameterTree,
            GenomeBuilder genomeBuilder,
            IActorRef genomeSorter,
            IActorRef targetRunResultStorage)
            : base(configuration, parameterTree, targetRunResultStorage, new GenomeSearchPointSorter <TInstance>(genomeSorter))
        {
            this._strategyConfiguration =
                this.Configuration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);

            if (this._strategyConfiguration.FocusOnIncumbent)
            {
                this._informationFlow = new LocalDifferentialEvolutionInformationFlow(
                    this._strategyConfiguration,
                    parameterTree,
                    genomeBuilder);
            }
            else
            {
                this._informationFlow = new GlobalDifferentialEvolutionInformationFlow(
                    this._strategyConfiguration,
                    parameterTree,
                    genomeBuilder);
            }

            this._searchPointFactory = (vector, parent) => new GenomeSearchPoint(vector, parent, genomeBuilder);

            this._differentialEvolutionRunner = this.CreateDifferentialEvolutionRunner(
                this._strategyConfiguration.DifferentialEvolutionConfiguration.InitialMeanMutationFactor,
                this._strategyConfiguration.DifferentialEvolutionConfiguration.InitialMeanCrossoverRate);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalDifferentialEvolutionInformationFlow"/> class.
 /// </summary>
 /// <param name="strategyConfiguration">
 /// Options used for the <see cref="DifferentialEvolutionStrategy{TInstance,TResult}"/>.
 /// </param>
 /// <param name="parameterTree">Provides the tunable parameters.</param>
 /// <param name="genomeBuilder">Responsible for creation, modification and crossover of genomes.</param>
 public LocalDifferentialEvolutionInformationFlow(
     DifferentialEvolutionStrategyConfiguration strategyConfiguration,
     ParameterTree parameterTree,
     GenomeBuilder genomeBuilder)
 {
     this._strategyConfiguration = strategyConfiguration ?? throw new ArgumentNullException(nameof(strategyConfiguration));
     this._parameterTree         = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree));
     this._genomeBuilder         = genomeBuilder ?? throw new ArgumentNullException(nameof(genomeBuilder));
 }
        /// <summary>
        /// Called before every test.
        /// </summary>
        protected override void InitializeDefault()
        {
            base.InitializeDefault();

            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0.25);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);

            var root = new AndNode();

            root.AddChild(new ValueNode <int>(ExtractIntegerValue.ParameterName, new IntegerDomain(-1, 3)));
            root.AddChild(new ValueNode <int>("quasi-continuous", new IntegerDomain(0, this._deConfiguration.MinimumDomainSize + 1)));
            this._parameterTree = new ParameterTree(root);

            this._genomeBuilder = new GenomeBuilder(this._parameterTree, this._completeConfiguration);
        }
        public void DefineCompetitivePopulationThrowsForIncumbentChangeOnlyWithoutIncumbent()
        {
            // Create configuration with a replacement rate of 0.
            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);
            var informationFlow = new LocalDifferentialEvolutionInformationFlow(
                this._deConfiguration,
                this._parameterTree,
                this._genomeBuilder);

            // Call defineCompetitivePopulation without an incumbent.
            Assert.Throws <ArgumentNullException>(
                () => informationFlow
                .DefineCompetitivePopulation(
                    originalCompetitives: this.CreateRandomGenomes(number: 6).ToList(),
                    originalIncumbent: null,
                    mostRecentSorting: this.CreateRandomSearchPoints())
                .ToList());
        }
        public void DefineCompetitivePopulationWorksForIncumbentChangeOnly()
        {
            // Create configuration with a replacement rate of 0.
            this._completeConfiguration = LocalDifferentialEvolutionInformationFlowTest.CreateConfiguration(replacementRate: 0);
            this._deConfiguration       =
                this._completeConfiguration.ExtractDetailedConfiguration <DifferentialEvolutionStrategyConfiguration>(
                    DifferentialEvolutionStrategyArgumentParser.Identifier);
            var informationFlow = new LocalDifferentialEvolutionInformationFlow(
                this._deConfiguration,
                this._parameterTree,
                this._genomeBuilder);

            // Create a competitive population which contains the same genome twice.
            var originalCompetitives = this.CreateRandomGenomes(number: 6).ToList();
            var incumbent            = originalCompetitives[3];

            originalCompetitives.Add(new Genome(incumbent));
            Assert.Equal(
                2,
                originalCompetitives.Count(individual => new Genome.GeneValueComparator().Equals(individual, incumbent)));

            // Call define competitive population with some search points.
            var searchPoints        = this.CreateRandomSearchPoints();
            var updatedCompetitives = informationFlow.DefineCompetitivePopulation(
                originalCompetitives,
                incumbent,
                searchPoints);

            // Best point should now replace incumbent in competitive population.
            var expectedCompetitives = originalCompetitives
                                       .Select(genome => genome.ToString())
                                       .ToList();

            expectedCompetitives.Remove(incumbent.ToString());
            expectedCompetitives.Add(new Genome(searchPoints[0].Genome.CreateMutableGenome(), incumbent.Age).ToString());
            Assert.Equal(
                expectedCompetitives.OrderBy(x => x).ToArray(),
                updatedCompetitives.Select(genome => genome.ToString()).OrderBy(x => x).ToArray());
        }
Esempio n. 6
0
        /// <summary>
        /// Called before every test.
        /// </summary>
        protected override void InitializeDefault()
        {
            base.InitializeDefault();

            var strategyConfigurationBuilder = new DifferentialEvolutionStrategyConfiguration.DifferentialEvolutionStrategyConfigurationBuilder()
                                               .SetFocusOnIncumbent(false)
                                               .SetDifferentialEvolutionConfigurationBuilder(
                new DifferentialEvolutionConfiguration.DifferentialEvolutionConfigurationBuilder().SetBestPercentage(0.2));

            this._completeConfiguration = new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder()
                                          .SetEnableRacing(true)
                                          .AddDetailedConfigurationBuilder(
                RegressionForestArgumentParser.Identifier,
                new GenomePredictionRandomForestConfig.GenomePredictionRandomForestConfigBuilder())
                                          .AddDetailedConfigurationBuilder(
                DifferentialEvolutionStrategyArgumentParser.Identifier,
                strategyConfigurationBuilder)
                                          .Build(maximumNumberParallelEvaluations: 1);

            this._genomeBuilder   = new GenomeBuilder(this._parameterTree, this._completeConfiguration);
            this._deConfiguration = strategyConfigurationBuilder.BuildWithFallback(null);
        }