public void CFO_should_find_maximum_value_when_function_is_convex() { var searchSpace = new SearchSpace <LSE3DSearchSpace>(); var initValues = searchSpace.SampleFromFeatureSpace(searchSpace.Default); var cfo = new CostFrugalTuner(searchSpace, Parameter.FromObject(initValues), false); double bestMetric = 0; for (int i = 0; i != 100; ++i) { var trialSettings = new TrialSettings() { TrialId = 0, }; var param = cfo.Propose(trialSettings).AsType <LSE3DSearchSpace>(); var x = param.X; var y = param.Y; var z = param.Z; var metric = LSE3D(x, y, z); bestMetric = Math.Max(bestMetric, metric); Output.WriteLine($"{i} x: {x} y: {y} z: {z}"); if (x == 10 && y == 10 && z == 10) { break; } cfo.Update(new TrialResult() { DurationInMilliseconds = 1 * 1000, Metric = metric, TrialSettings = trialSettings, }); } bestMetric.Should().BeGreaterThan(LSE3D(10, 10, 10) - 2); }
public void CFO_e2e_test() { var searchSpace = new SearchSpace <LbfgsOption>(); var initValues = searchSpace.SampleFromFeatureSpace(searchSpace.Default); var cfo = new CostFrugalTuner(searchSpace, Parameter.FromObject(initValues)); for (int i = 0; i != 1000; ++i) { var trialSettings = new TrialSettings() { TrialId = i, }; var param = cfo.Propose(trialSettings); var option = param.AsType <CodeGen.LbfgsOption>(); option.L1Regularization.Should().BeInRange(0.03125f, 32768.0f); option.L2Regularization.Should().BeInRange(0.03125f, 32768.0f); cfo.Update(new TrialResult() { DurationInMilliseconds = i * 1000, Metric = i, TrialSettings = trialSettings, }); } }
public void Hyper_parameters_from_CFO_should_be_culture_invariant_string() { var searchSpace = new SearchSpace <LSE3DSearchSpace>(); var initValues = searchSpace.SampleFromFeatureSpace(searchSpace.Default); var cfo = new CostFrugalTuner(searchSpace, Parameter.FromObject(initValues), true); var originalCuture = Thread.CurrentThread.CurrentCulture; var usCulture = new CultureInfo("en-US", false); Thread.CurrentThread.CurrentCulture = usCulture; Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator.Should().Be("."); for (int i = 0; i != 100; ++i) { var trialSettings = new TrialSettings() { TrialId = i, }; var param = cfo.Propose(trialSettings).AsType <LSE3DSearchSpace>(); param.X.Should().BeInRange(-10, 10); } var frCulture = new CultureInfo("fr-FR", false); Thread.CurrentThread.CurrentCulture = frCulture; Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator.Should().Be(","); for (int i = 0; i != 100; ++i) { var trialSettings = new TrialSettings() { TrialId = i, }; var param = cfo.Propose(trialSettings).AsType <LSE3DSearchSpace>(); param.X.Should().BeInRange(-10, 10); } Thread.CurrentThread.CurrentCulture = originalCuture; }
public void CFO_should_start_from_init_point_if_provided() { var trialSettings = new TrialSettings() { TrialId = 0, }; var searchSpace = new SearchSpace <LSE3DSearchSpace>(); var initValues = searchSpace.SampleFromFeatureSpace(searchSpace.Default); var cfo = new CostFrugalTuner(searchSpace, Parameter.FromObject(initValues), true); var param = cfo.Propose(trialSettings).AsType <LSE3DSearchSpace>(); var x = param.X; var y = param.Y; var z = param.Z; (x * x + y * y + z * z).Should().Be(0); }
public void CFO_should_find_minimum_value_when_function_is_convex() { var searchSpace = new SearchSpace <LSE3DSearchSpace>(); var initValues = searchSpace.SampleFromFeatureSpace(searchSpace.Default); var cfo = new CostFrugalTuner(searchSpace, Parameter.FromObject(initValues), true); double loss = 0; for (int i = 0; i != 100; ++i) { var trialSettings = new TrialSettings() { TrialId = i, }; var param = cfo.Propose(trialSettings).AsType <LSE3DSearchSpace>(); var x = param.X; var y = param.Y; var z = param.Z; loss = LSE3D(x, y, z); Output.WriteLine(loss.ToString()); Output.WriteLine($"{i} x: {x} y: {y} z: {z}"); if (x == -10 && y == -10 && z == -10) { break; } cfo.Update(new TrialResult() { DurationInMilliseconds = 1000, Metric = loss, TrialSettings = trialSettings, }); } loss.Should().BeLessThan(LSE3D(-10, -10, -10) + 2); }