# CMA-ES

CMA-ES stands for Covariance Matrix Adaptation Evolution Strategy. Evolution strategies (ES) are stochastic, derivative-free methods for numerical optimization of non-linear or non-convex continuous optimization problems. They belong to the class of evolutionary algorithms and evolutionary computation. An evolutionary algorithm is broadly based on the principle of biological evolution, namely the repeated interplay of variation (via recombination and mutation) and selection: in each generation (iteration) new individuals (candidate solutions, denoted as ${\displaystyle x}$) are generated by variation, usually in a stochastic way, of the current parental individuals. Then, some individuals are selected to become the parents in the next generation based on their fitness or objective function value ${\displaystyle f(x)}$. Like this, over the generation sequence, individuals with better and better ${\displaystyle f}$-values are generated.

In an evolution strategy, new candidate solutions are sampled according to a multivariate normal distribution in ${\displaystyle \mathbb {R} ^{n}}$. Recombination amounts to selecting a new mean value for the distribution. Mutation amounts to adding a random vector, a perturbation with zero mean. Pairwise dependencies between the variables in the distribution are represented by a covariance matrix. The covariance matrix adaptation (CMA) is a method to update the covariance matrix of this distribution. This is particularly useful if the function ${\displaystyle f}$ is ill-conditioned.

Adaptation of the covariance matrix amounts to learning a second order model of the underlying objective function similar to the approximation of the inverse Hessian matrix in the Quasi-Newton method in classical optimization. In contrast to most classical methods, fewer assumptions on the nature of the underlying objective function are made. Only the ranking between candidate solutions is exploited for learning the sample distribution and neither derivatives nor even the function values themselves are required by the method.

## Principles

Illustration of an actual optimization run with covariance matrix adaptation on a simple two-dimensional problem. The spherical optimization landscape is depicted with solid lines of equal ${\displaystyle f}$-values. The population (dots) is much larger than necessary, but clearly shows how the distribution of the population (dotted line) changes during the optimization. On this simple problem, the population concentrates over the global optimum within a few generations.

Two main principles for the adaptation of parameters of the search distribution are exploited in the CMA-ES algorithm.

First, a maximum-likelihood principle, based on the idea to increase the probability of successful candidate solutions and search steps. The mean of the distribution is updated such that the likelihood of previously successful candidate solutions is maximized. The covariance matrix of the distribution is updated (incrementally) such that the likelihood of previously successful search steps is increased. Both updates can be interpreted as a natural gradient descent. Also, in consequence, the CMA conducts an iterated principal components analysis of successful search steps while retaining all principal axes. Estimation of distribution algorithms and the Cross-Entropy Method are based on very similar ideas, but estimate (non-incrementally) the covariance matrix by maximizing the likelihood of successful solution points instead of successful search steps.

Second, two paths of the time evolution of the distribution mean of the strategy are recorded, called search or evolution paths. These paths contain significant information about the correlation between consecutive steps. Specifically, if consecutive steps are taken in a similar direction, the evolution paths become long. The evolution paths are exploited in two ways. One path is used for the covariance matrix adaptation procedure in place of single successful search steps and facilitates a possibly much faster variance increase of favorable directions. The other path is used to conduct an additional step-size control. This step-size control aims to make consecutive movements of the distribution mean orthogonal in expectation. The step-size control effectively prevents premature convergence yet allowing fast convergence to an optimum.

## Algorithm

In the following the most commonly used (μ/μw, λ)-CMA-ES is outlined, where in each iteration step a weighted combination of the μ best out of λ new candidate solutions is used to update the distribution parameters. The main loop consists of three main parts: 1) sampling of new solutions, 2) re-ordering of the sampled solutions based on their fitness, 3) update of the internal state variables based on the re-ordered samples. A pseudocode of the algorithm looks as follows.

 set ${\displaystyle \lambda }$  // number of samples per iteration, at least two, generally > 4
