public void RandomSearchOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(10.0, 37.5, Transform.Linear) }; var sut = maxDegreeOfParallelism.HasValue ? new RandomSearchOptimizer(parameters, 2, 42, true, maxDegreeOfParallelism.Value) : new RandomSearchOptimizer(parameters, 2); var actual = sut.Optimize(MinimizeWeightFromHeight); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 13.8749507052707 }, 23438.2157641635), new OptimizerResult(new double[] { 28.3729278125674 }, 3690.81119818742), }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void GridSearchOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new GridParameterSpec[] { new GridParameterSpec(10.0, 37.5) }; var sut = maxDegreeOfParallelism.HasValue ? new GridSearchOptimizer(parameters, true, maxDegreeOfParallelism.Value) : new GridSearchOptimizer(parameters); var actual = sut.Optimize(Minimize); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.5 }, 111.20889999999987), new OptimizerResult(new double[] { 10 }, 31638.9579) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void GlobalizedBoundedNelderMeadOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = maxDegreeOfParallelism.HasValue ? new GlobalizedBoundedNelderMeadOptimizer(parameters, 5, 1e-5, 10, maxDegreeOfParallelism: maxDegreeOfParallelism.Value) : new GlobalizedBoundedNelderMeadOptimizer(parameters, 5, 1e-5, 10); var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.71314535727786 }, 109.34381396310141), new OptimizerResult(new double[] { 37.7131485180996 }, 109.34381396350526) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void SmacOptimizer_Optimize() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = new SmacOptimizer(parameters, iterations: 80, randomStartingPointCount: 20, functionEvaluationsPerIterationCount: 1, localSearchPointCount: 10, randomSearchPointCount: 1000, epsilon: 0.00001, seed: 42); var actual = sut.Optimize(MinimizeWeightFromHeight); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 90.513222660177 }, 114559.431919558), new OptimizerResult(new double[] { 41.8333740634068 }, 806.274612132759), }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void BayesianOptimizer_Optimize() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = new BayesianOptimizer(parameters, iterations: 120, randomStartingPointCount: 5, functionEvaluationsPerIterationCount: 1, randomSearchPointCount: 1000, seed: 42, runParallel: false); // Note, since the returned results are not ordered on error, // running with parallel computations will not return reproducible order of results, // so runParallel must be false for this test. var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 43.216748276360683 }, 1352.8306605984087), new OptimizerResult(new double[] { 38.201425707992833 }, 119.1316225267316) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void ParticleSwarmOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = maxDegreeOfParallelism.HasValue ? new ParticleSwarmOptimizer(parameters, 100, maxDegreeOfParallelism: maxDegreeOfParallelism.Value) : new ParticleSwarmOptimizer(parameters, 100); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 38.1151505704492 }, 115.978346548015), new OptimizerResult(new double[] { 37.2514904205637 }, 118.093289672808), }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void RandomSearchOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(10.0, 37.5, Transform.Linear) }; var sut = maxDegreeOfParallelism.HasValue ? new RandomSearchOptimizer(parameters, 100, 42, true, maxDegreeOfParallelism.Value) : new RandomSearchOptimizer(parameters, 100); var actual = sut.Optimize(MinimizeWeightFromHeight); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 28.3729278125674 }, 3690.81119818742), new OptimizerResult(new double[] { 19.1529422843144 }, 14251.396910816733), }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void ParticleSwarmOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = CreateSut(maxDegreeOfParallelism, parameters); var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 38.1151505704492 }, 115.978346548015), new OptimizerResult(new double[] { 37.2514904205637 }, 118.093289672808), }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void GridSearchOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new GridParameterSpec[] { new GridParameterSpec(10.0, 20.0, 30.0, 35.0, 37.5, 40.0, 50.0, 60.0) }; var sut = maxDegreeOfParallelism.HasValue ? new GridSearchOptimizer(parameters, true, maxDegreeOfParallelism.Value) : new GridSearchOptimizer(parameters); var actual = sut.Optimize(MinimizeWeightFromHeight); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 10 }, 31638.9579), new OptimizerResult(new double[] { 60 }, 20500.6279) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void GlobalizedBoundedNelderMeadOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = CreateSut(maxDegreeOfParallelism, parameters); var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.71314634450421 }, 109.3438139631394), new OptimizerResult(new double[] { 37.713142445047254 }, 109.34381396345546) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void BayesianOptimizer_OptimizeNonDeterministicInParallel() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0, 1, Transform.Linear, ParameterType.Discrete) }; var sut = new BayesianOptimizer(parameters, iterations: 240, randomStartingPointCount: 5, functionEvaluationsPerIteration: 5, seed: Seed, maxDegreeOfParallelism: -1, allowMultipleEvaluations: true); var results = sut.Optimize(p => MinimizeNonDeterministic(p, Random)); var actual = new OptimizerResult[] { results.First(), results.Last() }.OrderByDescending(o => o.Error); Assert.AreEqual(1, actual.First().Error); Assert.AreEqual(1, (int)actual.First().ParameterSet[0]); }
public void GridSearchOptimizer_Optimize() { var parameters = new double[][] { new double[] { 10.0, 37.5 } }; var sut = new GridSearchOptimizer(parameters); var actual = sut.Optimize(Minimize); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.5 }, 111.20889999999987), new OptimizerResult(new double[] { 10 }, 31638.9579) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void RandomSearchOptimizer_Optimize() { var parameters = new double[][] { new double[] { 10.0, 37.5 } }; var sut = new RandomSearchOptimizer(parameters, 2); var actual = sut.Optimize(Minimize); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 28.372927812567415 }, 3690.8111981874217), new OptimizerResult(new double[] { 13.874950705270725 }, 23438.215764163542) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void SequentialModelBasedOptimizer_Optimize() { var parameters = new double[][] { new double[] { 0.0, 100.0 } }; var sut = new SequentialModelBasedOptimizer(parameters, 20, 5); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.712345696964071 }, 109.34384021647092), new OptimizerResult(new double[] { 66.810646591154239 }, 34867.634010511123) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void ParticleSwarmOptimizer_Optimize() { var parameters = new double[][] { new double[] { 0.0, 100.0 } }; var sut = new ParticleSwarmOptimizer(parameters, 100); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.635959742891046 }, 109.58839344747747), new OptimizerResult(new double[] { 38.891904333594624 }, 166.38611320480345) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void GlobalizedBoundedNelderMeadOptimizer_Optimize() { var parameters = new double[][] { new double[] { 0.0, 100.0 } }; var sut = new GlobalizedBoundedNelderMeadOptimizer(parameters, 5, 1e-5, 10); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.71314535727786 }, 109.34381396310141), new OptimizerResult(new double[] { 37.7131485180996 }, 109.34381396350526) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void BayesianOptimizer_Optimize() { var parameters = new double[][] { new double[] { 0.0, 100.0 } }; var sut = new BayesianOptimizer(parameters, 120, 5, 1); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.710969353891429 }, 109.34400835405613), new OptimizerResult(new double[] { 99.646240426062718 }, 157577.44222424511) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void BayesianOptimizer_Optimize() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = new BayesianOptimizer(parameters, 120, 5, 1); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 90.513222660177 }, 114559.431919558), new OptimizerResult(new double[] { 24.204380402436 }, 7601.008090362) }; Assert.AreEqual(expected.First().Error, actual.First().Error, m_delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), m_delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, m_delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), m_delta); }
public void ParticleSwarmOptimizer_Optimize() { var parameters = new ParameterBounds[] { new ParameterBounds(0.0, 100.0, Transform.Linear) }; var sut = new ParticleSwarmOptimizer(parameters, 100); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.660092259635064 }, 109.45936368750877), new OptimizerResult(new double[] { 39.038272502859328 }, 181.43166846962754) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void ParticleSwarmOptimizer_Optimize() { var parameters = new ParameterBounds[] { new ParameterBounds(0.0, 100.0, Transform.Linear) }; var sut = new ParticleSwarmOptimizer(parameters, 100); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 37.804275358363732 }, 109.68474734728727), new OptimizerResult(new double[] { 35.942821697748165 }, 238.00642904844648) }; Assert.AreEqual(expected.First().Error, actual.First().Error, 0.0001); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), 0.0001); Assert.AreEqual(expected.Last().Error, actual.Last().Error, 0.0001); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), 0.0001); }
public void BayesianOptimizer_Optimize() { var parameters = new ParameterBounds[] { new ParameterBounds(0.0, 100.0, Transform.Linear) }; var sut = new BayesianOptimizer(parameters, 120, 5, 1); var results = sut.Optimize(Minimize2); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 42.323589763754789 }, 981.97873691815118), new OptimizerResult(new double[] { 99.110398813667885 }, 154864.41962974239) }; Assert.AreEqual(expected.First().Error, actual.First().Error, m_delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), m_delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, m_delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), m_delta); }
public void SmacOptimizer_Optimize() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = CreateSut(parameters); var actual = sut.Optimize(MinimizeWeightFromHeight); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 90.513222660177 }, 114559.431919558), new OptimizerResult(new double[] { 41.8333740634068 }, 806.274612132759), }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void BayesianOptimizer_Optimize() { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = new BayesianOptimizer(parameters, 120, 5, 1, maxDegreeOfParallelism: 1); var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }.OrderByDescending(o => o.Error); var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 90.513222660177 }, 114559.431919558), new OptimizerResult(new double[] { 24.2043804024367 }, 7601.00809036235) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }
public void BayesianOptimizer_Optimize(int?maxDegreeOfParallelism) { var parameters = new MinMaxParameterSpec[] { new MinMaxParameterSpec(0.0, 100.0, Transform.Linear) }; var sut = CreateSut(maxDegreeOfParallelism, parameters); var results = sut.Optimize(MinimizeWeightFromHeight); var actual = new OptimizerResult[] { results.First(), results.Last() }; var expected = new OptimizerResult[] { new OptimizerResult(new double[] { 90.513222660177036 }, 114559.43191955783), new OptimizerResult(new double[] { 41.752538896050559 }, 779.196560786838) }; Assert.AreEqual(expected.First().Error, actual.First().Error, Delta); Assert.AreEqual(expected.First().ParameterSet.First(), actual.First().ParameterSet.First(), Delta); Assert.AreEqual(expected.Last().Error, actual.Last().Error, Delta); Assert.AreEqual(expected.Last().ParameterSet.First(), actual.Last().ParameterSet.First(), Delta); }