CMAESOptimizer extends MultivariateOptimizer { @Override public PointValuePair optimize(OptimizationData... optData) throws TooManyEvaluationsException, DimensionMismatchException { return super.optimize(optData); } CMAESOptimizer(int maxIterations,
                          double stopFitness,
                          boolean isActiveCMA,
                          int diagonalOnly,
                          int checkFeasableCount,
                          RandomGenerator random,
                          boolean generateStatistics,
                          ConvergenceChecker<PointValuePair> checker); List<Double> getStatisticsSigmaHistory(); List<RealMatrix> getStatisticsMeanHistory(); List<Double> getStatisticsFitnessHistory(); List<RealMatrix> getStatisticsDHistory(); @Override PointValuePair optimize(OptimizationData... optData);  }
@Test public void testMath864() { final CMAESOptimizer optimizer = new CMAESOptimizer(30000, 0, true, 10, 0, new MersenneTwister(), false, null); final MultivariateFunction fitnessFunction = new MultivariateFunction() { public double value(double[] parameters) { final double target = 1; final double error = target - parameters[0]; return error * error; } }; final double[] start = { 0 }; final double[] lower = { -1e6 }; final double[] upper = { 1.5 }; final double[] sigma = { 1e-1 }; final double[] result = optimizer.optimize(new MaxEval(10000), new ObjectiveFunction(fitnessFunction), GoalType.MINIMIZE, new CMAESOptimizer.PopulationSize(5), new CMAESOptimizer.Sigma(sigma), new InitialGuess(start), new SimpleBounds(lower, upper)).getPoint(); Assert.assertTrue("Out of bounds (" + result[0] + " > " + upper[0] + ")", result[0] <= upper[0]); }
@Test public void testFitAccuracyDependsOnBoundary() { final CMAESOptimizer optimizer = new CMAESOptimizer(30000, 0, true, 10, 0, new MersenneTwister(), false, null); final MultivariateFunction fitnessFunction = new MultivariateFunction() { public double value(double[] parameters) { final double target = 11.1; final double error = target - parameters[0]; return error * error; } }; final double[] start = { 1 }; PointValuePair result = optimizer.optimize(new MaxEval(100000), new ObjectiveFunction(fitnessFunction), GoalType.MINIMIZE, SimpleBounds.unbounded(1), new CMAESOptimizer.PopulationSize(5), new CMAESOptimizer.Sigma(new double[] { 1e-1 }), new InitialGuess(start)); final double resNoBound = result.getPoint()[0]; final double[] lower = { -20 }; final double[] upper = { 5e16 }; final double[] sigma = { 10 }; result = optimizer.optimize(new MaxEval(100000), new ObjectiveFunction(fitnessFunction), GoalType.MINIMIZE, new CMAESOptimizer.PopulationSize(5), new CMAESOptimizer.Sigma(sigma), new InitialGuess(start), new SimpleBounds(lower, upper)); final double resNearLo = result.getPoint()[0]; lower[0] = -5e16; upper[0] = 20; result = optimizer.optimize(new MaxEval(100000), new ObjectiveFunction(fitnessFunction), GoalType.MINIMIZE, new CMAESOptimizer.PopulationSize(5), new CMAESOptimizer.Sigma(sigma), new InitialGuess(start), new SimpleBounds(lower, upper)); final double resNearHi = result.getPoint()[0]; Assert.assertEquals(resNoBound, resNearLo, 1e-3); Assert.assertEquals(resNoBound, resNearHi, 1e-3); }