initialize ${\displaystyle m}$, ${\displaystyle \sigma }$, ${\displaystyle C=I}$, ${\displaystyle p_{\sigma }=0}$, ${\displaystyle p_{c}=0}$  // initialize state variables
while not terminate  // iterate
for ${\displaystyle i}$ in ${\displaystyle \{1...\lambda \}}$  // sample ${\displaystyle \lambda }$ new solutions and evaluate them
${\displaystyle x_{i}}$ = sample_multivariate_normal(mean=${\displaystyle m}$, covariance_matrix=${\displaystyle \sigma ^{2}C}$)
${\displaystyle f_{i}}$ = fitness(${\displaystyle x_{i}}$)
${\displaystyle x_{1...\lambda }}$ ← ${\displaystyle x_{s(1)...s(\lambda )}}$ with ${\displaystyle s(i)}$ = argsort(${\displaystyle f_{1...\lambda }}$, ${\displaystyle i}$)  // sort solutions
${\displaystyle m'}$ = ${\displaystyle m}$  // we need later ${\displaystyle m-m'}$ and ${\displaystyle x_{i}-m'}$
${\displaystyle m}$ ← update_m${\displaystyle (x_{1},...,}$ ${\displaystyle x_{\lambda })}$  // move mean to better solutions
${\displaystyle p_{\sigma }}$ ← update_ps${\displaystyle (p_{\sigma },}$ ${\displaystyle \sigma ^{-1}C^{-1/2}(m-m'))}$  // update isotropic evolution path
${\displaystyle p_{c}}$ ← update_pc${\displaystyle (p_{c},}$ ${\displaystyle \sigma ^{-1}(m-m'),}$ ${\displaystyle ||p_{\sigma }||)}$  // update anisotropic evolution path
${\displaystyle C}$ ← update_C${\displaystyle (C,}$ ${\displaystyle p_{c},}$ ${\displaystyle {(x_{1}-m')}/{\sigma },...,}$ ${\displaystyle {(x_{\lambda }-m')}/{\sigma })}$  // update covariance matrix
${\displaystyle \sigma }$ ← update_sigma${\displaystyle (\sigma ,}$ ${\displaystyle ||p_{\sigma }||)}$  // update step-size using isotropic path length
return ${\displaystyle m}$ or ${\displaystyle x_{1}}$


The order of the five update assignments is relevant. In the following, the update equations for the five state variables are specified.

Given are the search space dimension ${\displaystyle n}$ and the iteration step ${\displaystyle k}$. The five state variables are

${\displaystyle m_{k}\in \mathbb {R} ^{n}}$, the distribution mean and current favorite solution to the optimization problem,
${\displaystyle \sigma _{k}>0}$, the step-size,
${\displaystyle C_{k}}$, a symmetric and positive definite ${\displaystyle n\times n}$ covariance matrix with ${\displaystyle C_{0}=I}$ and
${\displaystyle p_{\sigma }\in \mathbb {R} ^{n},p_{c}\in \mathbb {R} ^{n}}$, two evolution paths, initially set to the zero vector.

The iteration starts with sampling ${\displaystyle \lambda >1}$ candidate solutions ${\displaystyle x_{i}\in \mathbb {R} ^{n}}$ from a multivariate normal distribution ${\displaystyle \textstyle {\mathcal {N}}(m_{k},\sigma _{k}^{2}C_{k})}$, i.e. for ${\displaystyle i=1,...,\lambda }$

{\displaystyle {\begin{aligned}x_{i}\ &\sim \ {\mathcal {N}}(m_{k},\sigma _{k}^{2}C_{k})\\&\sim \ m_{k}+\sigma _{k}\times {\mathcal {N}}(0,C_{k})\end{aligned}}}

The second line suggests the interpretation as perturbation (mutation) of the current favorite solution vector ${\displaystyle m_{k}}$ (the distribution mean vector). The candidate solutions ${\displaystyle x_{i}}$ are evaluated on the objective function ${\displaystyle f:\mathbb {R} ^{n}\to \mathbb {R} }$ to be minimized. Denoting the ${\displaystyle f}$-sorted candidate solutions as

${\displaystyle \{x_{i:\lambda }\;|\;i=1\dots \lambda \}=\{x_{i}\;|\;i=1\dots \lambda \}\;\;{\text{and}}\;\;f(x_{1:\lambda })\leq \dots \leq f(x_{\mu :\lambda })\leq f(x_{\mu +1:\lambda })\dots ,}$

the new mean value is computed as

{\displaystyle {\begin{aligned}m_{k+1}&=\sum _{i=1}^{\mu }w_{i}\,x_{i:\lambda }\\&=m_{k}+\sum _{i=1}^{\mu }w_{i}\,(x_{i:\lambda }-m_{k})\end{aligned}}}

where the positive (recombination) weights ${\displaystyle w_{1}\geq w_{2}\geq \dots \geq w_{\mu }>0}$ sum to one. Typically, ${\displaystyle \mu \leq \lambda /2}$ and the weights are chosen such that ${\displaystyle \textstyle \mu _{w}:=1/\sum _{i=1}^{\mu }w_{i}^{2}\approx \lambda /4}$. The only feedback used from the objective function here and in the following is an ordering of the sampled candidate solutions due to the indices ${\displaystyle i:\lambda }$.

The step-size ${\displaystyle \sigma _{k}}$ is updated using cumulative step-size adaptation (CSA), sometimes also denoted as path length control. The evolution path (or search path) ${\displaystyle p_{\sigma }}$ is updated first.

${\displaystyle p_{\sigma }\gets \underbrace {(1-c_{\sigma })} _{\!\!\!\!\!{\text{discount factor}}\!\!\!\!\!}\,p_{\sigma }+\overbrace {\sqrt {1-(1-c_{\sigma })^{2}}} ^{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{complements for discounted variance}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}\underbrace {{\sqrt {\mu _{w}}}\,C_{k}^{\;-1/2}\,{\frac {\overbrace {m_{k+1}-m_{k}} ^{\!\!\!{\text{displacement of}}\;m\!\!\!}}{\sigma _{k}}}} _{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{distributed as}}\;{\mathcal {N}}(0,I)\;{\text{under neutral selection}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}}$
${\displaystyle \sigma _{k+1}=\sigma _{k}\times \exp {\bigg (}{\frac {c_{\sigma }}{d_{\sigma }}}\underbrace {\left({\frac {\|p_{\sigma }\|}{E\|{\mathcal {N}}(0,I)\|}}-1\right)} _{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{unbiased about 0 under neutral selection}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}{\bigg )}}$

where

${\displaystyle c_{\sigma }^{-1}\approx n/3}$ is the backward time horizon for the evolution path ${\displaystyle p_{\sigma }}$ and larger than one (${\displaystyle c_{\sigma }\ll 1}$ is reminiscent of an exponential decay constant as ${\displaystyle (1-c_{\sigma })^{k}\approx \exp(-c_{\sigma }k)}$ where ${\displaystyle c_{\sigma }^{-1}}$ is the associated lifetime and ${\displaystyle c_{\sigma }^{-1}\ln(2)\approx 0.7c_{\sigma }^{-1}}$ the half-life),
${\displaystyle \mu _{w}=\left(\sum _{i=1}^{\mu }w_{i}^{2}\right)^{-1}}$ is the variance effective selection mass and ${\displaystyle 1\leq \mu _{w}\leq \mu }$ by definition of ${\displaystyle w_{i}}$,
${\displaystyle C_{k}^{\;-1/2}={\sqrt {C_{k}}}^{\;-1}={\sqrt {C_{k}^{\;-1}}}}$ is the unique symmetric square root of the inverse of ${\displaystyle C_{k}}$, and
${\displaystyle d_{\sigma }}$ is the damping parameter usually close to one. For ${\displaystyle d_{\sigma }=\infty }$ or ${\displaystyle c_{\sigma }=0}$ the step-size remains unchanged.

The step-size ${\displaystyle \sigma _{k}}$ is increased if and only if ${\displaystyle \|p_{\sigma }\|}$ is larger than the expected value

{\displaystyle {\begin{aligned}E\|{\mathcal {N}}(0,I)\|&={\sqrt {2}}\,\Gamma ((n+1)/2)/\Gamma (n/2)\\&\approx {\sqrt {n}}\,(1-1/(4\,n)+1/(21\,n^{2}))\end{aligned}}}

and decreased if it is smaller. For this reason, the step-size update tends to make consecutive steps ${\displaystyle C_{k}^{-1}}$-conjugate, in that after the adaptation has been successful ${\displaystyle \textstyle \left({\frac {m_{k+2}-m_{k+1}}{\sigma _{k+1}}}\right)^{T}\!C_{k}^{-1}{\frac {m_{k+1}-m_{k}}{\sigma _{k}}}\approx 0}$.[1]

Finally, the covariance matrix is updated, where again the respective evolution path is updated first.

${\displaystyle p_{c}\gets \underbrace {(1-c_{c})} _{\!\!\!\!\!{\text{discount factor}}\!\!\!\!\!}\,p_{c}+\underbrace {\mathbf {1} _{[0,\alpha {\sqrt {n}}]}(\|p_{\sigma }\|)} _{\text{indicator function}}\overbrace {\sqrt {1-(1-c_{c})^{2}}} ^{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{complements for discounted variance}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}\underbrace {{\sqrt {\mu _{w}}}\,{\frac {m_{k+1}-m_{k}}{\sigma _{k}}}} _{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{distributed as}}\;{\mathcal {N}}(0,C_{k})\;{\text{under neutral selection}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}}$
${\displaystyle C_{k+1}=\underbrace {(1-c_{1}-c_{\mu }+c_{s})} _{\!\!\!\!\!{\text{discount factor}}\!\!\!\!\!}\,C_{k}+c_{1}\underbrace {p_{c}p_{c}^{T}} _{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{rank one matrix}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}+\,c_{\mu }\underbrace {\sum _{i=1}^{\mu }w_{i}{\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\left({\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\right)^{T}} _{{\text{rank}}\;\min(\mu ,n)\;{\text{matrix}}}}$

where ${\displaystyle T}$ denotes the transpose and

${\displaystyle c_{c}^{-1}\approx n/4}$ is the backward time horizon for the evolution path ${\displaystyle p_{c}}$ and larger than one,
${\displaystyle \alpha \approx 1.5}$ and the indicator function ${\displaystyle \mathbf {1} _{[0,\alpha {\sqrt {n}}]}(\|p_{\sigma }\|)}$ evaluates to one iff ${\displaystyle \|p_{\sigma }\|\in [0,\alpha {\sqrt {n}}]}$ or, in other words, ${\displaystyle \|p_{\sigma }\|\leq \alpha {\sqrt {n}}}$, which is usually the case,
${\displaystyle c_{s}=(1-\mathbf {1} _{[0,\alpha {\sqrt {n}}]}(\|p_{\sigma }\|)^{2})\,c_{1}c_{c}(2-c_{c})}$ makes partly up for the small variance loss in case the indicator is zero,
${\displaystyle c_{1}\approx 2/n^{2}}$ is the learning rate for the rank-one update of the covariance matrix and
${\displaystyle c_{\mu }\approx \mu _{w}/n^{2}}$ is the learning rate for the rank-${\displaystyle \mu }$ update of the covariance matrix and must not exceed ${\displaystyle 1-c_{1}}$.

The covariance matrix update tends to increase the likelihood for ${\displaystyle p_{c}}$ and for ${\displaystyle (x_{i:\lambda }-m_{k})/\sigma _{k}}$ to be sampled from ${\displaystyle {\mathcal {N}}(0,C_{k+1})}$. This completes the iteration step.

The number of candidate samples per iteration, ${\displaystyle \lambda }$, is not determined a priori and can vary in a wide range. Smaller values, for example ${\displaystyle \lambda =10}$, lead to more local search behavior. Larger values, for example ${\displaystyle \lambda =10n}$ with default value ${\displaystyle \mu _{w}\approx \lambda /4}$, render the search more global. Sometimes the algorithm is repeatedly restarted with increasing ${\displaystyle \lambda }$ by a factor of two for each restart.[2] Besides of setting ${\displaystyle \lambda }$ (or possibly ${\displaystyle \mu }$ instead, if for example ${\displaystyle \lambda }$ is predetermined by the number of available processors), the above introduced parameters are not specific to the given objective function and therefore not meant to be modified by the user.

## Example code in MATLAB/Octave

function xmin=purecmaes   % (mu/mu_w, lambda)-CMA-ES
% --------------------  Initialization --------------------------------
% User defined input parameters (need to be edited)
strfitnessfct = 'frosenbrock';  % name of objective/fitness function
N = 20;               % number of objective variables/problem dimension
xmean = rand(N,1);    % objective variables initial point
sigma = 0.3;          % coordinate wise standard deviation (step size)
stopfitness = 1e-10;  % stop if fitness < stopfitness (minimization)
stopeval = 1e3*N^2;   % stop after stopeval number of function evaluations

% Strategy parameter setting: Selection
lambda = 4+floor(3*log(N));  % population size, offspring number
mu = lambda/2;               % number of parents/points for recombination
weights = log(mu+1/2)-log(1:mu)'; % muXone array for weighted recombination
mu = floor(mu);
weights = weights/sum(weights);     % normalize recombination weights array
mueff=sum(weights)^2/sum(weights.^2); % variance-effectiveness of sum w_i x_i

cc = (4+mueff/N) / (N+4 + 2*mueff/N);  % time constant for cumulation for C
cs = (mueff+2) / (N+mueff+5);  % t-const for cumulation for sigma control
c1 = 2 / ((N+1.3)^2+mueff);    % learning rate for rank-one update of C
cmu = min(1-c1, 2 * (mueff-2+1/mueff) / ((N+2)^2+mueff));  % and for rank-mu update
damps = 1 + 2*max(0, sqrt((mueff-1)/(N+1))-1) + cs; % damping for sigma
% usually close to 1
% Initialize dynamic (internal) strategy parameters and constants
pc = zeros(N,1); ps = zeros(N,1);   % evolution paths for C and sigma
B = eye(N,N);                       % B defines the coordinate system
D = ones(N,1);                      % diagonal D defines the scaling
C = B * diag(D.^2) * B';            % covariance matrix C
invsqrtC = B * diag(D.^-1) * B';    % C^-1/2
eigeneval = 0;                      % track update of B and D
chiN=N^0.5*(1-1/(4*N)+1/(21*N^2));  % expectation of
%   ||N(0,I)|| == norm(randn(N,1))
% -------------------- Generation Loop --------------------------------
counteval = 0;  % the next 40 lines contain the 20 lines of interesting code
while counteval < stopeval

% Generate and evaluate lambda offspring
for k=1:lambda,
arx(:,k) = xmean + sigma * B * (D .* randn(N,1)); % m + sig * Normal(0,C)
arfitness(k) = feval(strfitnessfct, arx(:,k)); % objective function call
counteval = counteval+1;
end

% Sort by fitness and compute weighted mean into xmean
[arfitness, arindex] = sort(arfitness); % minimization
xold = xmean;
xmean = arx(:,arindex(1:mu))*weights;   % recombination, new mean value

% Cumulation: Update evolution paths
ps = (1-cs)*ps ...
+ sqrt(cs*(2-cs)*mueff) * invsqrtC * (xmean-xold) / sigma;
hsig = norm(ps)/sqrt(1-(1-cs)^(2*counteval/lambda))/chiN < 1.4 + 2/(N+1);
pc = (1-cc)*pc ...
+ hsig * sqrt(cc*(2-cc)*mueff) * (xmean-xold) / sigma;

artmp = (1/sigma) * (arx(:,arindex(1:mu))-repmat(xold,1,mu));
C = (1-c1-cmu) * C ...                  % regard old matrix
+ c1 * (pc*pc' ...                 % plus rank one update
+ (1-hsig) * cc*(2-cc) * C) ... % minor correction if hsig==0
+ cmu * artmp * diag(weights) * artmp'; % plus rank mu update

sigma = sigma * exp((cs/damps)*(norm(ps)/chiN - 1));

% Decomposition of C into B*diag(D.^2)*B' (diagonalization)
if counteval - eigeneval > lambda/(c1+cmu)/N/10  % to achieve O(N^2)
eigeneval = counteval;
C = triu(C) + triu(C,1)'; % enforce symmetry
[B,D] = eig(C);           % eigen decomposition, B==normalized eigenvectors
D = sqrt(diag(D));        % D is a vector of standard deviations now
invsqrtC = B * diag(D.^-1) * B';
end

% Break, if fitness is good enough or condition exceeds 1e14, better termination methods are advisable
if arfitness(1) <= stopfitness || max(D) > 1e7 * min(D)
break;
end

end % while, end generation loop

xmin = arx(:, arindex(1)); % Return best point of last iteration.
% Notice that xmean is expected to be even
% better.
% ---------------------------------------------------------------
function f=frosenbrock(x)
if size(x,1) < 2 error('dimension must be greater one'); end
f = 100*sum((x(1:end-1).^2 - x(2:end)).^2) + sum((x(1:end-1)-1).^2);


## Theoretical foundations

Given the distribution parameters—mean, variances and covariances—the normal probability distribution for sampling new candidate solutions is the maximum entropy probability distribution over ${\displaystyle \mathbb {R} ^{n}}$, that is, the sample distribution with the minimal amount of prior information built into the distribution. More considerations on the update equations of CMA-ES are made in the following.

### Variable metric

The CMA-ES implements a stochastic variable-metric method. In the very particular case of a convex-quadratic objective function

${\displaystyle f(x)={\textstyle {\frac {1}{2}}}(x-x^{*})^{T}H(x-x^{*})}$

the covariance matrix ${\displaystyle C_{k}}$ adapts to the inverse of the Hessian matrix ${\displaystyle H}$, up to a scalar factor and small random fluctuations. More general, also on the function ${\displaystyle g\circ f}$, where ${\displaystyle g}$ is strictly increasing and therefore order preserving and ${\displaystyle f}$ is convex-quadratic, the covariance matrix ${\displaystyle C_{k}}$ adapts to ${\displaystyle H^{-1}}$, up to a scalar factor and small random fluctuations.

The update equations for mean and covariance matrix maximize a likelihood while resembling an expectation-maximization algorithm. The update of the mean vector ${\displaystyle m}$ maximizes a log-likelihood, such that

${\displaystyle m_{k+1}=\arg \max _{m}\sum _{i=1}^{\mu }w_{i}\log p_{\mathcal {N}}(x_{i:\lambda }|m)}$

where

${\displaystyle \log p_{\mathcal {N}}(x)=-{\frac {1}{2}}\log \det(2\pi C)-{\frac {1}{2}}(x-m)^{T}C^{-1}(x-m)}$

denotes the log-likelihood of ${\displaystyle x}$ from a multivariate normal distribution with mean ${\displaystyle m}$ and any positive definite covariance matrix ${\displaystyle C}$. To see that ${\displaystyle m_{k+1}}$ is independent of ${\displaystyle C}$ remark first that this is the case for any diagonal matrix ${\displaystyle C}$, because the coordinate-wise maximizer is independent of a scaling factor. Then, rotation of the data points or choosing ${\displaystyle C}$ non-diagonal are equivalent.

The rank-${\displaystyle \mu }$ update of the covariance matrix, that is, the right most summand in the update equation of ${\displaystyle C_{k}}$, maximizes a log-likelihood in that

${\displaystyle \sum _{i=1}^{\mu }w_{i}{\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\left({\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\right)^{T}=\arg \max _{C}\sum _{i=1}^{\mu }w_{i}\log p_{\mathcal {N}}\left(\left.{\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\right|C\right)}$

for ${\displaystyle \mu \geq n}$ (otherwise ${\displaystyle C}$ is singular, but substantially the same result holds for ${\displaystyle \mu ). Here, ${\displaystyle p_{\mathcal {N}}(x|C)}$ denotes the likelihood of ${\displaystyle x}$ from a multivariate normal distribution with zero mean and covariance matrix ${\displaystyle C}$. Therefore, for ${\displaystyle c_{1}=0}$ and ${\displaystyle c_{\mu }=1}$, ${\displaystyle C_{k+1}}$ is the above maximum-likelihood estimator. See estimation of covariance matrices for details on the derivation.

### Natural gradient descent in the space of sample distributions

Akimoto et al.[3] and Glasmachers et al.[4] discovered independently that the update of the distribution parameters resembles the descent in direction of a sampled natural gradient of the expected objective function value E f (x) (to be minimized), where the expectation is taken under the sample distribution. With the parameter setting of ${\displaystyle c_{\sigma }=0}$ and ${\displaystyle c_{1}=0}$, i.e. without step-size control and rank-one update, CMA-ES can thus be viewed as an instantiation of Natural Evolution Strategies (NES).[3][4] The natural gradient is independent of the parameterization of the distribution. Taken with respect to the parameters θ of the sample distribution p, the gradient of E f (x) can be expressed as

{\displaystyle {\begin{aligned}{\nabla }_{\!\theta }E(f(x)|\theta )&=\nabla _{\!\theta }\int _{\mathbb {R} ^{n}}f(x)p(x)\mathrm {d} x\\&=\int _{\mathbb {R} ^{n}}f(x)\nabla _{\!\theta }p(x)\mathrm {d} x\\&=\int _{\mathbb {R} ^{n}}f(x)p(x)\nabla _{\!\theta }\ln p(x)\mathrm {d} x\\&=E(f(x)\nabla _{\!\theta }\ln p(x|\theta ))\end{aligned}}}

where ${\displaystyle p(x)=p(x|\theta )}$ depends on the parameter vector ${\displaystyle \theta }$. The so-called score function, ${\displaystyle \nabla _{\!\theta }\ln p(x|\theta )={\frac {\nabla _{\!\theta }p(x)}{p(x)}}}$, indicates the relative sensitivity of p w.r.t. θ, and the expectation is taken with respect to the distribution p. The natural gradient of E f (x), complying with the Fisher information metric (an informational distance measure between probability distributions and the curvature of the relative entropy), now reads

{\displaystyle {\begin{aligned}{\tilde {\nabla }}E(f(x)|\theta )&=F_{\theta }^{-1}\nabla _{\!\theta }E(f(x)|\theta )\end{aligned}}}

where the Fisher information matrix ${\displaystyle F_{\theta }}$ is the expectation of the Hessian of -lnp and renders the expression independent of the chosen parameterization. Combining the previous equalities we get

{\displaystyle {\begin{aligned}{\tilde {\nabla }}E(f(x)|\theta )&=F_{\theta }^{-1}E(f(x)\nabla _{\!\theta }\ln p(x|\theta ))\\&=E(f(x)F_{\theta }^{-1}\nabla _{\!\theta }\ln p(x|\theta ))\end{aligned}}}

A Monte Carlo approximation of the latter expectation takes the average over λ samples from p

${\displaystyle {\tilde {\nabla }}{\widehat {E}}_{\theta }(f):=-\sum _{i=1}^{\lambda }\overbrace {w_{i}} ^{\!\!\!\!{\text{preference weight}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}\underbrace {F_{\theta }^{-1}\nabla _{\!\theta }\ln p(x_{i:\lambda }|\theta )} _{\!\!\!\!\!{\text{candidate direction from }}x_{i:\lambda }\!\!\!\!\!}\quad \mathrm {with~} w_{i}=-f(x_{i:\lambda })/\lambda }$

where the notation ${\displaystyle i:\lambda }$ from above is used and therefore ${\displaystyle w_{i}}$ are monotonously decreasing in ${\displaystyle i}$.

Ollivier et al.[5] finally found a rigorous derivation for the more robust weights, ${\displaystyle w_{i}}$, as they are defined in the CMA-ES (weights are often zero for i > μ). They are formulated as the consistent estimator for the CDF of ${\displaystyle f(X),X\sim p(.|\theta )}$ at the point ${\displaystyle f(x_{i:\lambda })}$, composed with a fixed monotonous decreased transformation ${\displaystyle w}$, that is,

${\displaystyle w_{i}=w\left({\frac {{\mathsf {rank}}(f(x_{i:\lambda }))-1/2}{\lambda }}\right)}$

This makes the algorithm insensitive to the specific ${\displaystyle f}$-values. More concisely, using the CDF estimator of ${\displaystyle f}$ instead of ${\displaystyle f}$ itself let the algorithm only depend on the ranking of ${\displaystyle f}$-values but not on their underlying distribution. It renders the algorithm invariant to monotonous ${\displaystyle f}$-transformations. Let

${\displaystyle \theta =[m_{k}^{T}\mathrm {vec} (C_{k})^{T}\sigma _{k}]^{T}\in \mathbb {R} ^{n+n^{2}+1}}$

such that ${\displaystyle p(.|\theta )}$ is the density of the multivariate normal distribution ${\displaystyle {\mathcal {N}}(m_{k},\sigma _{k}^{2}C_{k})}$. Then, we have an explicit expression for the inverse of the Fisher information matrix where ${\displaystyle \sigma _{k}}$ is fixed

${\displaystyle F_{\theta |\sigma _{k}}^{-1}=\left[{\begin{array}{cc}\sigma _{k}^{2}C_{k}&0\\0&2C_{k}\otimes C_{k}\end{array}}\right]}$

and for

${\displaystyle \ln p(x|\theta )=\ln p(x|m_{k},\sigma _{k}^{2}C_{k})=-{\frac {1}{2}}(x-m_{k})^{T}\sigma _{k}^{-2}C_{k}^{-1}(x-m_{k})\,-\,{\frac {1}{2}}\ln \det(2\pi \sigma _{k}^{2}C_{k})}$

and, after some calculations, the updates in the CMA-ES turn out as[3]

{\displaystyle {\begin{aligned}m_{k+1}&=m_{k}-\underbrace {[{\tilde {\nabla }}{\widehat {E}}_{\theta }(f)]_{1,\dots ,n}} _{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{natural gradient for mean}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}\\&=m_{k}+\sum _{i=1}^{\lambda }w_{i}(x_{i:\lambda }-m_{k})\end{aligned}}}

and

{\displaystyle {\begin{aligned}C_{k+1}&=C_{k}+c_{1}(p_{c}p_{c}^{T}-C_{k})-c_{\mu }\,\mathrm {mat} (\overbrace {[{\tilde {\nabla }}{\widehat {E}}_{\theta }(f)]_{n+1,\dots ,n+n^{2}}} ^{\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!{\text{natural gradient for covariance matrix}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!})\\&=C_{k}+c_{1}(p_{c}p_{c}^{T}-C_{k})+c_{\mu }\sum _{i=1}^{\lambda }w_{i}\left({\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\left({\frac {x_{i:\lambda }-m_{k}}{\sigma _{k}}}\right)^{T}-C_{k}\right)\end{aligned}}}

where mat forms the proper matrix from the respective natural gradient sub-vector. That means, setting ${\displaystyle c_{1}=c_{\sigma }=0}$, the CMA-ES updates descend in direction of the approximation ${\displaystyle {\tilde {\nabla }}{\widehat {E}}_{\theta }(f)}$ of the natural gradient while using different step-sizes (learning rates 1 and ${\displaystyle c_{\mu }}$) for the orthogonal parameters ${\displaystyle m}$ and ${\displaystyle C}$ respectively. The most recent version of CMA-ES also use a different function ${\displaystyle w}$ for ${\displaystyle m}$ and ${\displaystyle C}$ with negative values only for the latter (so-called active CMA).

### Stationarity or unbiasedness

It is comparatively easy to see that the update equations of CMA-ES satisfy some stationarity conditions, in that they are essentially unbiased. Under neutral selection, where ${\displaystyle x_{i:\lambda }\sim {\mathcal {N}}(m_{k},\sigma _{k}^{2}C_{k})}$, we find that

${\displaystyle E(m_{k+1}\,|\,m_{k})=m_{k}}$

and under some mild additional assumptions on the initial conditions

${\displaystyle E(\log \sigma _{k+1}\,|\,\sigma _{k})=\log \sigma _{k}}$

and with an additional minor correction in the covariance matrix update for the case where the indicator function evaluates to zero, we find

${\displaystyle E(C_{k+1}\,|\,C_{k})=C_{k}}$

### Invariance

Invariance properties imply uniform performance on a class of objective functions. They have been argued to be an advantage, because they allow to generalize and predict the behavior of the algorithm and therefore strengthen the meaning of empirical results obtained on single functions. The following invariance properties have been established for CMA-ES.

• Invariance under order-preserving transformations of the objective function value ${\displaystyle f}$, in that for any ${\displaystyle h:\mathbb {R} ^{n}\to \mathbb {R} }$ the behavior is identical on ${\displaystyle f:x\mapsto g(h(x))}$ for all strictly increasing ${\displaystyle g:\mathbb {R} \to \mathbb {R} }$. This invariance is easy to verify, because only the ${\displaystyle f}$-ranking is used in the algorithm, which is invariant under the choice of ${\displaystyle g}$.
• Scale-invariance, in that for any ${\displaystyle h:\mathbb {R} ^{n}\to \mathbb {R} }$ the behavior is independent of ${\displaystyle \alpha >0}$ for the objective function ${\displaystyle f:x\mapsto h(\alpha x)}$ given ${\displaystyle \sigma _{0}\propto 1/\alpha }$ and ${\displaystyle m_{0}\propto 1/\alpha }$.
• Invariance under rotation of the search space in that for any ${\displaystyle h:\mathbb {R} ^{n}\to \mathbb {R} }$ and any ${\displaystyle z\in \mathbb {R} ^{n}}$ the behavior on ${\displaystyle f:x\mapsto h(Rx)}$ is independent of the orthogonal matrix ${\displaystyle R}$, given ${\displaystyle m_{0}=R^{-1}z}$. More general, the algorithm is also invariant under general linear transformations ${\displaystyle R}$ when additionally the initial covariance matrix is chosen as ${\displaystyle R^{-1}{R^{-1}}^{T}}$.

Any serious parameter optimization method should be translation invariant, but most methods do not exhibit all the above described invariance properties. A prominent example with the same invariance properties is the Nelder–Mead method, where the initial simplex must be chosen respectively.

### Convergence

Conceptual considerations like the scale-invariance property of the algorithm, the analysis of simpler evolution strategies, and overwhelming empirical evidence suggest that the algorithm converges on a large class of functions fast to the global optimum, denoted as ${\displaystyle x^{*}}$. On some functions, convergence occurs independently of the initial conditions with probability one. On some functions the probability is smaller than one and typically depends on the initial ${\displaystyle m_{0}}$ and ${\displaystyle \sigma _{0}}$. Empirically, the fastest possible convergence rate in ${\displaystyle k}$ for rank-based direct search methods can often be observed (depending on the context denoted as linear or log-linear or exponential convergence). Informally, we can write

${\displaystyle \|m_{k}-x^{*}\|\;\approx \;\|m_{0}-x^{*}\|\times e^{-ck}}$

for some ${\displaystyle c>0}$, and more rigorously

${\displaystyle {\frac {1}{k}}\sum _{i=1}^{k}\log {\frac {\|m_{i}-x^{*}\|}{\|m_{i-1}-x^{*}\|}}\;=\;{\frac {1}{k}}\log {\frac {\|m_{k}-x^{*}\|}{\|m_{0}-x^{*}\|}}\;\to \;-c<0\quad {\text{for}}\;k\to \infty \;,}$

or similarly,

${\displaystyle E\log {\frac {\|m_{k}-x^{*}\|}{\|m_{k-1}-x^{*}\|}}\;\to \;-c<0\quad {\text{for}}\;k\to \infty \;.}$

This means that on average the distance to the optimum decreases in each iteration by a "constant" factor, namely by ${\displaystyle \exp(-c)}$. The convergence rate ${\displaystyle c}$ is roughly ${\displaystyle 0.1\lambda /n}$, given ${\displaystyle \lambda }$ is not much larger than the dimension ${\displaystyle n}$. Even with optimal ${\displaystyle \sigma }$ and ${\displaystyle C}$, the convergence rate ${\displaystyle c}$ cannot largely exceed ${\displaystyle 0.25\lambda /n}$, given the above recombination weights ${\displaystyle w_{i}}$ are all non-negative. The actual linear dependencies in ${\displaystyle \lambda }$ and ${\displaystyle n}$ are remarkable and they are in both cases the best one can hope for in this kind of algorithm. Yet, a rigorous proof of convergence is missing.

### Interpretation as coordinate-system transformation

Using a non-identity covariance matrix for the multivariate normal distribution in evolution strategies is equivalent to a coordinate system transformation of the solution vectors,[6] mainly because the sampling equation

{\displaystyle {\begin{aligned}x_{i}&\sim \ m_{k}+\sigma _{k}\times {\mathcal {N}}(0,C_{k})\\&\sim \ m_{k}+\sigma _{k}\times C_{k}^{1/2}{\mathcal {N}}(0,I)\end{aligned}}}

can be equivalently expressed in an "encoded space" as

${\displaystyle \underbrace {C_{k}^{-1/2}x_{i}} _{{\text{represented in the encode space}}\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!\!}\sim \ \underbrace {C_{k}^{-1/2}m_{k}} {}+\sigma _{k}\times {\mathcal {N}}(0,I)}$

The covariance matrix defines a bijective transformation (encoding) for all solution vectors into a space, where the sampling takes place with identity covariance matrix. Because the update equations in the CMA-ES are invariant under linear coordinate system transformations, the CMA-ES can be re-written as an adaptive encoding procedure applied to a simple evolution strategy with identity covariance matrix.[6] This adaptive encoding procedure is not confined to algorithms that sample from a multivariate normal distribution (like evolution strategies), but can in principle be applied to any iterative search method.

## Performance in practice

In contrast to most other evolutionary algorithms, the CMA-ES is, from the user's perspective, quasi parameter-free. The user has to choose an initial solution point, ${\displaystyle m_{0}\in \mathbb {R} ^{n}}$, and the initial step-size, ${\displaystyle \sigma _{0}>0}$. Optionally, the number of candidate samples λ (population size) can be modified by the user in order to change the characteristic search behavior (see above) and termination conditions can or should be adjusted to the problem at hand.

The CMA-ES has been empirically successful in hundreds of applications and is considered to be useful in particular on non-convex, non-separable, ill-conditioned, multi-modal or noisy objective functions[citation needed]. The search space dimension ranges typically between two and a few hundred. Assuming a black-box optimization scenario, where gradients are not available (or not useful) and function evaluations are the only considered cost of search, the CMA-ES method is likely to be outperformed by other methods in the following conditions:

• on low-dimensional functions, say ${\displaystyle n<5}$, for example by the downhill simplex method or surrogate-based methods (like kriging with expected improvement);
• on separable functions without or with only negligible dependencies between the design variables in particular in the case of multi-modality or large dimension, for example by differential evolution;
• on (nearly) convex-quadratic functions with low or moderate condition number of the Hessian matrix, where BFGS or NEWUOA are typically ten times faster;
• on functions that can already be solved with a comparatively small number of function evaluations, say no more than ${\displaystyle 10n}$, where CMA-ES is often slower than, for example, NEWUOA or Multilevel Coordinate Search (MCS).

On separable functions, the performance disadvantage is likely to be most significant in that CMA-ES might not be able to find at all comparable solutions. On the other hand, on non-separable functions that are ill-conditioned or rugged or can only be solved with more than ${\displaystyle 100n}$ function evaluations, the CMA-ES shows most often superior performance.

## Variations and extensions

The (1+1)-CMA-ES[7] generates only one candidate solution per iteration step which becomes the new distribution mean if it is better than the current mean. For ${\displaystyle c_{c}=1}$ the (1+1)-CMA-ES is a close variant of Gaussian adaptation. Some Natural Evolution Strategies are close variants of the CMA-ES with specific parameter settings. Natural Evolution Strategies do not utilize evolution paths (that means in CMA-ES setting ${\displaystyle c_{c}=c_{\sigma }=1}$) and they formalize the update of variances and covariances on a Cholesky factor instead of a covariance matrix. The CMA-ES has also been extended to multiobjective optimization as MO-CMA-ES.[8] Another remarkable extension has been the addition of a negative update of the covariance matrix with the so-called active CMA.[9]

With the advent of niching methods in evolutionary strategies, the question of an optimal niche radius arises. An "adaptive individual niche radius" is introduced in [10]

## References

1. ^ Hansen, N. (2006), "The CMA evolution strategy: a comparing review", Towards a new evolutionary computation. Advances on estimation of distribution algorithms, Springer, pp. 1769–1776
2. ^ Auger, A.; N. Hansen (2005). "A Restart CMA Evolution Strategy With Increasing Population Size" (PDF). 2005 IEEE Congress on Evolutionary Computation, Proceedings. IEEE. pp. 1769–1776.
3. ^ a b c Akimoto, Y.; Y. Nagata; I. Ono; S. Kobayashi (2010). "Bidirectional Relation between CMA Evolution Strategies and Natural Evolution Strategies". Parallel Problem Solving from Nature, PPSN XI. Springer. pp. 154–163.
4. ^ a b Glasmachers, T.; T. Schaul; Y. Sun; D. Wierstra; J. Schmidhuber (2010). "Exponential Natural Evolution Strategies" (PDF). Genetic and Evolutionary Computation Conference GECCO. Portland, OR.
5. ^ Ollivier, Y.; Arnold, L.; Auger, A.; Hansen, N. (2013). "Information-Geometric Optimization Algorithms: A Unifying Picture via Invariance Principles". arXiv:.
6. ^ a b Hansen, N. (2008). "Adpative Encoding: How to Render Search Coordinate System Invariant". Parallel Problem Solving from Nature, PPSN X. Springer. pp. 205–214.
7. ^ Igel, C.; T. Suttorp; N. Hansen (2006). "A Computational Efficient Covariance Matrix Update and a (1+1)-CMA for Evolution Strategies" (PDF). Proceedings of the Genetic and Evolutionary Computation Conference (GECCO). ACM Press. pp. 453–460.
8. ^ Igel, C.; N. Hansen; S. Roth (2007). "Covariance Matrix Adaptation for Multi-objective Optimization". Evolutionary Computation. MIT press. 15 (1): 1–28. doi:10.1162/evco.2007.15.1.1. PMID 17388777.
9. ^ Jastrebski, G.A.; D.V. Arnold (2006). "Improving Evolution Strategies through Active Covariance Matrix Adaptation". 2006 IEEE World Congress on Computational Intelligence, Proceedings. IEEE. pp. 9719–9726. doi:10.1109/CEC.2006.1688662.
10. ^ Shir, Ofer M.; Bäck, Thomas (2006). Parallel Problem Solving from Nature-PPSN IX. Springer. pp. 142–151.

## Bibliography

• Hansen N, Ostermeier A (2001). Completely derandomized self-adaptation in evolution strategies. Evolutionary Computation, 9(2) pp. 159–195. [1]
• Hansen N, Müller SD, Koumoutsakos P (2003). Reducing the time complexity of the derandomized evolution strategy with covariance matrix adaptation (CMA-ES). Evolutionary Computation, 11(1) pp. 1–18. [2]
• Hansen N, Kern S (2004). Evaluating the CMA evolution strategy on multimodal test functions. In Xin Yao et al., editors, Parallel Problem Solving from Nature - PPSN VIII, pp. 282–291, Springer. [3]
• Igel C, Hansen N, Roth S (2007). Covariance Matrix Adaptation for Multi-objective Optimization. Evolutionary Computation, 15(1) pp. 1–28. [4]