public void DefineCompetitivePopulationReturnsCurrentSearchPoints() { var originalCompetitives = new List <Genome>(); for (int i = 0; i < 5; i++) { originalCompetitives.Add(this._genomeBuilder.CreateRandomGenome(age: i % 3)); } var searchPoints = new List <GenomeSearchPoint>(); for (int i = 0; i < 8; i++) { searchPoints.Add( GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 0), this._parameterTree, 0, this._genomeBuilder)); } var informationFlowStrategy = new GlobalDifferentialEvolutionInformationFlow( this._deConfiguration, this._parameterTree, this._genomeBuilder); var competitiveIndividuals = informationFlowStrategy.DefineCompetitivePopulation(originalCompetitives, null, searchPoints); Assert.Equal( searchPoints.Select(point => point.Genome.ToString()).OrderBy(x => x).ToArray(), competitiveIndividuals.Select(genome => genome.ToString()).OrderBy(x => x).ToArray()); }
public void BaseRandomPointOnGenomeThrowsForMissingGenomeBuilder() { Assert.Throws <ArgumentNullException>( () => GenomeSearchPoint.BaseRandomPointOnGenome( this._genomeBuilder.CreateRandomGenome(age: 1), this._parameterTree, this._minimumDomainSize, genomeBuilder: null)); }
public void BaseRandomPointOnGenomeThrowsForMissingGenome() { Assert.Throws <ArgumentNullException>( () => GenomeSearchPoint.BaseRandomPointOnGenome( genome: null, parameterTree: this._parameterTree, minimumDomainSize: this._minimumDomainSize, genomeBuilder: this._genomeBuilder)); }
public void IsValidReturnsTrueForValidPoint() { var point = new GenomeSearchPoint( Vector <double> .Build.DenseOfArray(new[] { 1.2, 3.5, 0.3, 0.8 }), this._parent, this._genomeBuilder); Assert.True(point.IsValid(), $"{point} should be valid."); }
public void CreateFromGenomeThrowsForMissingParameterTree() { Assert.Throws <ArgumentNullException>( () => GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 1), parameterTree: null, minimumDomainSize: this._minimumDomainSize, genomeBuilder: this._genomeBuilder)); }
public void IsValidChecksBoundaries() { var point = new GenomeSearchPoint( Vector <double> .Build.DenseOfArray(new[] { 1.2, 3.5, -24.3, 0.8 }), this._parent, this._genomeBuilder); Assert.False(point.IsValid(), $"{point} should not be valid."); }
public void ToStringPrintsGenome() { var genome = this._genomeBuilder.CreateRandomGenome(age: 0); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.Equal(genome.ToString(), point.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="GenomeSearchPointTest"/> class. /// </summary> public GenomeSearchPointTest() { Randomizer.Configure(); this._parameterTree = this.CreateParameterTree(); this._genomeBuilder = new GenomeBuilder( this._parameterTree, new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().Build(1)); this._parent = GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 1), this._parameterTree, this._minimumDomainSize, this._genomeBuilder); }
public void GenomePropertyReversesCreateFromGenome() { var originalGenome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( originalGenome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); var createdGenome = point.Genome.CreateMutableGenome(); Assert.True( new Genome.GeneValueComparator().Equals(originalGenome, createdGenome), $"{createdGenome} should have the same values as the genome it is based on, {originalGenome}."); }
public void GenomeSearchPointMakesUseOfParent() { var point = new GenomeSearchPoint(Vector <double> .Build.Dense(4), this._parent, this._genomeBuilder); var genome = point.Genome.CreateMutableGenome(); var parentGenome = this._parent.Genome.CreateMutableGenome(); var fixedParameters = new[] { "b", "d", "aa" }; foreach (var identifier in fixedParameters) { Assert.Equal( parentGenome.GetGeneValue(identifier).GetValue(), genome.GetGeneValue(identifier).GetValue()); } }
/// <summary> /// Creates <see cref="GenomeSearchPoint"/>s according to <see cref="GenomeBuilder"/>. /// </summary> /// <returns>The created <see cref="GenomeSearchPoint"/>s.</returns> private List <GenomeSearchPoint> CreateRandomSearchPoints() { var searchPoints = new List <GenomeSearchPoint>(); for (int i = 0; i < 8; i++) { searchPoints.Add( GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 0), this._parameterTree, 0, this._genomeBuilder)); } return(searchPoints); }
public void GenomePropertyProducesIndependentGenome() { var genome = this._genomeBuilder.CreateRandomGenome(age: 0); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); genome.SetGene("a", new Allele <int>(234)); var createdGenome = point.Genome.CreateMutableGenome(); Assert.NotEqual( 234, createdGenome.GetGeneValue("a").GetValue()); }
public void BaseRandomPointOnGenomeRandomlyChoosesContinuousValues() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); // Sample many points. int numberPoints = 1000; var valuesForLargeIntegerDomain = new Dictionary <int, int>(); for (int i = 0; i < numberPoints; i++) { var point = GenomeSearchPoint.BaseRandomPointOnGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); // Remember one of their values. var value = (int)point.Genome.CreateMutableGenome().GetGeneValue("a").GetValue(); if (valuesForLargeIntegerDomain.ContainsKey(value)) { valuesForLargeIntegerDomain[value]++; } else { valuesForLargeIntegerDomain.Add(value, 1); } } // Apply the Chi-Squared test on that gene. var numberPossibleGeneValues = (int)this._parameterTree.GetNumericalParameters() .Single(parameter => parameter.Identifier.Equals("a")) .Domain .DomainSize; double[] observed = valuesForLargeIntegerDomain.Select(keyValuePair => (double)keyValuePair.Value).ToArray(); double[] expected = Enumerable.Range(0, numberPossibleGeneValues) .Select(i => (double)numberPoints / numberPossibleGeneValues) .ToArray(); ChiSquareTest uniformTest = new ChiSquareTest(expected, observed, degreesOfFreedom: numberPossibleGeneValues - 1); Assert.False( uniformTest.Significant, $"BaseRandomPointOnGenome was found to not create uniform distributions by the Chi-Squared test test with significance level of {uniformTest.Size}."); }
/// <summary> /// Called before every test case. /// </summary> protected override void InitializeDefault() { var parameterTree = this.GetDefaultParameterTree(); var genomeBuilder = new GenomeBuilder(parameterTree, this.GetDefaultAlgorithmTunerConfiguration()); this._originalIncumbent = genomeBuilder.CreateRandomGenome(age: 2); for (int i = 0; i < 5; i++) { var searchPoint = GenomeSearchPoint.CreateFromGenome( genomeBuilder.CreateRandomGenome(age: 0), parameterTree, minimumDomainSize: 5, genomeBuilder: genomeBuilder); this._mostRecentSorting.Add(searchPoint); this._currentEvaluationInstances.Add(new TestInstance(i.ToString())); } }
public void BaseRandomPointOnGenomeFixesNonContinuousValues() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.BaseRandomPointOnGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); var nonContinuousIdentifiers = new[] { "b", "d", "aa" }; foreach (var identifier in nonContinuousIdentifiers) { Assert.Equal( genome.GetGeneValue(identifier).GetValue(), point.Genome.CreateMutableGenome().GetGeneValue(identifier).GetValue()); } }
public void BaseRandomPointOnGenomeCopiesCorrectInformation() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); genome.IsEngineered = true; var point = GenomeSearchPoint.BaseRandomPointOnGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.False( point.Genome.CreateMutableGenome().IsEngineered, "IsEngineered property should not be copied over."); // Age is only relevant for GGA. As points are not generated in GGA, the age should be fixed. Assert.Equal( genome.Age, point.Genome.CreateMutableGenome().Age); }
public void GenomeSearchPointRoundsIntegerValues() { var point = new GenomeSearchPoint( Vector <double> .Build.DenseOfArray(new[] { 0.51, -3.2, -24.3, 12.8 }), this._parent, this._genomeBuilder); var genome = point.Genome.CreateMutableGenome(); Assert.Equal( 1, genome.GetGeneValue("a").GetValue()); Assert.Equal( -3, genome.GetGeneValue("c").GetValue()); Assert.Equal( -24.3, genome.GetGeneValue("e").GetValue()); Assert.Equal( 12.8, genome.GetGeneValue("f").GetValue()); }
public void IsValidChecksCustomGenomeBuilder() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.True(point.IsValid(), $"{point} should be valid."); var pointAsForbidden = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, new ConfigurableGenomeBuilder(this._parameterTree, isValidFunction: g => false, mutationRate: 0)); Assert.False( pointAsForbidden.IsValid(), $"{pointAsForbidden} should not be valid for other genome builder."); }
public void CreateFromGenomeExtractsCorrectValues() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); var continuousIdentifiers = new[] { "a", "c", "e", "f" }; Assert.True( continuousIdentifiers.Length == point.Values.Count, $"There should be four continuous parameters: {TestUtils.PrintList(continuousIdentifiers)}."); for (int i = 0; i < continuousIdentifiers.Length; i++) { var identifier = continuousIdentifiers[i]; Assert.Equal( Convert.ToDouble(genome.GetGeneValue(identifier).GetValue()), point.Values[i]); } }