public void Uniform_log_double_option_round_up_test() { var option = new UniformDoubleOption(2e-10, 1, defaultValue: 2e-10, logBase: true); option.Default.Should().Equal(0); option.SampleFromFeatureSpace(option.Default).AsType <double>().Should().Be(2e-10); option.SampleFromFeatureSpace(new[] { 1.0 }).AsType <double>().Should().Be(1.0); }
public void Uniform_double_option_mapping_to_uniform_space_test() { var option = new UniformDoubleOption(0, 100); var sampleInputs = Enumerable.Range(0, 10).Select(i => Parameter.FromDouble(i * 10.0)); var sampleOutputs = sampleInputs.Select(i => option.MappingToFeatureSpace(i)[0]); sampleOutputs.Should().Equal(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9); }
public void Uniform_log_double_option_sampling_from_uniform_space_test() { var option = new UniformDoubleOption(1, 1024, true); var sampleInputs = Enumerable.Range(0, 10).Select(i => i * 0.1); var sampleOutputs = sampleInputs.Select(i => option.SampleFromFeatureSpace(new[] { i })); sampleOutputs.Select((x, i) => (x.AsType <double>(), Math.Pow(2, i))) .All((x) => Math.Abs(x.Item1 - x.Item2) < 1e-5) .Should().BeTrue(); }
public void Uniform_log_double_option_mapping_to_uniform_space_test() { var option = new UniformDoubleOption(1, 1024, true); var sampleInputs = Enumerable.Range(0, 10).Select(i => Parameter.FromDouble(Math.Pow(2, i))); var sampleOutputs = sampleInputs.Select(i => option.MappingToFeatureSpace(i)).ToArray(); foreach (var i in Enumerable.Range(0, 10)) { sampleOutputs[i][0].Should().BeApproximately(0.1 * i, 1e-5); } }
/// <summary> /// Create a <see cref="RangeAttribute"/> for <see cref="UniformDoubleOption"/>. /// </summary> public RangeAttribute(double min, double max, double init, bool logBase = false) { Option = new UniformDoubleOption(min, max, logBase, init); }