Deprecated
As of 3.1 (to be removed in 4.0).
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 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 function evaluations. On difficult problems the complete optimization (a single run) is expected to take roughly between and 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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | CMAESOptimizer.
Used to sort fitness values. |
| private class | CMAESOptimizer.
Normalizes fitness values to the range [0,1]. |
| public static class | CMAESOptimizer.
Deprecated
as a consequence of Population size.
OptimizationData being deprecated.
|
| public static class | CMAESOptimizer.
Deprecated
as a consequence of Input sigma values.
OptimizationData being deprecated.
|
| Modifier and Type | Field and Description |
|---|---|
| private RealMatrix | B
Coordinate system. |
| private RealMatrix | BD
B*D, stored for efficiency. |
| private RealMatrix | C
Covariance matrix. |
| private double | cc
Cumulation constant. |
| private double | ccov1
Learning rate for rank-one update. |
| private double | ccov1Sep
Learning rate for rank-one update - diagonalOnly |
| private double | ccovmu
Learning rate for rank-mu update' |
| private double | ccovmuSep
Learning rate for rank-mu update - diagonalOnly |
| private int | checkFeasableCount
Determines how often a new random offspring is generated in case it is not feasible / beyond the defined limits, default is 0. |
| private double | chiN
Expectation of ||N(0,I)|| == norm(randn(N,1)). |
| private double | cs
Cumulation constant for step-size. |
| private RealMatrix | D
Scaling. |
| private double | damps
Damping for step-size. |
| public static final int | DEFAULT_CHECKFEASABLECOUNT
Default value for |
| public static final int | DEFAULT_DIAGONALONLY
Default value for |
| public static final boolean | DEFAULT_ISACTIVECMA
Default value for |
| public static final int | DEFAULT_MAXITERATIONS
Default value for |
| public static final RandomGenerator | DEFAULT_RANDOMGENERATOR
Default value for |
| public static final double | DEFAULT_STOPFITNESS
Default value for |
| private RealMatrix | diagC
Diagonal of C, used for diagonalOnly. |
| private RealMatrix | diagD
Diagonal of sqrt(D), stored for efficiency. |
| private int | diagonalOnly
Defines the number of initial iterations, where the covariance matrix remains diagonal and the algorithm has internally linear time complexity. |
| private int | dimension
Number of objective variables/problem dimension |
| private double[] | fitnessHistory
History queue of best values. |
| private boolean | generateStatistics
Indicates whether statistic data is collected. |
| private int | historySize
Size of history queue of best values. |
| private double[] | |
| private boolean | isActiveCMA
Covariance update mechanism, default is active CMA. |
| private boolean | isMinimize
Number of objective variables/problem dimension |
| private int | iterations
Number of iterations already performed. |
| private int | lambda
Population size, offspring number. |
| private double | logMu2
log(mu + 0.5), stored for efficiency. |
| private int | maxIterations
Maximal number of iterations allowed. |
| private int | mu
Number of parents/points for recombination. |
| private double | mueff
Variance-effectiveness of sum w_i x_i. |
| private double | normps
Norm of ps, stored for efficiency. |
| private RealMatrix | pc
Evolution path. |
| private RealMatrix | ps
Evolution path for sigma. |
| private RandomGenerator | random
Random generator. |
| private double | sigma
Overall standard deviation - search volume. |
| private List | statisticsDHistory
History of D matrix. |
| private List | statisticsFitnessHistory
History of fitness values. |
| private List | statisticsMeanHistory
History of mean matrix. |
| private List | statisticsSigmaHistory
History of sigma values. |
| private double | stopFitness
Limit for fitness value. |
| private double | stopTolFun
Stop if fun-changes smaller stopTolFun. |
| private double | stopTolHistFun
Stop if back fun-changes smaller stopTolHistFun. |
| private double | stopTolUpX
Stop if x-changes larger stopTolUpX. |
| private double | stopTolX
Stop if x-change smaller stopTolX. |
| private RealMatrix | weights
Array for weighted recombination. |
| private RealMatrix | xmean
Objective variables. |
| Access | Constructor and Description |
|---|---|
| public | CMAESOptimizer()
Deprecated
As of version 3.1: Parameter
lambda must be
passed with the call to optimize (whereas in the current code it is set to an undocumented value).
Default constructor, uses default parameters |
| public | CMAESOptimizer(int
Population size. lambda)
Deprecated
As of version 3.1: Parameter
lambda must be
passed with the call to optimize (whereas in the current code it is set to an undocumented value)..
|
| public | CMAESOptimizer(int
Population size. lambda, double[] Initial standard deviations to sample new points
around the initial guess. inputSigma)
Deprecated
As of version 3.1: Parameters
lambda and inputSigma must be
passed with the call to optimize.
|
| public | CMAESOptimizer(int
Population size. lambda, double[] Initial standard deviations to sample new points
around the initial guess. inputSigma, int Maximal number of iterations. maxIterations, double Whether to stop if objective function value is smaller than
stopFitness, boolean stopFitness.Chooses the covariance matrix update method. isActiveCMA, int Number of initial iterations, where the covariance matrix
remains diagonal. diagonalOnly, int Determines how often new random objective variables are
generated in case they are out of bounds. checkFeasableCount, RandomGenerator Random generator. random, boolean Whether statistic data is collected. generateStatistics)
Deprecated
See
SimpleValueChecker#SimpleValueChecker()
|
| public | CMAESOptimizer(int
Population size. lambda, double[] Initial standard deviations to sample new points
around the initial guess. inputSigma, int Maximal number of iterations. maxIterations, double Whether to stop if objective function value is smaller than
stopFitness, boolean stopFitness.Chooses the covariance matrix update method. isActiveCMA, int Number of initial iterations, where the covariance matrix
remains diagonal. diagonalOnly, int Determines how often new random objective variables are
generated in case they are out of bounds. checkFeasableCount, RandomGenerator Random generator. random, boolean Whether statistic data is collected. generateStatistics, ConvergenceChecker<PointValuePair> Convergence checker. checker)
Deprecated
As of version 3.1: Parameters
lambda and inputSigma must be
passed with the call to optimize.
|
| public | CMAESOptimizer(int
Maximal number of iterations. maxIterations, double Whether to stop if objective function value is smaller than
stopFitness, boolean stopFitness.Chooses the covariance matrix update method. isActiveCMA, int Number of initial iterations, where the covariance matrix
remains diagonal. diagonalOnly, int Determines how often new random objective variables are
generated in case they are out of bounds. checkFeasableCount, RandomGenerator Random generator. random, boolean Whether statistic data is collected. generateStatistics, ConvergenceChecker<PointValuePair> Convergence checker. checker)
Deprecated
as a consequence of
ConvergenceChecker being deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
| private void | checkParameters()
Hides org. Checks dimensions and values of boundaries and inputSigma if defined. |
| private static void | copyColumn(final RealMatrix
Source matrix. m1, int Source column. col1, RealMatrix Target matrix. m2, int Target column. col2)Copies a column from m1 to m2. |
| private static RealMatrix | Returns: the diagonal n-by-n matrix if m is a column matrix or the column matrix representing the diagonal if m is a n-by-n matrix.Input matrix. m)
|
| private static RealMatrix | Returns: Matrix where the elements of m and n are element-wise divided.Input matrix 1. m, final RealMatrix Input matrix 2. n)
|
| protected PointValuePair | doOptimize()
Implements abstract org.
Deprecated
as a consequence of
PointValuePair being deprecated.
Perform the bulk of the optimization algorithm. |
| private static RealMatrix | Returns: n-by-m matrix of 0 values out of diagonal, and 1 values on the diagonal.Number of rows. n, int Number of columns. m)
|
| public List | |
| public List | |
| public List | |
| public List | |
| private void | initializeCMA(double[]
Initial guess for the arguments of the fitness function. guess)Initialization of the dynamic search parameters |
| private static int[] | Returns: the inverse of the mapping defined by indices.Input index array. indices)
|
| private static RealMatrix | |
| private static double | |
| private static double | |
| private static double | |
| private static double | |
| private static RealMatrix | |
| protected PointValuePair | Returns: the point/value pair giving the optimal value for objective function.Allowed number of evaluations of the objective function. maxEval, MultivariateFunction Objective function. f, GoalType Optimization type. goalType, OptimizationData... Optimization data. The following data will be looked for:
optData)Overrides org.
Deprecated
as a consequence of
GoalType, OptimizationData and PointValuePair being deprecated.
Optimize an objective function. |
| private void | parseOptimizationData(OptimizationData...
Optimization data. The following data will be looked for:
optData)Hides org.
Deprecated
as a consequence of
OptimizationData being deprecated.
Scans the list of (required and optional) optimization data that characterize the problem. |
| private static void | push(double[]
History queue. vals, double Current best fitness value. val)Pushes the current best fitness value in a history queue. |
| private double[] | |
| private RealMatrix | Returns: a 2-dimensional matrix of Gaussian random numbers.Number of rows. size, int Population size. popSize)
|
| private static RealMatrix | Returns: a matrix which replicates the input matrix in both directions.Input matrix. mat, int Number of row replicates. n, int Number of column replicates. m)
|
| private static int[] | Returns: the indices in inverse order (last is first).Input index array. indices)
|
| private static RealMatrix | Returns: Matrix representing the selected columns.Input matrix. m, final int[] Columns to select. cols)
|
| private static RealMatrix | Returns: a sequence as column matrix.Start value. start, double End value. end, double Step size. step)
|
| private int[] | Returns: a sorted array of indices pointing into doubles.Array of values to be sorted. doubles)Sorts fitness values. |
| private static RealMatrix | Returns: Matrix representing the element-wise square root of m.Input matrix. m)
|
| private static RealMatrix | |
| private static RealMatrix | |
| private static RealMatrix | Returns: the matrix where the elements of m and n are element-wise multiplied.Input matrix 1. m, final RealMatrix Input matrix 2. n)
|
| private static RealMatrix | Returns: Upper triangular part of matrix.Input matrix. m, int Diagonal position. k)
|
| private void | |
| private void | updateCovariance(boolean
Flag indicating a small correction. hsig, final RealMatrix Fitness-sorted matrix of the argument vectors producing the
current offspring. bestArx, final RealMatrix Unsorted matrix containing the gaussian random values of the
current offspring. arz, final int[] Indices indicating the fitness-order of the current offspring. arindex, final RealMatrix xmean matrix of the previous generation. xold)Update of the covariance matrix C. |
| private void | updateCovarianceDiagonalOnly(boolean
Flag indicating a small correction. hsig, final RealMatrix Fitness-sorted matrix of the gaussian random values of the
current offspring. bestArz)Update of the covariance matrix C for diagonalOnly > 0 |
| private boolean | Returns: hsig flag indicating a small correction.Weighted row matrix of the gaussian random numbers generating
the current offspring. zmean, RealMatrix xmean matrix of the previous generation. xold)Update of the evolution paths ps and pc. |
| private static RealMatrix |