MultiStartMultivariateOptimizer extends BaseMultiStartMultivariateOptimizer<PointValuePair> { @Override public PointValuePair[] getOptima() { Collections.sort(optima, getPairComparator()); return optima.toArray(new PointValuePair[0]); } MultiStartMultivariateOptimizer(final MultivariateOptimizer optimizer,
                                           final int starts,
                                           final RandomVectorGenerator generator); @Override PointValuePair[] getOptima();  }
@Test public void testCircleFitting() { CircleScalar circle = new CircleScalar(); circle.addPoint( 30.0, 68.0); circle.addPoint( 50.0, -6.0); circle.addPoint(110.0, -20.0); circle.addPoint( 35.0, 15.0); circle.addPoint( 45.0, 97.0); GradientMultivariateOptimizer underlying = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE, new SimpleValueChecker(1e-10, 1e-10)); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(753289573253l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(new double[] { 50, 50 }, new double[] { 10, 10 }, new GaussianRandomGenerator(g)); int nbStarts = 10; MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, nbStarts, generator); PointValuePair optimum = optimizer.optimize(new MaxEval(1000), circle.getObjectiveFunction(), circle.getObjectiveFunctionGradient(), GoalType.MINIMIZE, new InitialGuess(new double[] { 98.680, 47.345 })); Assert.assertEquals(1000, optimizer.getMaxEvaluations()); PointValuePair[] optima = optimizer.getOptima(); Assert.assertEquals(nbStarts, optima.length); for (PointValuePair o : optima) { Vector2D center = new Vector2D(o.getPointRef()[0], o.getPointRef()[1]); Assert.assertTrue(69.9592 < circle.getRadius(center)); Assert.assertTrue(69.9602 > circle.getRadius(center)); Assert.assertTrue(96.0745 < center.getX()); Assert.assertTrue(96.0762 > center.getX()); Assert.assertTrue(48.1344 < center.getY()); Assert.assertTrue(48.1354 > center.getY()); } Assert.assertTrue(optimizer.getEvaluations() > 850); Assert.assertTrue(optimizer.getEvaluations() < 900); Assert.assertEquals(3.1267527, optimum.getValue(), 1e-8); }
@Test public void testRosenbrock() { Rosenbrock rosenbrock = new Rosenbrock(); SimplexOptimizer underlying = new SimplexOptimizer(new SimpleValueChecker(-1, 1e-3)); NelderMeadSimplex simplex = new NelderMeadSimplex(new double[][] { { -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 } }); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g)); int nbStarts = 10; MultiStartMultivariateOptimizer optimizer = new MultiStartMultivariateOptimizer(underlying, nbStarts, generator); PointValuePair optimum = optimizer.optimize(new MaxEval(1100), new ObjectiveFunction(rosenbrock), GoalType.MINIMIZE, simplex, new InitialGuess(new double[] { -1.2, 1.0 })); Assert.assertEquals(nbStarts, optimizer.getOptima().length); Assert.assertEquals(rosenbrock.getCount(), optimizer.getEvaluations()); Assert.assertTrue(optimizer.getEvaluations() > 900); Assert.assertTrue(optimizer.getEvaluations() < 1200); Assert.assertTrue(optimum.getValue() < 5e-5); }