public void StandardizeValuesThrowsForLowerBoundHigherUpperBound() { this._lowerBounds[1] = this._upperBounds[1] + 0.1; Assert.Throws <ArgumentOutOfRangeException>( () => BoundedSearchPoint.StandardizeValues( this._values.ToArray(), this._lowerBounds, this._upperBounds)); }
public void StandardizeValuesThrowsForWrongNumberOfLowerBounds() { var notEnoughLowerBounds = new[] { 0.1, 0, -12.4 }; Assert.Throws <ArgumentOutOfRangeException>( () => BoundedSearchPoint.StandardizeValues( this._values.ToArray(), notEnoughLowerBounds, this._upperBounds)); }
public void StandardizeValuesThrowsForWrongNumberOfUpperBounds() { var tooManyUpperBounds = new[] { 104.56, 0.02, 0, 7, 46 }; Assert.Throws <ArgumentOutOfRangeException>( () => BoundedSearchPoint.StandardizeValues( this._values.ToArray(), this._lowerBounds, tooManyUpperBounds)); }
public void MapIntoValuesUndoesStandardizeValues() { var boundedValues = new[] { 23.67, 0.01, -12.4, 7 }; var standardized = BoundedSearchPoint.StandardizeValues(boundedValues, this._lowerBounds, this._upperBounds); var backIntoBounds = new BoundedSearchPoint(standardized, this._lowerBounds, this._upperBounds).MapIntoBounds(); for (int i = 0; i < boundedValues.Length; i++) { Assert.Equal(boundedValues[i], backIntoBounds[i], 4); } }
public void MapIntoBoundsWorksCorrectly() { var testValues = Vector <double> .Build.DenseOfArray(new[] { 105.56, -23, -6.2, 28 }); var mapped = new BoundedSearchPoint(testValues, this._lowerBounds, this._upperBounds).MapIntoBounds(); var tolerance = 1e-4; TestUtils.Equals(mapped[0], 61.4714, tolerance); TestUtils.Equals(mapped[1], 0.0041, tolerance); TestUtils.Equals(mapped[2], -3.9176, tolerance); TestUtils.Equals(mapped[3], 7, tolerance); }
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 CreateFromGenomeSetsPropertiesCorrectly() { var genome = new Genome(age: 2); genome.SetGene("categorical", new Allele <double>(123.6)); genome.SetGene("continuous", new Allele <double>(0.2)); genome.SetGene("discrete", new Allele <int>(-3)); genome.SetGene("single_categorical", new Allele <string>("foo")); var searchPoint = ContinuizedGenomeSearchPoint.CreateFromGenome(genome, this._parameterTree); Assert.Equal( genome.ToString(), searchPoint.Genome.ToString()); // Values be transformed into [0, 10]. Assert.Equal( BoundedSearchPoint.StandardizeValues(new[] { 0, 0.2, -3, 0 }, this._lowerBounds, this._upperBounds), searchPoint.Values); Assert.False( searchPoint.IsRepaired, "Search points directly created from genomes do not have to be repaired."); }
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."); }
public void InvalidGenomeIsHandledCorrectly() { var positiveGenomeBuilder = new ConfigurableGenomeBuilder( this._parameterTree, g => (int)g.GetGeneValue("discrete").GetValue() != -4, mutationRate: 1); var genomeValues = new[] { 0, 1.4, -4, 0 }; var standardizedValues = BoundedSearchPoint.StandardizeValues(genomeValues, this._lowerBounds, this._upperBounds); var searchPoint = new ContinuizedGenomeSearchPoint( values: standardizedValues, parameterTree: this._parameterTree, genomeBuilder: positiveGenomeBuilder, lowerBounds: this._lowerBounds, upperBounds: this._upperBounds); var genome = searchPoint.Genome.CreateMutableGenome(); Assert.True( -4 != (int)genome.GetGeneValue("discrete").GetValue(), "Genome should have been repaired."); Assert.Equal(standardizedValues, searchPoint.Values); Assert.True(searchPoint.IsRepaired, "Repair flag should have been set."); }