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.
For more information, please refer to the following links:
| 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.
Population size. |
| public static class | CMAESOptimizer.
Input sigma values. |
| private static class | CMAESOptimizer.
Stores the value and penalty (for repair of out of bounds point). |
| 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 final 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. |
| 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 final boolean | generateStatistics
Indicates whether statistic data is collected. |
| private int | historySize
Size of history queue of best values. |
| private double[] | |
| private final boolean | isActiveCMA
Covariance update mechanism, default is active CMA. |
| private boolean | isMinimize
Number of objective variables/problem dimension |
| private int | iterations
Hides org. |
| private int | lambda
Population size, offspring number. |
| private double | logMu2
log(mu + 0.5), stored for efficiency. |
| private final 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 final RandomGenerator | random
Random generator. |
| private double | sigma
Overall standard deviation - search volume. |
| private final List | statisticsDHistory
History of D matrix. |
| private final List | statisticsFitnessHistory
History of fitness values. |
| private final List | statisticsMeanHistory
History of mean matrix. |
| private final List | statisticsSigmaHistory
History of sigma values. |
| private final 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(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)
|
| 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. Performs 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 | |
| public PointValuePair | Returns: a point/value pair that satisfies the convergence criteria.Optimization data. In addition to those documented in
optData)MultivariateOptimizer, this method will register the following data:
Overrides org. Stores data and performs the optimization. |
| protected void | parseOptimizationData(OptimizationData...
Optimization data. The following data will be looked for:
optData)Overrides org. 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 double | Returns: a double equal to maximum value minus minimum value.Array of valuePenaltyPairs to get range from. vpPairsGet range of values. |
| private static RealMatrix |