public void CreateFromGenomeExtractsCorrectValues() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = PartialGenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize); var continuousIdentifiers = new[] { "continuous", "log", "quasi-continuous", "quasi-continuous-log" }; Assert.True( continuousIdentifiers.Length == point.Values.Count, $"There should be four continuous parameters: {TestUtils.PrintList(continuousIdentifiers)}."); var values = BoundedSearchPoint.StandardizeValues( continuousIdentifiers.Select(id => Convert.ToDouble(genome.GetGeneValue(id).GetValue())).ToArray(), this._lowerBounds, this._upperBounds); for (int i = 0; i < continuousIdentifiers.Length; i++) { var identifier = continuousIdentifiers[i]; Console.Out.WriteLine($"Checking value of parameter {identifier}..."); Assert.Equal( values[i], point.Values[i]); } }
public void InvalidGenomeIsHandledCorrectly() { var positiveGenomeBuilder = new ConfigurableGenomeBuilder( this._parameterTree, g => (int)g.GetGeneValue("discrete").GetValue() != 0, mutationRate: 1); var genome = this._genomeBuilder.CreateRandomGenome(0); genome.SetGene("discrete", new Allele <int>(0)); var genomeValues = new[] { 1.4, 0.3, 0, 1.5 }; var standardizedValues = BoundedSearchPoint.StandardizeValues(genomeValues, this._lowerBounds, this._upperBounds); var searchPoint = new PartialGenomeSearchPoint( underlyingGenome: new ImmutableGenome(genome), values: standardizedValues, genomeSearchPointConverter: this._genomeSearchPointConverter, genomeBuilder: positiveGenomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); var associatedGenome = searchPoint.Genome.CreateMutableGenome(); Assert.True( 0 != (int)associatedGenome.GetGeneValue("discrete").GetValue(), "Genome should have been repaired."); Assert.True(searchPoint.IsRepaired, "Repair flag should have been set."); }
public void CreateFromGenomeThrowsForMissingParameterTree() { Assert.Throws <ArgumentNullException>( () => PartialGenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 1), parameterTree: null, minimumDomainSize: 5)); }
public void CreateFromGenomeThrowsForMissingGenome() { Assert.Throws <ArgumentNullException>( () => PartialGenomeSearchPoint.CreateFromGenome( genome: null, parameterTree: this._parameterTree, minimumDomainSize: 5)); }
public void ObtainParameterBoundsFindsCorrectBounds() { PartialGenomeSearchPoint.ObtainParameterBounds( this._parameterTree, this._minimumDomainSize, out var obtainedLowerBounds, out var obtainedUpperBounds); Assert.Equal(this._lowerBounds, obtainedLowerBounds); Assert.Equal(this._upperBounds, obtainedUpperBounds); }
public void GenomePropertyProducesIndependentGenome() { var genome = this._genomeBuilder.CreateRandomGenome(age: 0); var point = PartialGenomeSearchPoint.CreateFromGenome(genome, this._parameterTree, this._minimumDomainSize); genome.SetGene("discrete", new Allele <double>(-6)); var createdGenome = point.Genome.CreateMutableGenome(); Assert.True( -6 != (int)createdGenome.GetGeneValue("discrete").GetValue(), "Created genome should be a different object than the one the point was initialized with."); }
public void ConstructorCorrectlySetsValues() { var providedValues = Vector <double> .Build.Random(4); var searchPoint = new PartialGenomeSearchPoint( underlyingGenome: this._baseGenome, values: providedValues, genomeSearchPointConverter: this._genomeSearchPointConverter, genomeBuilder: this._genomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); Assert.Equal(providedValues, searchPoint.Values); }
public void ConstructionIsConsistent() { // We do not care about age --> set it to default age. var genome = this._genomeBuilder.CreateRandomGenome(age: 0); genome.SetGene("quasi-continuous-log", new Allele <int>(3)); var searchPoint = PartialGenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize); var samePoint = new PartialGenomeSearchPoint( underlyingGenome: new ImmutableGenome(genome), values: searchPoint.Values, genomeSearchPointConverter: this._genomeSearchPointConverter, genomeBuilder: this._genomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); var genomeString = genome.ToCappedDecimalString(); var samePointString = samePoint.Genome.ToCappedDecimalString(); genomeString.ShouldBe(samePointString, "Genome should stay the same if transformed into values and back."); var values = BoundedSearchPoint.StandardizeValues(new[] { 0, 0.2, 3, 2 }, this._lowerBounds, this._upperBounds); searchPoint = new PartialGenomeSearchPoint( underlyingGenome: new ImmutableGenome(genome), values: values, genomeSearchPointConverter: this._genomeSearchPointConverter, genomeBuilder: this._genomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); samePoint = PartialGenomeSearchPoint.CreateFromGenome( searchPoint.Genome.CreateMutableGenome(), this._parameterTree, this._minimumDomainSize); for (int i = 0; i < values.Count; i++) { Assert.Equal( values[i], samePoint.Values[i], 4); } }
public void ConstructorAssociatesCorrectGenome() { var genomeValues = new[] { 1.4, 0.8, 2.7, 1.2 }; var offset = 20 * 5; var searchPoint = new PartialGenomeSearchPoint( underlyingGenome: this._baseGenome, values: BoundedSearchPoint.StandardizeValues(genomeValues, this._lowerBounds, this._upperBounds) + offset, genomeSearchPointConverter: this._genomeSearchPointConverter, genomeBuilder: this._genomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); var genome = searchPoint.Genome.CreateMutableGenome(); Assert.Equal( this._baseGenome.CreateMutableGenome().GetGeneValue("categorical").GetValue(), genome.GetGeneValue("categorical").GetValue()); Assert.Equal( 1.4, genome.GetGeneValue("continuous").GetValue()); Assert.Equal( this._baseGenome.CreateMutableGenome().GetGeneValue("discrete").GetValue(), genome.GetGeneValue("discrete").GetValue()); Assert.Equal( this._baseGenome.CreateMutableGenome().GetGeneValue("discrete-log").GetValue(), genome.GetGeneValue("discrete-log").GetValue()); Assert.Equal( 0.8, (double)genome.GetGeneValue("log").GetValue(), 4); Assert.False(searchPoint.IsRepaired, "The genome should not have needed repair."); Assert.True( 3 == (int)genome.GetGeneValue("quasi-continuous").GetValue(), "Quasi continuous value should be rounded to nearest integer."); Assert.True( 1 == (int)genome.GetGeneValue("quasi-continuous-log").GetValue(), "Quasi continuous value should be rounded to nearest integer."); }