public void TestLongValueSweep(string name, int min, int max, bool logBase, int stepSize, int numSteps, string valueText) { var paramSweep = new LongValueGenerator(new LongParamArguments() { Name = name, Min = min, Max = max, LogBase = logBase, StepSize = stepSize, NumSteps = numSteps }); IParameterValue value = paramSweep.CreateFromNormalized(0.5); Assert.Equal(name, value.Name); Assert.Equal(valueText, value.ValueText); }
public void TestLong() { var l = LongValueGenerator.NextValue(); var str = LongInterface.Singleton.LongToString(l); Assert.IsTrue(LongInterface.Singleton.TryParse(str, out var nl)); Assert.AreEqual(l, nl); l = 1274725414896843596; str = LongInterface.Singleton.LongToString(l); Assert.IsTrue(LongInterface.Singleton.TryParse(str, out nl)); Assert.AreEqual(l, nl); }
public void LongValueGenerator_should_generate_value_from_normalize(long min, long max, int step, bool logbase, long expect) { var option = new LongValueGenerator.Option() { Min = min, Max = max, Name = "long", Steps = step, LogBase = logbase, }; var generator = new LongValueGenerator(option); generator.CreateFromNormalized(1.0).RawValue.Should().Be(max); generator.CreateFromNormalized(0).RawValue.Should().Be(min); generator.CreateFromNormalized(0.5).RawValue.Should().Be(expect); }
public void TestLongValueGeneratorRoundTrip() { var paramSweep = new LongValueGenerator(new LongParamArguments() { Name = "bla", Min = 0, Max = 17 }); var value = new LongParameterValue("bla", 5); float normalizedValue = paramSweep.NormalizeValue(value); IParameterValue unNormalizedValue = paramSweep.CreateFromNormalized(normalizedValue); Assert.Equal("5", unNormalizedValue.ValueText); IParameterValue param = paramSweep.CreateFromNormalized(0.345); float unNormalizedParam = paramSweep.NormalizeValue(param); Assert.Equal("5", param.ValueText); Assert.Equal((float)5 / 17, unNormalizedParam); }
public void LongValueGenerator_should_work_with_index(long min, long max, int step, bool logBase, int count) { var option = new LongValueGenerator.Option() { Min = min, Max = max, Steps = step, Name = "long", LogBase = logBase, }; var generator = new LongValueGenerator(option); generator.Count.Should().Be(count + 1); generator[0].RawValue.Should().Be(min); ((long)generator[count].RawValue) .Should() .Be(max); }
public void SmacQuickRunTest() { var numInitialPopulation = 10; var floatValueGenerator = new FloatValueGenerator(new FloatParamArguments() { Name = "float", Min = 1, Max = 1000 }); var floatLogValueGenerator = new FloatValueGenerator(new FloatParamArguments() { Name = "floatLog", Min = 1, Max = 1000, LogBase = true }); var longValueGenerator = new LongValueGenerator(new LongParamArguments() { Name = "long", Min = 1, Max = 1000 }); var longLogValueGenerator = new LongValueGenerator(new LongParamArguments() { Name = "longLog", Min = 1, Max = 1000, LogBase = true }); var discreteValueGeneator = new DiscreteValueGenerator(new DiscreteParamArguments() { Name = "discrete", Values = new[] { "200", "400", "600", "800" } }); var sweeper = new SmacSweeper(new MLContext(), new SmacSweeper.Arguments() { SweptParameters = new IValueGenerator[] { floatValueGenerator, floatLogValueGenerator, longValueGenerator, longLogValueGenerator, discreteValueGeneator }, NumberInitialPopulation = numInitialPopulation }); // sanity check grid Assert.NotNull(floatValueGenerator[0].ValueText); Assert.NotNull(floatLogValueGenerator[0].ValueText); Assert.NotNull(longValueGenerator[0].ValueText); Assert.NotNull(longLogValueGenerator[0].ValueText); Assert.NotNull(discreteValueGeneator[0].ValueText); List <RunResult> results = new List <RunResult>(); RunResult bestResult = null; for (var i = 0; i < numInitialPopulation + 1; i++) { ParameterSet[] pars = sweeper.ProposeSweeps(1, results); foreach (ParameterSet p in pars) { float x1 = float.Parse(p["float"].ValueText); float x2 = float.Parse(p["floatLog"].ValueText); long x3 = long.Parse(p["long"].ValueText); long x4 = long.Parse(p["longLog"].ValueText); int x5 = int.Parse(p["discrete"].ValueText); double metric = x1 + x2 + x3 + x4 + x5; RunResult result = new RunResult(p, metric, true); if (bestResult == null || bestResult.MetricValue < metric) { bestResult = result; } results.Add(result); Console.WriteLine($"{metric}\t{x1},{x2}"); } } Console.WriteLine($"Best: {bestResult.MetricValue}"); Assert.NotNull(bestResult); Assert.True(bestResult.MetricValue > 0); }