Class CMAESOptimizer
- java.lang.Object
-
- org.apache.commons.math4.legacy.optim.BaseOptimizer<PAIR>
-
- org.apache.commons.math4.legacy.optim.BaseMultivariateOptimizer<PointValuePair>
-
- org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer
-
- org.apache.commons.math4.legacy.optim.nonlinear.scalar.noderiv.CMAESOptimizer
-
public class CMAESOptimizer extends MultivariateOptimizer
An implementation of the active Covariance Matrix Adaptation Evolution Strategy (CMA-ES) for non-linear, non-convex, non-smooth, global function minimization.The CMA-Evolution Strategy (CMA-ES) is a reliable stochastic optimization method which should be applied if derivative-based methods, e.g. quasi-Newton BFGS or conjugate gradient, fail due to a rugged search landscape (e.g. noise, local optima, outlier, etc.) of the objective function. Like a quasi-Newton method, the CMA-ES learns and applies a variable metric on the underlying search space. Unlike a quasi-Newton method, the CMA-ES neither estimates nor uses gradients, making it considerably more reliable in terms of finding a good, or even close to optimal, solution.
In general, on smooth objective functions the CMA-ES is roughly ten times slower than BFGS (counting objective function evaluations, no gradients provided). For up to
N=10
variables also the derivative-free simplex direct search method (Nelder and Mead) can be faster, but it is far less reliable than CMA-ES.The CMA-ES is particularly well suited for non-separable and/or badly conditioned problems. To observe the advantage of CMA compared to a conventional evolution strategy, it will usually take about
30 N
function evaluations. On difficult problems the complete optimization (a single run) is expected to take roughly between30 N
and300 N2
function evaluations.This implementation is translated and adapted from the Matlab version of the CMA-ES algorithm as implemented in module
cmaes.m
version 3.51.For more information, please refer to the following links:
- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description CMAESOptimizer(int maxIterations, double stopFitness, boolean isActiveCMA, int diagonalOnly, int checkFeasableCount, org.apache.commons.rng.UniformRandomProvider rng, boolean generateStatistics, ConvergenceChecker<PointValuePair> checker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected PointValuePair
doOptimize()
Performs the bulk of the optimization algorithm.List<RealMatrix>
getStatisticsDHistory()
List<Double>
getStatisticsFitnessHistory()
List<RealMatrix>
getStatisticsMeanHistory()
List<Double>
getStatisticsSigmaHistory()
PointValuePair
optimize(OptimizationData... optData)
Stores data and performs the optimization.protected void
parseOptimizationData(OptimizationData... optData)
Scans the list of (required and optional) optimization data that characterize the problem.-
Methods inherited from class org.apache.commons.math4.legacy.optim.nonlinear.scalar.MultivariateOptimizer
computeObjectiveValue, createLineSearch, getGoalType, getObjectiveFunction, lineSearch
-
Methods inherited from class org.apache.commons.math4.legacy.optim.BaseMultivariateOptimizer
getLowerBound, getStartPoint, getUpperBound
-
Methods inherited from class org.apache.commons.math4.legacy.optim.BaseOptimizer
getAbsoluteTolerance, getConvergenceChecker, getEvaluations, getIterations, getMaxEvaluations, getMaxIterations, getRelativeTolerance, incrementEvaluationCount, incrementIterationCount, optimize
-
-
-
-
Constructor Detail
-
CMAESOptimizer
public CMAESOptimizer(int maxIterations, double stopFitness, boolean isActiveCMA, int diagonalOnly, int checkFeasableCount, org.apache.commons.rng.UniformRandomProvider rng, boolean generateStatistics, ConvergenceChecker<PointValuePair> checker)
- Parameters:
maxIterations
- Maximal number of iterations.stopFitness
- Whether to stop if objective function value is smaller thanstopFitness
.isActiveCMA
- Chooses the covariance matrix update method.diagonalOnly
- Number of initial iterations, where the covariance matrix remains diagonal.checkFeasableCount
- Determines how often new random objective variables are generated in case they are out of bounds.rng
- Random generator.generateStatistics
- Whether statistic data is collected.checker
- Convergence checker.- Since:
- 3.1
-
-
Method Detail
-
getStatisticsSigmaHistory
public List<Double> getStatisticsSigmaHistory()
- Returns:
- History of sigma values.
-
getStatisticsMeanHistory
public List<RealMatrix> getStatisticsMeanHistory()
- Returns:
- History of mean matrix.
-
getStatisticsFitnessHistory
public List<Double> getStatisticsFitnessHistory()
- Returns:
- History of fitness values.
-
getStatisticsDHistory
public List<RealMatrix> getStatisticsDHistory()
- Returns:
- History of D matrix.
-
optimize
public PointValuePair optimize(OptimizationData... optData)
Stores data and performs the optimization.The list of parameters is open-ended so that sub-classes can extend it with arguments specific to their concrete implementations.
When the method is called multiple times, instance data is overwritten only when actually present in the list of arguments: when not specified, data set in a previous call is retained (and thus is optional in subsequent calls).
Important note: Subclasses must override
BaseOptimizer.parseOptimizationData(OptimizationData[])
if they need to register their own options; but then, they must also callsuper.parseOptimizationData(optData)
within that method.- Overrides:
optimize
in classMultivariateOptimizer
- Parameters:
optData
- Optimization data. In addition to those documented inMultivariateOptimizer
, this method will register the following data:-
Sigma
values define the initial coordinate-wise standard deviations for sampling new search points around the initial guess. It is suggested to set them to the estimated distance from the initial to the desired optimum. Small values induce the search to be more local (and very small values are more likely to find a local optimum close to the initial guess). Too small values might however lead to early termination. -
PopulationSize
is the number of offsprings and the primary strategy parameter. In the absence of better clues, a good default could be an integer close to4 + 3 ln(n)
, wheren
is the number of optimized parameters. Increasing the population size improves global search properties at the expense of speed (which in general decreases at most linearly with increasing population size).
-
- Returns:
- a point/value pair that satisfies the convergence criteria.
- Throws:
TooManyEvaluationsException
- if the maximal number of evaluations is exceeded.DimensionMismatchException
- if the initial guess, target, and weight arguments have inconsistent dimensions.
-
doOptimize
protected PointValuePair doOptimize()
Performs the bulk of the optimization algorithm.- Specified by:
doOptimize
in classBaseOptimizer<PointValuePair>
- Returns:
- the point/value pair giving the optimal value of the objective function.
-
parseOptimizationData
protected void parseOptimizationData(OptimizationData... optData)
Scans the list of (required and optional) optimization data that characterize the problem.- Overrides:
parseOptimizationData
in classMultivariateOptimizer
- Parameters:
optData
- Optimization data. The following data will be looked for:
-
-