MultiStartMultivariateVectorOptimizer extends BaseMultiStartMultivariateOptimizer<PointVectorValuePair> { @Override public PointVectorValuePair[] getOptima() { Collections.sort(optima, getPairComparator()); return optima.toArray(new PointVectorValuePair[0]); } MultiStartMultivariateVectorOptimizer(final MultivariateVectorOptimizer optimizer,
                                                 final int starts,
                                                 final RandomVectorGenerator generator); @Override PointVectorValuePair[] getOptima();  }
@Test(expected=NullPointerException.class) public void testGetOptimaBeforeOptimize() { JacobianMultivariateVectorOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartMultivariateVectorOptimizer optimizer = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator); optimizer.getOptima(); }
@Test public void testTrivial() { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); JacobianMultivariateVectorOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)); JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartMultivariateVectorOptimizer optimizer = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator); PointVectorValuePair optimum = optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0 })); Assert.assertEquals(1.5, optimum.getPoint()[0], 1e-10); Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10); PointVectorValuePair[] optima = optimizer.getOptima(); Assert.assertEquals(10, optima.length); for (int i = 0; i < optima.length; i++) { Assert.assertEquals(1.5, optima[i].getPoint()[0], 1e-10); Assert.assertEquals(3.0, optima[i].getValue()[0], 1e-10); } Assert.assertTrue(optimizer.getEvaluations() > 20); Assert.assertTrue(optimizer.getEvaluations() < 50); Assert.assertEquals(100, optimizer.getMaxEvaluations()); }
@Test public void testIssue914() { LinearProblem problem = new LinearProblem(new double[][] { { 2 } }, new double[] { 3 }); JacobianMultivariateVectorOptimizer underlyingOptimizer = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6)) { @Override public PointVectorValuePair optimize(OptimizationData... optData) { OptimizationData[] filtered = optData.clone(); for (int i = 0; i < filtered.length; ++i) { if (filtered[i] instanceof SimpleBounds) { filtered[i] = null; } } return super.optimize(filtered); } }; JDKRandomGenerator g = new JDKRandomGenerator(); g.setSeed(16069223052l); RandomVectorGenerator generator = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g)); MultiStartMultivariateVectorOptimizer optimizer = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator); optimizer.optimize(new MaxEval(100), problem.getModelFunction(), problem.getModelFunctionJacobian(), problem.getTarget(), new Weight(new double[] { 1 }), new InitialGuess(new double[] { 0 }), new SimpleBounds(new double[] { -1.0e-10 }, new double[] { 1.0e-10 })); PointVectorValuePair[] optima = optimizer.getOptima(); Assert.assertEquals(1, optima.length); }