CMA-ES
Evolutionary algorithm
- 36 min read
- 6 chapters
Related on Lably
Through Mathematical optimization, Evolution and Loss function
In an evolution strategy, new candidate solutions are usually sampled according to a multivariate normal distribution in . 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 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 underlying objective function are made. Because only a ranking (or, equivalently, sorting) of candidate solutions is exploited, neither derivatives nor even an (explicit) objective function is required by the method. For example, the ranking could come about from pairwise competitions between the candidate solutions in a Swiss-system tournament.
Principles
Two main principles for the adaptation of parameters of the search distribution are exploited in the CMA-ES algorithm.
First, a maximum-likelihood principle predicated on the idea that increasing (though not necessarily maximizing) the sample probability of successful candidate solutions or search directions is beneficial. 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 generally estimate (non-incrementally) the covariance matrix by maximizing the likelihood of successful solution points rather than 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.
Sign in to keep reading
5 more chapters are free with a Lably account.
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.
<b id="mwSQ">set</b> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt8" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"\\lambda"}}' id="mwSg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle \lambda }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>λ<!-- λ --></mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \lambda }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b43d0ea3c9c025af1be9128e62a18fa74bedda2a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.355ex; height:2.176ex;" alt="{\displaystyle \lambda }"/></span> // number of samples per iteration, at least two, generally > 4 <b id="mwSw">initialize</b> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt9" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"m"}}' id="mwTA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"/></span>, <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt10" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"\\sigma"}}' id="mwTQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle \sigma }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>σ<!-- σ --></mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \sigma }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/59f59b7c3e6fdb1d0365a494b81fb9a696138c36" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle \sigma }"/></span>, <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt11" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"C=I"}}' id="mwTg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle C=I}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>C</mi> <mo>=</mo> <mi>I</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle C=I}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0e7945f445688c1d706436f645f853f1851410af" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.037ex; height:2.176ex;" alt="{\displaystyle C=I}"/></span>, <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt12" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"p_\\sigma=0"}}' id="mwTw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle p_{\sigma }=0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>σ<!-- σ --></mi> </mrow> </msub> <mo>=</mo> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle p_{\sigma }=0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/1f61bb99b7b5efe23a8c24774b5677ab93c68ed8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:6.692ex; height:2.509ex;" alt="{\displaystyle p_{\sigma }=0}"/></span>, <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt13" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"p_c=0"}}' id="mwUA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle p_{c}=0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>c</mi> </mrow> </msub> <mo>=</mo> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle p_{c}=0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b23fbbfb9d75d2651e3cb1ff3ff639f117b4be18" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:6.464ex; height:2.509ex;" alt="{\displaystyle p_{c}=0}"/></span> // initialize state variables <b id="mwUQ">while</b> <i id="mwUg">not terminate</i> <b id="mwUw">do</b> // iterate <b id="mwVA">for</b> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt14" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"i"}}' id="mwVQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle i}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>i</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle i}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/add78d8608ad86e54951b8c8bd6c8d8416533d20" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.802ex; height:2.176ex;" alt="{\displaystyle i}"/></span> <b id="mwVg">in</b> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt15" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"\\{1\\ldots\\lambda\\}"}}' id="mwVw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle \{1\ldots \lambda \}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo fence="false" stretchy="false">{</mo> <mn>1</mn> <mo>…<!-- … --></mo> <mi>λ<!-- λ --></mi> <mo fence="false" stretchy="false">}</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \{1\ldots \lambda \}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/612b7fa33f53a6da7b3c903b0e502559348aaf22" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.34ex; height:2.843ex;" alt="{\displaystyle \{1\ldots \lambda \}}"/></span> <b id="mwWA">do</b> // sample <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt16" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"\\lambda"}}' id="mwWQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle \lambda }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>λ<!-- λ --></mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \lambda }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/b43d0ea3c9c025af1be9128e62a18fa74bedda2a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.355ex; height:2.176ex;" alt="{\displaystyle \lambda }"/></span> new solutions and evaluate them <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt17" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"x_i ={}"}}' id="mwWg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle x_{i}={}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>i</mi> </mrow> </msub> <mo>=</mo> <mrow class="MJX-TeXAtom-ORD"> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle x_{i}={}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/67335873b8c3cf2854559717a90d56eedebd89a8" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:5.228ex; height:2.009ex;" alt="{\displaystyle x_{i}={}}"/></span>sample_multivariate_normal(mean<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt18" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"{}=m"}}' id="mwWw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle {}=m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> </mrow> <mo>=</mo> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {}=m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3755f4fc92a65ad44d1dc79133b048b681ed434e" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:5.139ex; height:1.676ex;" alt="{\displaystyle {}=m}"/></span>, covariance_matrix<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt19" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"{}=\\sigma^2 C "}}' id="mwXA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle {}=\sigma ^{2}C}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow class="MJX-TeXAtom-ORD"> </mrow> <mo>=</mo> <msup> <mi>σ<!-- σ --></mi> <mrow class="MJX-TeXAtom-ORD"> <mn>2</mn> </mrow> </msup> <mi>C</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle {}=\sigma ^{2}C}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/01c4f75be2418676c6bef536f4b32c431c79a697" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:7.25ex; height:2.676ex;" alt="{\displaystyle {}=\sigma ^{2}C}"/></span>) <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt20" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"f_i = \\operatorname{fitness}(x_i)"}}' id="mwXQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle f_{i}=\operatorname {fitness} (x_{i})}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>f</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>i</mi> </mrow> </msub> <mo>=</mo> <mi>fitness</mi> <mo><!-- --></mo> <mo stretchy="false">(</mo> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>i</mi> </mrow> </msub> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle f_{i}=\operatorname {fitness} (x_{i})}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/e8063afecede89c224dcd706d36e7699fb07c10a" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:15.397ex; height:2.843ex;" alt="{\displaystyle f_{i}=\operatorname {fitness} (x_{i})}"/></span> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt21" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"x_{1\\ldots\\lambda}"}}' id="mwXg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle x_{1\ldots \lambda }}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> <mo>…<!-- … --></mo> <mi>λ<!-- λ --></mi> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle x_{1\ldots \lambda }}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/896938ba8abb5c77cd81c9ce3b76de740b57d874" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:5.268ex; height:2.009ex;" alt="{\displaystyle x_{1\ldots \lambda }}"/></span> <span typeof="mw:Entity" id="mwXw">←</span> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt22" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"x_{s(1)\\ldots s(\\lambda)}"}}' id="mwYA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle x_{s(1)\ldots s(\lambda )}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>s</mi> <mo stretchy="false">(</mo> <mn>1</mn> <mo stretchy="false">)</mo> <mo>…<!-- … --></mo> <mi>s</mi> <mo stretchy="false">(</mo> <mi>λ<!-- λ --></mi> <mo stretchy="false">)</mo> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle x_{s(1)\ldots s(\lambda )}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/f0ea84fbaf894e00bb2c8e7f2900704658389574" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.171ex; width:9.369ex; height:2.509ex;" alt="{\displaystyle x_{s(1)\ldots s(\lambda )}}"/></span> with <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt23" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"s(i) = \\operatorname{argsort}(f_{1\\ldots\\lambda}, i)"}}' id="mwYQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle s(i)=\operatorname {argsort} (f_{1\ldots \lambda },i)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>s</mi> <mo stretchy="false">(</mo> <mi>i</mi> <mo stretchy="false">)</mo> <mo>=</mo> <mi>argsort</mi> <mo><!-- --></mo> <mo stretchy="false">(</mo> <msub> <mi>f</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> <mo>…<!-- … --></mo> <mi>λ<!-- λ --></mi> </mrow> </msub> <mo>,</mo> <mi>i</mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle s(i)=\operatorname {argsort} (f_{1\ldots \lambda },i)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/224b15839941495dc2ba0735a4ebf52412a21891" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:22.655ex; height:2.843ex;" alt="{\displaystyle s(i)=\operatorname {argsort} (f_{1\ldots \lambda },i)}"/></span> // sort solutions <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt24" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"m' = m"}}' id="mwYg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle m'=m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msup> <mi>m</mi> <mo>′</mo> </msup> <mo>=</mo> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m'=m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ff480b3622dd206f473ecf2e37cedcc74ad90ffd" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:7.864ex; height:2.509ex;" alt="{\displaystyle m'=m}"/></span> // we need later <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt25" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"m - m'"}}' id="mwYw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle m-m'}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m-m'}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/68255a60e1cf9871b801b0419a99ba93ac0e18a0" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:7.606ex; height:2.676ex;" alt="{\displaystyle m-m'}"/></span> and <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt26" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"x_i - m'"}}' id="mwZA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle x_{i}-m'}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>i</mi> </mrow> </msub> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle x_{i}-m'}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/5ce2c3d7fb7659271e345a19d540a764ec71fae1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:7.695ex; height:2.843ex;" alt="{\displaystyle x_{i}-m'}"/></span> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt27" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"m"}}' id="mwZQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"/></span> <span typeof="mw:Entity" id="mwZg">←</span> update_m<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt28" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"(x_1, \\ldots ,x_\\lambda)"}}' id="mwZw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle (x_{1},\ldots ,x_{\lambda })}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </msub> <mo>,</mo> <mo>…<!-- … --></mo> <mo>,</mo> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>λ<!-- λ --></mi> </mrow> </msub> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (x_{1},\ldots ,x_{\lambda })}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/46ee5d8b3dcb71a4236348092e667794f9d0ff9f" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.892ex; height:2.843ex;" alt="{\displaystyle (x_{1},\ldots ,x_{\lambda })}"/></span> // move mean to better solutions <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt29" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"p_\\sigma"}}' id="mwaA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle p_{\sigma }}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>σ<!-- σ --></mi> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle p_{\sigma }}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/6038f411ed45fd574bff054df13006bde88ef427" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:2.431ex; height:2.009ex;" alt="{\displaystyle p_{\sigma }}"/></span> <span typeof="mw:Entity" id="mwaQ">←</span> update_ps<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt30" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"(p_\\sigma,\\sigma^{-1} C^{-1/2} (m - m'))"}}' id="mwag"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle (p_{\sigma },\sigma ^{-1}C^{-1/2}(m-m'))}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>σ<!-- σ --></mi> </mrow> </msub> <mo>,</mo> <msup> <mi>σ<!-- σ --></mi> <mrow class="MJX-TeXAtom-ORD"> <mo>−<!-- − --></mo> <mn>1</mn> </mrow> </msup> <msup> <mi>C</mi> <mrow class="MJX-TeXAtom-ORD"> <mo>−<!-- − --></mo> <mn>1</mn> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mn>2</mn> </mrow> </msup> <mo stretchy="false">(</mo> <mi>m</mi> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> <mo stretchy="false">)</mo> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (p_{\sigma },\sigma ^{-1}C^{-1/2}(m-m'))}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/82f72e73cead00f9b90772652ab5fd3de6e3c34b" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:24.038ex; height:3.343ex;" alt="{\displaystyle (p_{\sigma },\sigma ^{-1}C^{-1/2}(m-m'))}"/></span> // update isotropic evolution path <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt31" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"p_c"}}' id="mwaw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle p_{c}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>c</mi> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle p_{c}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/836639c3805ca867b1ff24dc6db7a6b24fc69158" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:2.203ex; height:2.009ex;" alt="{\displaystyle p_{c}}"/></span> <span typeof="mw:Entity" id="mwbA">←</span> update_pc<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt32" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"(p_c,\\sigma^{-1}(m - m'),\\|p_\\sigma\\|)"}}' id="mwbQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle (p_{c},\sigma ^{-1}(m-m'),\|p_{\sigma }\|)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>c</mi> </mrow> </msub> <mo>,</mo> <msup> <mi>σ<!-- σ --></mi> <mrow class="MJX-TeXAtom-ORD"> <mo>−<!-- − --></mo> <mn>1</mn> </mrow> </msup> <mo stretchy="false">(</mo> <mi>m</mi> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> <mo stretchy="false">)</mo> <mo>,</mo> <mo fence="false" stretchy="false">‖<!-- ‖ --></mo> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>σ<!-- σ --></mi> </mrow> </msub> <mo fence="false" stretchy="false">‖<!-- ‖ --></mo> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (p_{c},\sigma ^{-1}(m-m'),\|p_{\sigma }\|)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/10a227c46e6fc345b57d5b2e11c41c2aa9f056f2" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:23.736ex; height:3.176ex;" alt="{\displaystyle (p_{c},\sigma ^{-1}(m-m'),\|p_{\sigma }\|)}"/></span> // update anisotropic evolution path <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt33" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"C"}}' id="mwbg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle C}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>C</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle C}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/4fc55753007cd3c18576f7933f6f089196732029" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.766ex; height:2.176ex;" alt="{\displaystyle C}"/></span> <span typeof="mw:Entity" id="mwbw">←</span> update_C<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt34" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"(C,p_c,(x_1 - m')/\\sigma,\\ldots ,(x_\\lambda - m')/\\sigma)"}}' id="mwcA"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle (C,p_{c},(x_{1}-m')/\sigma ,\ldots ,(x_{\lambda }-m')/\sigma )}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mi>C</mi> <mo>,</mo> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>c</mi> </mrow> </msub> <mo>,</mo> <mo stretchy="false">(</mo> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </msub> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mi>σ<!-- σ --></mi> <mo>,</mo> <mo>…<!-- … --></mo> <mo>,</mo> <mo stretchy="false">(</mo> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>λ<!-- λ --></mi> </mrow> </msub> <mo>−<!-- − --></mo> <msup> <mi>m</mi> <mo>′</mo> </msup> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mi>σ<!-- σ --></mi> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (C,p_{c},(x_{1}-m')/\sigma ,\ldots ,(x_{\lambda }-m')/\sigma )}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/c2d0cac8426eb32956dec4a80fd8c34c70500510" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:37.573ex; height:3.009ex;" alt="{\displaystyle (C,p_{c},(x_{1}-m')/\sigma ,\ldots ,(x_{\lambda }-m')/\sigma )}"/></span> // update covariance matrix <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt35" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"\\sigma"}}' id="mwcQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle \sigma }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>σ<!-- σ --></mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \sigma }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/59f59b7c3e6fdb1d0365a494b81fb9a696138c36" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle \sigma }"/></span> <span typeof="mw:Entity" id="mwcg">←</span> update_sigma<span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt36" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"(\\sigma,\\|p_\\sigma\\|)"}}' id="mwcw"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle (\sigma ,\|p_{\sigma }\|)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mi>σ<!-- σ --></mi> <mo>,</mo> <mo fence="false" stretchy="false">‖<!-- ‖ --></mo> <msub> <mi>p</mi> <mrow class="MJX-TeXAtom-ORD"> <mi>σ<!-- σ --></mi> </mrow> </msub> <mo fence="false" stretchy="false">‖<!-- ‖ --></mo> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (\sigma ,\|p_{\sigma }\|)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a0555f1c6e116513af1edd8e39e15080a0290cf1" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.84ex; height:2.843ex;" alt="{\displaystyle (\sigma ,\|p_{\sigma }\|)}"/></span> // update step-size using isotropic path length <b id="mwdA">return</b> <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt37" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"m"}}' id="mwdQ"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle m}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>m</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle m}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/0a07d98bb302f3856cbabc47b2b9016692e3f7bc" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}"/></span> or <span class="mwe-math-element mwe-math-element-inline" typeof="mw:Extension/math" about="#mwt38" data-mw='{"name":"math","attrs":{},"body":{"extsrc":"x_1"}}' id="mwdg"><span class="mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" class="mathjax_ignore" alttext="{\displaystyle x_{1}}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <msub> <mi>x</mi> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </msub> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle x_{1}}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/a8788bf85d532fa88d1fb25eff6ae382a601c308" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.384ex; height:2.009ex;" alt="{\displaystyle x_{1}}"/></span>The order of the five update assignments is relevant: must be updated first, and must be updated before , and must be updated last. The update equations for the five state variables are specified in the following.
Given are the search space dimension and the iteration step . The five state variables are
- , the distribution mean and current favorite solution to the optimization problem,
- , the step-size,
- , a symmetric and positive-definite covariance matrix with and
- , two evolution paths, initially set to the zero vector.
The iteration starts with sampling candidate solutions from a multivariate normal distribution , i.e. for
The second line suggests the interpretation as unbiased perturbation (mutation) of the current favorite solution vector (the distribution mean vector). The candidate solutions are evaluated on the objective function to be minimized. Denoting the -sorted candidate solutions as
the new mean value is computed as
where the positive (recombination) weights sum to one. Typically, and the weights are chosen such that . 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 .
The step-size is updated using cumulative step-size adaptation (CSA), sometimes also denoted as path length control. The evolution path (or search path) is updated first.
where
- is the backward time horizon for the evolution path and larger than one ( is reminiscent of an exponential decay constant as where is the associated lifetime and the half-life),
- is the variance effective selection mass and by definition of ,
- is the unique symmetric square root of the inverse of , and
- is the damping parameter usually close to one. For or the step-size remains unchanged.
The step-size is increased if and only if is larger than the expected value
and decreased if it is smaller. For this reason, the step-size update tends to make consecutive steps -conjugate, in that after the adaptation has been successful .
Finally, the covariance matrix is updated, where again the respective evolution path is updated first.
where denotes the transpose and
- is the backward time horizon for the evolution path and larger than one,
- and the indicator function evaluates to one if and only if or, in other words, , which is usually the case,
- makes partly up for the small variance loss in case the indicator is zero,
- is the learning rate for the rank-one update of the covariance matrix and
- is the learning rate for the rank- update of the covariance matrix and must not exceed .
The covariance matrix update tends to increase the likelihood for and for to be sampled from . This completes the iteration step.
The number of candidate samples per iteration, , is not determined a priori and can vary in a wide range. Smaller values, for example , lead to more local search behavior. Larger values, for example with default value , render the search more global. Sometimes the algorithm is repeatedly restarted with increasing by a factor of two for each restart. Besides of setting (or possibly instead, if for example 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
<span id="mwAQU"></span><span class="k" id="mwAQY">function</span><span class="w" id="mwAQc"> </span>xmin<span class="p" id="mwAQg">=</span><span class="nf" id="mwAQk">purecmaes</span><span class="w" id="mwAQo"> </span><span class="c" id="mwAQs">% (mu/mu_w, lambda)-CMA-ES</span> <span class="w" id="mwAQw"> </span><span class="c" id="mwAQ0">% --------- User defined input parameters (need to be edited) ---------</span> <span class="w" id="mwAQ4"> </span><span class="n" id="mwAQ8">strfitnessfct</span><span class="w" id="mwARA"> </span><span class="p" id="mwARE">=</span><span class="w" id="mwARI"> </span><span class="s" id="mwARM">'frosenbrock'</span><span class="p" id="mwARQ">;</span><span class="w" id="mwARU"> </span><span class="c" id="mwARY">% name of objective/fitness function</span> <span class="w" id="mwARc"> </span><span class="n" id="mwARg">N</span><span class="w" id="mwARk"> </span><span class="p" id="mwARo">=</span><span class="w" id="mwARs"> </span><span class="mi" id="mwARw">20</span><span class="p" id="mwAR0">;</span><span class="w" id="mwAR4"> </span><span class="c" id="mwAR8">% number of objective variables/problem dimension</span> <span class="w" id="mwASA"> </span><span class="n" id="mwASE">xmean</span><span class="w" id="mwASI"> </span><span class="p" id="mwASM">=</span><span class="w" id="mwASQ"> </span><span class="nb" id="mwASU">rand</span><span class="p" id="mwASY">(</span><span class="n" id="mwASc">N</span><span class="p" id="mwASg">,</span><span class="mi" id="mwASk">1</span><span class="p" id="mwASo">);</span><span class="w" id="mwASs"> </span><span class="c" id="mwASw">% objective variables initial point</span> <span class="w" id="mwAS0"> </span><span class="n" id="mwAS4">sigma</span><span class="w" id="mwAS8"> </span><span class="p" id="mwATA">=</span><span class="w" id="mwATE"> </span><span class="mf" id="mwATI">0.3</span><span class="p" id="mwATM">;</span><span class="w" id="mwATQ"> </span><span class="c" id="mwATU">% coordinate wise standard deviation (step size)</span> <span class="w" id="mwATY"> </span><span class="n" id="mwATc">stopfitness</span><span class="w" id="mwATg"> </span><span class="p" id="mwATk">=</span><span class="w" id="mwATo"> </span><span class="mf" id="mwATs">1e-10</span><span class="p" id="mwATw">;</span><span class="w" id="mwAT0"> </span><span class="c" id="mwAT4">% stop if fitness < stopfitness (minimization)</span> <span class="w" id="mwAT8"> </span><span class="n" id="mwAUA">stopeval</span><span class="w" id="mwAUE"> </span><span class="p" id="mwAUI">=</span><span class="w" id="mwAUM"> </span><span class="mf" id="mwAUQ">1e3</span><span class="o" id="mwAUU">*</span><span class="n" id="mwAUY">N</span><span class="o" id="mwAUc">^</span><span class="mi" id="mwAUg">2</span><span class="p" id="mwAUk">;</span><span class="w" id="mwAUo"> </span><span class="c" id="mwAUs">% stop after stopeval number of function evaluations</span> <span class="w" id="mwAUw"> </span> <span class="w" id="mwAU0"> </span><span class="c" id="mwAU4">% -------------------- Initialization -------------------------------- </span> <span class="w" id="mwAU8"> </span><span class="c" id="mwAVA">% Strategy parameter setting: Selection </span> <span class="w" id="mwAVE"> </span><span class="n" id="mwAVI">lambda</span><span class="w" id="mwAVM"> </span><span class="p" id="mwAVQ">=</span><span class="w" id="mwAVU"> </span><span class="mi" id="mwAVY">4</span><span class="o" id="mwAVc">+</span><span class="nb" id="mwAVg">floor</span><span class="p" id="mwAVk">(</span><span class="mi" id="mwAVo">3</span><span class="o" id="mwAVs">*</span><span class="nb" id="mwAVw">log</span><span class="p" id="mwAV0">(</span><span class="n" id="mwAV4">N</span><span class="p" id="mwAV8">));</span><span class="w" id="mwAWA"> </span><span class="c" id="mwAWE">% population size, offspring number</span> <span class="w" id="mwAWI"> </span><span class="n" id="mwAWM">mu</span><span class="w" id="mwAWQ"> </span><span class="p" id="mwAWU">=</span><span class="w" id="mwAWY"> </span><span class="n" id="mwAWc">lambda</span><span class="o" id="mwAWg">/</span><span class="mi" id="mwAWk">2</span><span class="p" id="mwAWo">;</span><span class="w" id="mwAWs"> </span><span class="c" id="mwAWw">% number of parents/points for recombination</span> <span class="w" id="mwAW0"> </span><span class="n" id="mwAW4">weights</span><span class="w" id="mwAW8"> </span><span class="p" id="mwAXA">=</span><span class="w" id="mwAXE"> </span><span class="nb" id="mwAXI">log</span><span class="p" id="mwAXM">(</span><span class="n" id="mwAXQ">mu</span><span class="o" id="mwAXU">+</span><span class="mi" id="mwAXY">1</span><span class="o" id="mwAXc">/</span><span class="mi" id="mwAXg">2</span><span class="p" id="mwAXk">)</span><span class="o" id="mwAXo">-</span><span class="nb" id="mwAXs">log</span><span class="p" id="mwAXw">(</span><span class="mi" id="mwAX0">1</span><span class="p" id="mwAX4">:</span><span class="n" id="mwAX8">mu</span><span class="p" id="mwAYA">)</span><span class="o" id="mwAYE">'</span><span class="p" id="mwAYI">;</span><span class="w" id="mwAYM"> </span><span class="c" id="mwAYQ">% muXone array for weighted recombination</span> <span class="w" id="mwAYU"> </span><span class="n" id="mwAYY">mu</span><span class="w" id="mwAYc"> </span><span class="p" id="mwAYg">=</span><span class="w" id="mwAYk"> </span><span class="nb" id="mwAYo">floor</span><span class="p" id="mwAYs">(</span><span class="n" id="mwAYw">mu</span><span class="p" id="mwAY0">);</span><span class="w" id="mwAY4"> </span> <span class="w" id="mwAY8"> </span><span class="n" id="mwAZA">weights</span><span class="w" id="mwAZE"> </span><span class="p" id="mwAZI">=</span><span class="w" id="mwAZM"> </span><span class="n" id="mwAZQ">weights</span><span class="o" id="mwAZU">/</span><span class="nb" id="mwAZY">sum</span><span class="p" id="mwAZc">(</span><span class="n" id="mwAZg">weights</span><span class="p" id="mwAZk">);</span><span class="w" id="mwAZo"> </span><span class="c" id="mwAZs">% normalize recombination weights array</span> <span class="w" id="mwAZw"> </span><span class="n" id="mwAZ0">mueff</span><span class="p" id="mwAZ4">=</span><span class="nb" id="mwAZ8">sum</span><span class="p" id="mwAaA">(</span><span class="n" id="mwAaE">weights</span><span class="p" id="mwAaI">)</span><span class="o" id="mwAaM">^</span><span class="mi" id="mwAaQ">2</span><span class="o" id="mwAaU">/</span><span class="nb" id="mwAaY">sum</span><span class="p" id="mwAac">(</span><span class="n" id="mwAag">weights</span><span class="o" id="mwAak">.^</span><span class="mi" id="mwAao">2</span><span class="p" id="mwAas">);</span><span class="w" id="mwAaw"> </span><span class="c" id="mwAa0">% variance-effectiveness of sum w_i x_i</span> <span class="w" id="mwAa4"> </span><span class="c" id="mwAa8">% Strategy parameter setting: Adaptation</span> <span class="w" id="mwAbA"> </span><span class="n" id="mwAbE">cc</span><span class="w" id="mwAbI"> </span><span class="p" id="mwAbM">=</span><span class="w" id="mwAbQ"> </span><span class="p" id="mwAbU">(</span><span class="mi" id="mwAbY">4</span><span class="o" id="mwAbc">+</span><span class="n" id="mwAbg">mueff</span><span class="o" id="mwAbk">/</span><span class="n" id="mwAbo">N</span><span class="p" id="mwAbs">)</span><span class="w" id="mwAbw"> </span><span class="o" id="mwAb0">/</span><span class="w" id="mwAb4"> </span><span class="p" id="mwAb8">(</span><span class="n" id="mwAcA">N</span><span class="o" id="mwAcE">+</span><span class="mi" id="mwAcI">4</span><span class="w" id="mwAcM"> </span><span class="o" id="mwAcQ">+</span><span class="w" id="mwAcU"> </span><span class="mi" id="mwAcY">2</span><span class="o" id="mwAcc">*</span><span class="n" id="mwAcg">mueff</span><span class="o" id="mwAck">/</span><span class="n" id="mwAco">N</span><span class="p" id="mwAcs">);</span><span class="w" id="mwAcw"> </span><span class="c" id="mwAc0">% time constant for cumulation for C</span> <span class="w" id="mwAc4"> </span><span class="n" id="mwAc8">cs</span><span class="w" id="mwAdA"> </span><span class="p" id="mwAdE">=</span><span class="w" id="mwAdI"> </span><span class="p" id="mwAdM">(</span><span class="n" id="mwAdQ">mueff</span><span class="o" id="mwAdU">+</span><span class="mi" id="mwAdY">2</span><span class="p" id="mwAdc">)</span><span class="w" id="mwAdg"> </span><span class="o" id="mwAdk">/</span><span class="w" id="mwAdo"> </span><span class="p" id="mwAds">(</span><span class="n" id="mwAdw">N</span><span class="o" id="mwAd0">+</span><span class="n" id="mwAd4">mueff</span><span class="o" id="mwAd8">+</span><span class="mi" id="mwAeA">5</span><span class="p" id="mwAeE">);</span><span class="w" id="mwAeI"> </span><span class="c" id="mwAeM">% t-const for cumulation for sigma control</span> <span class="w" id="mwAeQ"> </span><span class="n" id="mwAeU">c1</span><span class="w" id="mwAeY"> </span><span class="p" id="mwAec">=</span><span class="w" id="mwAeg"> </span><span class="mi" id="mwAek">2</span><span class="w" id="mwAeo"> </span><span class="o" id="mwAes">/</span><span class="w" id="mwAew"> </span><span class="p" id="mwAe0">((</span><span class="n" id="mwAe4">N</span><span class="o" id="mwAe8">+</span><span class="mf" id="mwAfA">1.3</span><span class="p" id="mwAfE">)</span><span class="o" id="mwAfI">^</span><span class="mi" id="mwAfM">2</span><span class="o" id="mwAfQ">+</span><span class="n" id="mwAfU">mueff</span><span class="p" id="mwAfY">);</span><span class="w" id="mwAfc"> </span><span class="c" id="mwAfg">% learning rate for rank-one update of C</span> <span class="w" id="mwAfk"> </span><span class="n" id="mwAfo">cmu</span><span class="w" id="mwAfs"> </span><span class="p" id="mwAfw">=</span><span class="w" id="mwAf0"> </span><span class="nb" id="mwAf4">min</span><span class="p" id="mwAf8">(</span><span class="mi" id="mwAgA">1</span><span class="o" id="mwAgE">-</span><span class="n" id="mwAgI">c1</span><span class="p" id="mwAgM">,</span><span class="w" id="mwAgQ"> </span><span class="mi" id="mwAgU">2</span><span class="w" id="mwAgY"> </span><span class="o" id="mwAgc">*</span><span class="w" id="mwAgg"> </span><span class="p" id="mwAgk">(</span><span class="n" id="mwAgo">mueff</span><span class="o" id="mwAgs">-</span><span class="mi" id="mwAgw">2</span><span class="o" id="mwAg0">+</span><span class="mi" id="mwAg4">1</span><span class="o" id="mwAg8">/</span><span class="n" id="mwAhA">mueff</span><span class="p" id="mwAhE">)</span><span class="w" id="mwAhI"> </span><span class="o" id="mwAhM">/</span><span class="w" id="mwAhQ"> </span><span class="p" id="mwAhU">((</span><span class="n" id="mwAhY">N</span><span class="o" id="mwAhc">+</span><span class="mi" id="mwAhg">2</span><span class="p" id="mwAhk">)</span><span class="o" id="mwAho">^</span><span class="mi" id="mwAhs">2</span><span class="o" id="mwAhw">+</span><span class="n" id="mwAh0">mueff</span><span class="p" id="mwAh4">));</span><span class="w" id="mwAh8"> </span><span class="c" id="mwAiA">% and for rank-mu update</span> <span class="w" id="mwAiE"> </span><span class="n" id="mwAiI">damps</span><span class="w" id="mwAiM"> </span><span class="p" id="mwAiQ">=</span><span class="w" id="mwAiU"> </span><span class="mi" id="mwAiY">1</span><span class="w" id="mwAic"> </span><span class="o" id="mwAig">+</span><span class="w" id="mwAik"> </span><span class="mi" id="mwAio">2</span><span class="o" id="mwAis">*</span><span class="nb" id="mwAiw">max</span><span class="p" id="mwAi0">(</span><span class="mi" id="mwAi4">0</span><span class="p" id="mwAi8">,</span><span class="w" id="mwAjA"> </span><span class="nb" id="mwAjE">sqrt</span><span class="p" id="mwAjI">((</span><span class="n" id="mwAjM">mueff</span><span class="o" id="mwAjQ">-</span><span class="mi" id="mwAjU">1</span><span class="p" id="mwAjY">)</span><span class="o" id="mwAjc">/</span><span class="p" id="mwAjg">(</span><span class="n" id="mwAjk">N</span><span class="o" id="mwAjo">+</span><span class="mi" id="mwAjs">1</span><span class="p" id="mwAjw">))</span><span class="o" id="mwAj0">-</span><span class="mi" id="mwAj4">1</span><span class="p" id="mwAj8">)</span><span class="w" id="mwAkA"> </span><span class="o" id="mwAkE">+</span><span class="w" id="mwAkI"> </span><span class="n" id="mwAkM">cs</span><span class="p" id="mwAkQ">;</span><span class="w" id="mwAkU"> </span><span class="c" id="mwAkY">% damping for sigma </span> <span class="w" id="mwAkc"> </span><span class="c" id="mwAkg">% usually close to 1</span> <span class="w" id="mwAkk"> </span><span class="c" id="mwAko">% Initialize dynamic (internal) strategy parameters and constants</span> <span class="w" id="mwAks"> </span><span class="n" id="mwAkw">pc</span><span class="w" id="mwAk0"> </span><span class="p" id="mwAk4">=</span><span class="w" id="mwAk8"> </span><span class="nb" id="mwAlA">zeros</span><span class="p" id="mwAlE">(</span><span class="n" id="mwAlI">N</span><span class="p" id="mwAlM">,</span><span class="mi" id="mwAlQ">1</span><span class="p" id="mwAlU">);</span><span class="w" id="mwAlY"> </span><span class="n" id="mwAlc">ps</span><span class="w" id="mwAlg"> </span><span class="p" id="mwAlk">=</span><span class="w" id="mwAlo"> </span><span class="nb" id="mwAls">zeros</span><span class="p" id="mwAlw">(</span><span class="n" id="mwAl0">N</span><span class="p" id="mwAl4">,</span><span class="mi" id="mwAl8">1</span><span class="p" id="mwAmA">);</span><span class="w" id="mwAmE"> </span><span class="c" id="mwAmI">% evolution paths for C and sigma</span> <span class="w" id="mwAmM"> </span><span class="n" id="mwAmQ">B</span><span class="w" id="mwAmU"> </span><span class="p" id="mwAmY">=</span><span class="w" id="mwAmc"> </span><span class="nb" id="mwAmg">eye</span><span class="p" id="mwAmk">(</span><span class="n" id="mwAmo">N</span><span class="p" id="mwAms">,</span><span class="n" id="mwAmw">N</span><span class="p" id="mwAm0">);</span><span class="w" id="mwAm4"> </span><span class="c" id="mwAm8">% B defines the coordinate system</span> <span class="w" id="mwAnA"> </span><span class="n" id="mwAnE">D</span><span class="w" id="mwAnI"> </span><span class="p" id="mwAnM">=</span><span class="w" id="mwAnQ"> </span><span class="nb" id="mwAnU">ones</span><span class="p" id="mwAnY">(</span><span class="n" id="mwAnc">N</span><span class="p" id="mwAng">,</span><span class="mi" id="mwAnk">1</span><span class="p" id="mwAno">);</span><span class="w" id="mwAns"> </span><span class="c" id="mwAnw">% diagonal D defines the scaling</span> <span class="w" id="mwAn0"> </span><span class="n" id="mwAn4">C</span><span class="w" id="mwAn8"> </span><span class="p" id="mwAoA">=</span><span class="w" id="mwAoE"> </span><span class="n" id="mwAoI">B</span><span class="w" id="mwAoM"> </span><span class="o" id="mwAoQ">*</span><span class="w" id="mwAoU"> </span><span class="nb" id="mwAoY">diag</span><span class="p" id="mwAoc">(</span><span class="n" id="mwAog">D</span><span class="o" id="mwAok">.^</span><span class="mi" id="mwAoo">2</span><span class="p" id="mwAos">)</span><span class="w" id="mwAow"> </span><span class="o" id="mwAo0">*</span><span class="w" id="mwAo4"> </span><span class="n" id="mwAo8">B</span><span class="o" id="mwApA">'</span><span class="p" id="mwApE">;</span><span class="w" id="mwApI"> </span><span class="c" id="mwApM">% covariance matrix C</span> <span class="w" id="mwApQ"> </span><span class="n" id="mwApU">invsqrtC</span><span class="w" id="mwApY"> </span><span class="p" id="mwApc">=</span><span class="w" id="mwApg"> </span><span class="n" id="mwApk">B</span><span class="w" id="mwApo"> </span><span class="o" id="mwAps">*</span><span class="w" id="mwApw"> </span><span class="nb" id="mwAp0">diag</span><span class="p" id="mwAp4">(</span><span class="n" id="mwAp8">D</span><span class="o" id="mwAqA">.^-</span><span class="mi" id="mwAqE">1</span><span class="p" id="mwAqI">)</span><span class="w" id="mwAqM"> </span><span class="o" id="mwAqQ">*</span><span class="w" id="mwAqU"> </span><span class="n" id="mwAqY">B</span><span class="o" id="mwAqc">'</span><span class="p" id="mwAqg">;</span><span class="w" id="mwAqk"> </span><span class="c" id="mwAqo">% C^-1/2 </span> <span class="w" id="mwAqs"> </span><span class="n" id="mwAqw">eigeneval</span><span class="w" id="mwAq0"> </span><span class="p" id="mwAq4">=</span><span class="w" id="mwAq8"> </span><span class="mi" id="mwArA">0</span><span class="p" id="mwArE">;</span><span class="w" id="mwArI"> </span><span class="c" id="mwArM">% track update of B and D</span> <span class="w" id="mwArQ"> </span><span class="n" id="mwArU">chiN</span><span class="p" id="mwArY">=</span><span class="n" id="mwArc">N</span><span class="o" id="mwArg">^</span><span class="mf" id="mwArk">0.5</span><span class="o" id="mwAro">*</span><span class="p" id="mwArs">(</span><span class="mi" id="mwArw">1</span><span class="o" id="mwAr0">-</span><span class="mi" id="mwAr4">1</span><span class="o" id="mwAr8">/</span><span class="p" id="mwAsA">(</span><span class="mi" id="mwAsE">4</span><span class="o" id="mwAsI">*</span><span class="n" id="mwAsM">N</span><span class="p" id="mwAsQ">)</span><span class="o" id="mwAsU">+</span><span class="mi" id="mwAsY">1</span><span class="o" id="mwAsc">/</span><span class="p" id="mwAsg">(</span><span class="mi" id="mwAsk">21</span><span class="o" id="mwAso">*</span><span class="n" id="mwAss">N</span><span class="o" id="mwAsw">^</span><span class="mi" id="mwAs0">2</span><span class="p" id="mwAs4">));</span><span class="w" id="mwAs8"> </span><span class="c" id="mwAtA">% expectation of </span> <span class="w" id="mwAtE"> </span><span class="c" id="mwAtI">% ||N(0,I)|| == norm(randn(N,1)) </span> <span class="w" id="mwAtM"> </span><span class="c" id="mwAtQ">% -------------------- Generation Loop --------------------------------</span> <span class="w" id="mwAtU"> </span><span class="n" id="mwAtY">counteval</span><span class="w" id="mwAtc"> </span><span class="p" id="mwAtg">=</span><span class="w" id="mwAtk"> </span><span class="mi" id="mwAto">0</span><span class="p" id="mwAts">;</span><span class="w" id="mwAtw"> </span><span class="c" id="mwAt0">% the next 40 lines contain the 20 lines of interesting code </span> <span class="w" id="mwAt4"> </span><span class="k" id="mwAt8">while</span><span class="w" id="mwAuA"> </span><span class="n" id="mwAuE">counteval</span><span class="w" id="mwAuI"> </span><span class="o" id="mwAuM"><</span><span class="w" id="mwAuQ"> </span><span class="n" id="mwAuU">stopeval</span> <span class="w" id="mwAuY"> </span> <span class="w" id="mwAuc"> </span><span class="c" id="mwAug">% Generate and evaluate lambda offspring</span> <span class="w" id="mwAuk"> </span><span class="k" id="mwAuo">for</span><span class="w" id="mwAus"> </span><span class="n" id="mwAuw">k</span><span class="p" id="mwAu0">=</span><span class="mi" id="mwAu4">1</span><span class="p" id="mwAu8">:</span><span class="n" id="mwAvA">lambda</span> <span class="w" id="mwAvE"> </span><span class="n" id="mwAvI">arx</span><span class="p" id="mwAvM">(:,</span><span class="n" id="mwAvQ">k</span><span class="p" id="mwAvU">)</span><span class="w" id="mwAvY"> </span><span class="p" id="mwAvc">=</span><span class="w" id="mwAvg"> </span><span class="n" id="mwAvk">xmean</span><span class="w" id="mwAvo"> </span><span class="o" id="mwAvs">+</span><span class="w" id="mwAvw"> </span><span class="n" id="mwAv0">sigma</span><span class="w" id="mwAv4"> </span><span class="o" id="mwAv8">*</span><span class="w" id="mwAwA"> </span><span class="n" id="mwAwE">B</span><span class="w" id="mwAwI"> </span><span class="o" id="mwAwM">*</span><span class="w" id="mwAwQ"> </span><span class="p" id="mwAwU">(</span><span class="n" id="mwAwY">D</span><span class="w" id="mwAwc"> </span><span class="o" id="mwAwg">.*</span><span class="w" id="mwAwk"> </span><span class="nb" id="mwAwo">randn</span><span class="p" id="mwAws">(</span><span class="n" id="mwAww">N</span><span class="p" id="mwAw0">,</span><span class="mi" id="mwAw4">1</span><span class="p" id="mwAw8">));</span><span class="w" id="mwAxA"> </span><span class="c" id="mwAxE">% m + sig * Normal(0,C) </span> <span class="w" id="mwAxI"> </span><span class="n" id="mwAxM">arfitness</span><span class="p" id="mwAxQ">(</span><span class="n" id="mwAxU">k</span><span class="p" id="mwAxY">)</span><span class="w" id="mwAxc"> </span><span class="p" id="mwAxg">=</span><span class="w" id="mwAxk"> </span><span class="nb" id="mwAxo">feval</span><span class="p" id="mwAxs">(</span><span class="n" id="mwAxw">strfitnessfct</span><span class="p" id="mwAx0">,</span><span class="w" id="mwAx4"> </span><span class="n" id="mwAx8">arx</span><span class="p" id="mwAyA">(:,</span><span class="n" id="mwAyE">k</span><span class="p" id="mwAyI">));</span><span class="w" id="mwAyM"> </span><span class="c" id="mwAyQ">% objective function call</span> <span class="w" id="mwAyU"> </span><span class="n" id="mwAyY">counteval</span><span class="w" id="mwAyc"> </span><span class="p" id="mwAyg">=</span><span class="w" id="mwAyk"> </span><span class="n" id="mwAyo">counteval</span><span class="o" id="mwAys">+</span><span class="mi" id="mwAyw">1</span><span class="p" id="mwAy0">;</span> <span class="w" id="mwAy4"> </span><span class="k" id="mwAy8">end</span> <span class="w" id="mwAzA"> </span> <span class="w" id="mwAzE"> </span><span class="c" id="mwAzI">% Sort by fitness and compute weighted mean into xmean</span> <span class="w" id="mwAzM"> </span><span class="p" id="mwAzQ">[</span><span class="n" id="mwAzU">arfitness</span><span class="p" id="mwAzY">,</span><span class="w" id="mwAzc"> </span><span class="n" id="mwAzg">arindex</span><span class="p" id="mwAzk">]</span><span class="w" id="mwAzo"> </span><span class="p" id="mwAzs">=</span><span class="w" id="mwAzw"> </span><span class="nb" id="mwAz0">sort</span><span class="p" id="mwAz4">(</span><span class="n" id="mwAz8">arfitness</span><span class="p" id="mwA0A">);</span><span class="w" id="mwA0E"> </span><span class="c" id="mwA0I">% minimization</span> <span class="w" id="mwA0M"> </span><span class="n" id="mwA0Q">xold</span><span class="w" id="mwA0U"> </span><span class="p" id="mwA0Y">=</span><span class="w" id="mwA0c"> </span><span class="n" id="mwA0g">xmean</span><span class="p" id="mwA0k">;</span> <span class="w" id="mwA0o"> </span><span class="n" id="mwA0s">xmean</span><span class="w" id="mwA0w"> </span><span class="p" id="mwA00">=</span><span class="w" id="mwA04"> </span><span class="n" id="mwA08">arx</span><span class="p" id="mwA1A">(:,</span><span class="n" id="mwA1E">arindex</span><span class="p" id="mwA1I">(</span><span class="mi" id="mwA1M">1</span><span class="p" id="mwA1Q">:</span><span class="n" id="mwA1U">mu</span><span class="p" id="mwA1Y">))</span><span class="o" id="mwA1c">*</span><span class="n" id="mwA1g">weights</span><span class="p" id="mwA1k">;</span><span class="w" id="mwA1o"> </span><span class="c" id="mwA1s">% recombination, new mean value</span> <span class="w" id="mwA1w"> </span> <span class="w" id="mwA10"> </span><span class="c" id="mwA14">% Cumulation: Update evolution paths</span> <span class="w" id="mwA18"> </span><span class="n" id="mwA2A">ps</span><span class="w" id="mwA2E"> </span><span class="p" id="mwA2I">=</span><span class="w" id="mwA2M"> </span><span class="p" id="mwA2Q">(</span><span class="mi" id="mwA2U">1</span><span class="o" id="mwA2Y">-</span><span class="n" id="mwA2c">cs</span><span class="p" id="mwA2g">)</span><span class="o" id="mwA2k">*</span><span class="n" id="mwA2o">ps</span><span class="w" id="mwA2s"> </span><span class="k" id="mwA2w">...</span><span class="c" id="mwA20"> </span> <span class="w" id="mwA24"> </span><span class="o" id="mwA28">+</span><span class="w" id="mwA3A"> </span><span class="nb" id="mwA3E">sqrt</span><span class="p" id="mwA3I">(</span><span class="n" id="mwA3M">cs</span><span class="o" id="mwA3Q">*</span><span class="p" id="mwA3U">(</span><span class="mi" id="mwA3Y">2</span><span class="o" id="mwA3c">-</span><span class="n" id="mwA3g">cs</span><span class="p" id="mwA3k">)</span><span class="o" id="mwA3o">*</span><span class="n" id="mwA3s">mueff</span><span class="p" id="mwA3w">)</span><span class="w" id="mwA30"> </span><span class="o" id="mwA34">*</span><span class="w" id="mwA38"> </span><span class="n" id="mwA4A">invsqrtC</span><span class="w" id="mwA4E"> </span><span class="o" id="mwA4I">*</span><span class="w" id="mwA4M"> </span><span class="p" id="mwA4Q">(</span><span class="n" id="mwA4U">xmean</span><span class="o" id="mwA4Y">-</span><span class="n" id="mwA4c">xold</span><span class="p" id="mwA4g">)</span><span class="w" id="mwA4k"> </span><span class="o" id="mwA4o">/</span><span class="w" id="mwA4s"> </span><span class="n" id="mwA4w">sigma</span><span class="p" id="mwA40">;</span><span class="w" id="mwA44"> </span> <span class="w" id="mwA48"> </span><span class="n" id="mwA5A">hsig</span><span class="w" id="mwA5E"> </span><span class="p" id="mwA5I">=</span><span class="w" id="mwA5M"> </span><span class="nb" id="mwA5Q">norm</span><span class="p" id="mwA5U">(</span><span class="n" id="mwA5Y">ps</span><span class="p" id="mwA5c">)</span><span class="o" id="mwA5g">/</span><span class="nb" id="mwA5k">sqrt</span><span class="p" id="mwA5o">(</span><span class="mi" id="mwA5s">1</span><span class="o" id="mwA5w">-</span><span class="p" id="mwA50">(</span><span class="mi" id="mwA54">1</span><span class="o" id="mwA58">-</span><span class="n" id="mwA6A">cs</span><span class="p" id="mwA6E">)</span><span class="o" id="mwA6I">^</span><span class="p" id="mwA6M">(</span><span class="mi" id="mwA6Q">2</span><span class="o" id="mwA6U">*</span><span class="n" id="mwA6Y">counteval</span><span class="o" id="mwA6c">/</span><span class="n" id="mwA6g">lambda</span><span class="p" id="mwA6k">))</span><span class="o" id="mwA6o">/</span><span class="n" id="mwA6s">chiN</span><span class="w" id="mwA6w"> </span><span class="o" id="mwA60"><</span><span class="w" id="mwA64"> </span><span class="mf" id="mwA68">1.4</span><span class="w" id="mwA7A"> </span><span class="o" id="mwA7E">+</span><span class="w" id="mwA7I"> </span><span class="mi" id="mwA7M">2</span><span class="o" id="mwA7Q">/</span><span class="p" id="mwA7U">(</span><span class="n" id="mwA7Y">N</span><span class="o" id="mwA7c">+</span><span class="mi" id="mwA7g">1</span><span class="p" id="mwA7k">);</span> <span class="w" id="mwA7o"> </span><span class="n" id="mwA7s">pc</span><span class="w" id="mwA7w"> </span><span class="p" id="mwA70">=</span><span class="w" id="mwA74"> </span><span class="p" id="mwA78">(</span><span class="mi" id="mwA8A">1</span><span class="o" id="mwA8E">-</span><span class="n" id="mwA8I">cc</span><span class="p" id="mwA8M">)</span><span class="o" id="mwA8Q">*</span><span class="n" id="mwA8U">pc</span><span class="w" id="mwA8Y"> </span><span class="k" id="mwA8c">...</span> <span class="w" id="mwA8g"> </span><span class="o" id="mwA8k">+</span><span class="w" id="mwA8o"> </span><span class="n" id="mwA8s">hsig</span><span class="w" id="mwA8w"> </span><span class="o" id="mwA80">*</span><span class="w" id="mwA84"> </span><span class="nb" id="mwA88">sqrt</span><span class="p" id="mwA9A">(</span><span class="n" id="mwA9E">cc</span><span class="o" id="mwA9I">*</span><span class="p" id="mwA9M">(</span><span class="mi" id="mwA9Q">2</span><span class="o" id="mwA9U">-</span><span class="n" id="mwA9Y">cc</span><span class="p" id="mwA9c">)</span><span class="o" id="mwA9g">*</span><span class="n" id="mwA9k">mueff</span><span class="p" id="mwA9o">)</span><span class="w" id="mwA9s"> </span><span class="o" id="mwA9w">*</span><span class="w" id="mwA90"> </span><span class="p" id="mwA94">(</span><span class="n" id="mwA98">xmean</span><span class="o" id="mwA-A">-</span><span class="n" id="mwA-E">xold</span><span class="p" id="mwA-I">)</span><span class="w" id="mwA-M"> </span><span class="o" id="mwA-Q">/</span><span class="w" id="mwA-U"> </span><span class="n" id="mwA-Y">sigma</span><span class="p" id="mwA-c">;</span> <span class="w" id="mwA-g"> </span><span class="c" id="mwA-k">% Adapt covariance matrix C</span> <span class="w" id="mwA-o"> </span><span class="n" id="mwA-s">artmp</span><span class="w" id="mwA-w"> </span><span class="p" id="mwA-0">=</span><span class="w" id="mwA-4"> </span><span class="p" id="mwA-8">(</span><span class="mi" id="mwA_A">1</span><span class="o" id="mwA_E">/</span><span class="n" id="mwA_I">sigma</span><span class="p" id="mwA_M">)</span><span class="w" id="mwA_Q"> </span><span class="o" id="mwA_U">*</span><span class="w" id="mwA_Y"> </span><span class="p" id="mwA_c">(</span><span class="n" id="mwA_g">arx</span><span class="p" id="mwA_k">(:,</span><span class="n" id="mwA_o">arindex</span><span class="p" id="mwA_s">(</span><span class="mi" id="mwA_w">1</span><span class="p" id="mwA_0">:</span><span class="n" id="mwA_4">mu</span><span class="p" id="mwA_8">))</span><span class="o" id="mwBAA">-</span><span class="nb" id="mwBAE">repmat</span><span class="p" id="mwBAI">(</span><span class="n" id="mwBAM">xold</span><span class="p" id="mwBAQ">,</span><span class="mi" id="mwBAU">1</span><span class="p" id="mwBAY">,</span><span class="n" id="mwBAc">mu</span><span class="p" id="mwBAg">));</span> <span class="w" id="mwBAk"> </span><span class="n" id="mwBAo">C</span><span class="w" id="mwBAs"> </span><span class="p" id="mwBAw">=</span><span class="w" id="mwBA0"> </span><span class="p" id="mwBA4">(</span><span class="mi" id="mwBA8">1</span><span class="o" id="mwBBA">-</span><span class="n" id="mwBBE">c1</span><span class="o" id="mwBBI">-</span><span class="n" id="mwBBM">cmu</span><span class="p" id="mwBBQ">)</span><span class="w" id="mwBBU"> </span><span class="o" id="mwBBY">*</span><span class="w" id="mwBBc"> </span><span class="n" id="mwBBg">C</span><span class="w" id="mwBBk"> </span><span class="k" id="mwBBo">...</span><span class="c" id="mwBBs"> % regard old matrix </span> <span class="w" id="mwBBw"> </span><span class="o" id="mwBB0">+</span><span class="w" id="mwBB4"> </span><span class="n" id="mwBB8">c1</span><span class="w" id="mwBCA"> </span><span class="o" id="mwBCE">*</span><span class="w" id="mwBCI"> </span><span class="p" id="mwBCM">(</span><span class="n" id="mwBCQ">pc</span><span class="o" id="mwBCU">*</span><span class="n" id="mwBCY">pc</span><span class="o" id="mwBCc">'</span><span class="w" id="mwBCg"> </span><span class="k" id="mwBCk">...</span><span class="c" id="mwBCo"> % plus rank one update</span> <span class="w" id="mwBCs"> </span><span class="o" id="mwBCw">+</span><span class="w" id="mwBC0"> </span><span class="p" id="mwBC4">(</span><span class="mi" id="mwBC8">1</span><span class="o" id="mwBDA">-</span><span class="n" id="mwBDE">hsig</span><span class="p" id="mwBDI">)</span><span class="w" id="mwBDM"> </span><span class="o" id="mwBDQ">*</span><span class="w" id="mwBDU"> </span><span class="n" id="mwBDY">cc</span><span class="o" id="mwBDc">*</span><span class="p" id="mwBDg">(</span><span class="mi" id="mwBDk">2</span><span class="o" id="mwBDo">-</span><span class="n" id="mwBDs">cc</span><span class="p" id="mwBDw">)</span><span class="w" id="mwBD0"> </span><span class="o" id="mwBD4">*</span><span class="w" id="mwBD8"> </span><span class="n" id="mwBEA">C</span><span class="p" id="mwBEE">)</span><span class="w" id="mwBEI"> </span><span class="k" id="mwBEM">...</span><span class="c" id="mwBEQ"> % minor correction if hsig==0</span> <span class="w" id="mwBEU"> </span><span class="o" id="mwBEY">+</span><span class="w" id="mwBEc"> </span><span class="n" id="mwBEg">cmu</span><span class="w" id="mwBEk"> </span><span class="o" id="mwBEo">*</span><span class="w" id="mwBEs"> </span><span class="n" id="mwBEw">artmp</span><span class="w" id="mwBE0"> </span><span class="o" id="mwBE4">*</span><span class="w" id="mwBE8"> </span><span class="nb" id="mwBFA">diag</span><span class="p" id="mwBFE">(</span><span class="n" id="mwBFI">weights</span><span class="p" id="mwBFM">)</span><span class="w" id="mwBFQ"> </span><span class="o" id="mwBFU">*</span><span class="w" id="mwBFY"> </span><span class="n" id="mwBFc">artmp</span><span class="o" id="mwBFg">'</span><span class="p" id="mwBFk">;</span><span class="w" id="mwBFo"> </span><span class="c" id="mwBFs">% plus rank mu update</span> <span class="w" id="mwBFw"> </span><span class="c" id="mwBF0">% Adapt step size sigma</span> <span class="w" id="mwBF4"> </span><span class="n" id="mwBF8">sigma</span><span class="w" id="mwBGA"> </span><span class="p" id="mwBGE">=</span><span class="w" id="mwBGI"> </span><span class="n" id="mwBGM">sigma</span><span class="w" id="mwBGQ"> </span><span class="o" id="mwBGU">*</span><span class="w" id="mwBGY"> </span><span class="nb" id="mwBGc">exp</span><span class="p" id="mwBGg">((</span><span class="n" id="mwBGk">cs</span><span class="o" id="mwBGo">/</span><span class="n" id="mwBGs">damps</span><span class="p" id="mwBGw">)</span><span class="o" id="mwBG0">*</span><span class="p" id="mwBG4">(</span><span class="nb" id="mwBG8">norm</span><span class="p" id="mwBHA">(</span><span class="n" id="mwBHE">ps</span><span class="p" id="mwBHI">)</span><span class="o" id="mwBHM">/</span><span class="n" id="mwBHQ">chiN</span><span class="w" id="mwBHU"> </span><span class="o" id="mwBHY">-</span><span class="w" id="mwBHc"> </span><span class="mi" id="mwBHg">1</span><span class="p" id="mwBHk">));</span><span class="w" id="mwBHo"> </span> <span class="w" id="mwBHs"> </span> <span class="w" id="mwBHw"> </span><span class="c" id="mwBH0">% Decomposition of C into B*diag(D.^2)*B' (diagonalization)</span> <span class="w" id="mwBH4"> </span><span class="k" id="mwBH8">if</span><span class="w" id="mwBIA"> </span><span class="n" id="mwBIE">counteval</span><span class="w" id="mwBII"> </span><span class="o" id="mwBIM">-</span><span class="w" id="mwBIQ"> </span><span class="n" id="mwBIU">eigeneval</span><span class="w" id="mwBIY"> </span><span class="o" id="mwBIc">></span><span class="w" id="mwBIg"> </span><span class="n" id="mwBIk">lambda</span><span class="o" id="mwBIo">/</span><span class="p" id="mwBIs">(</span><span class="n" id="mwBIw">c1</span><span class="o" id="mwBI0">+</span><span class="n" id="mwBI4">cmu</span><span class="p" id="mwBI8">)</span><span class="o" id="mwBJA">/</span><span class="n" id="mwBJE">N</span><span class="o" id="mwBJI">/</span><span class="mi" id="mwBJM">10</span><span class="w" id="mwBJQ"> </span><span class="c" id="mwBJU">% to achieve O(N^2)</span> <span class="w" id="mwBJY"> </span><span class="n" id="mwBJc">eigeneval</span><span class="w" id="mwBJg"> </span><span class="p" id="mwBJk">=</span><span class="w" id="mwBJo"> </span><span class="n" id="mwBJs">counteval</span><span class="p" id="mwBJw">;</span> <span class="w" id="mwBJ0"> </span><span class="n" id="mwBJ4">C</span><span class="w" id="mwBJ8"> </span><span class="p" id="mwBKA">=</span><span class="w" id="mwBKE"> </span><span class="nb" id="mwBKI">triu</span><span class="p" id="mwBKM">(</span><span class="n" id="mwBKQ">C</span><span class="p" id="mwBKU">)</span><span class="w" id="mwBKY"> </span><span class="o" id="mwBKc">+</span><span class="w" id="mwBKg"> </span><span class="nb" id="mwBKk">triu</span><span class="p" id="mwBKo">(</span><span class="n" id="mwBKs">C</span><span class="p" id="mwBKw">,</span><span class="mi" id="mwBK0">1</span><span class="p" id="mwBK4">)</span><span class="o" id="mwBK8">'</span><span class="p" id="mwBLA">;</span><span class="w" id="mwBLE"> </span><span class="c" id="mwBLI">% enforce symmetry</span> <span class="w" id="mwBLM"> </span><span class="p" id="mwBLQ">[</span><span class="n" id="mwBLU">B</span><span class="p" id="mwBLY">,</span><span class="n" id="mwBLc">D</span><span class="p" id="mwBLg">]</span><span class="w" id="mwBLk"> </span><span class="p" id="mwBLo">=</span><span class="w" id="mwBLs"> </span><span class="nb" id="mwBLw">eig</span><span class="p" id="mwBL0">(</span><span class="n" id="mwBL4">C</span><span class="p" id="mwBL8">);</span><span class="w" id="mwBMA"> </span><span class="c" id="mwBME">% eigen decomposition, B==normalized eigenvectors</span> <span class="w" id="mwBMI"> </span><span class="n" id="mwBMM">D</span><span class="w" id="mwBMQ"> </span><span class="p" id="mwBMU">=</span><span class="w" id="mwBMY"> </span><span class="nb" id="mwBMc">sqrt</span><span class="p" id="mwBMg">(</span><span class="nb" id="mwBMk">diag</span><span class="p" id="mwBMo">(</span><span class="n" id="mwBMs">D</span><span class="p" id="mwBMw">));</span><span class="w" id="mwBM0"> </span><span class="c" id="mwBM4">% D is a vector of standard deviations now</span> <span class="w" id="mwBM8"> </span><span class="n" id="mwBNA">invsqrtC</span><span class="w" id="mwBNE"> </span><span class="p" id="mwBNI">=</span><span class="w" id="mwBNM"> </span><span class="n" id="mwBNQ">B</span><span class="w" id="mwBNU"> </span><span class="o" id="mwBNY">*</span><span class="w" id="mwBNc"> </span><span class="nb" id="mwBNg">diag</span><span class="p" id="mwBNk">(</span><span class="n" id="mwBNo">D</span><span class="o" id="mwBNs">.^-</span><span class="mi" id="mwBNw">1</span><span class="p" id="mwBN0">)</span><span class="w" id="mwBN4"> </span><span class="o" id="mwBN8">*</span><span class="w" id="mwBOA"> </span><span class="n" id="mwBOE">B</span><span class="o" id="mwBOI">'</span><span class="p" id="mwBOM">;</span> <span class="w" id="mwBOQ"> </span><span class="k" id="mwBOU">end</span> <span class="w" id="mwBOY"> </span> <span class="w" id="mwBOc"> </span><span class="c" id="mwBOg">% Break, if fitness is good enough or condition exceeds 1e14, better termination methods are advisable </span> <span class="w" id="mwBOk"> </span><span class="k" id="mwBOo">if</span><span class="w" id="mwBOs"> </span><span class="n" id="mwBOw">arfitness</span><span class="p" id="mwBO0">(</span><span class="mi" id="mwBO4">1</span><span class="p" id="mwBO8">)</span><span class="w" id="mwBPA"> </span><span class="o" id="mwBPE"><=</span><span class="w" id="mwBPI"> </span><span class="n" id="mwBPM">stopfitness</span><span class="w" id="mwBPQ"> </span><span class="o" id="mwBPU">||</span><span class="w" id="mwBPY"> </span><span class="nb" id="mwBPc">max</span><span class="p" id="mwBPg">(</span><span class="n" id="mwBPk">D</span><span class="p" id="mwBPo">)</span><span class="w" id="mwBPs"> </span><span class="o" id="mwBPw">></span><span class="w" id="mwBP0"> </span><span class="mf" id="mwBP4">1e7</span><span class="w" id="mwBP8"> </span><span class="o" id="mwBQA">*</span><span class="w" id="mwBQE"> </span><span class="nb" id="mwBQI">min</span><span class="p" id="mwBQM">(</span><span class="n" id="mwBQQ">D</span><span class="p" id="mwBQU">)</span> <span class="w" id="mwBQY"> </span><span class="k" id="mwBQc">break</span><span class="p" id="mwBQg">;</span> <span class="w" id="mwBQk"> </span><span class="k" id="mwBQo">end</span> <span class="w" id="mwBQs"> </span><span class="k" id="mwBQw">end</span><span class="w" id="mwBQ0"> </span><span class="c" id="mwBQ4">% while, end generation loop</span> <span class="w" id="mwBQ8"> </span><span class="n" id="mwBRA">xmin</span><span class="w" id="mwBRE"> </span><span class="p" id="mwBRI">=</span><span class="w" id="mwBRM"> </span><span class="n" id="mwBRQ">arx</span><span class="p" id="mwBRU">(:,</span><span class="w" id="mwBRY"> </span><span class="n" id="mwBRc">arindex</span><span class="p" id="mwBRg">(</span><span class="mi" id="mwBRk">1</span><span class="p" id="mwBRo">));</span><span class="w" id="mwBRs"> </span><span class="c" id="mwBRw">% Return best point of last iteration.</span> <span class="w" id="mwBR0"> </span><span class="c" id="mwBR4">% Notice that xmean is expected to be even</span> <span class="w" id="mwBR8"> </span><span class="c" id="mwBSA">% better.</span> <span class="k" id="mwBSE">end</span> <span class="c" id="mwBSI">% --------------------------------------------------------------- </span> <span class="k" id="mwBSM">function</span><span class="w" id="mwBSQ"> </span>f<span class="p" id="mwBSU">=</span><span class="nf" id="mwBSY">frosenbrock</span><span class="p" id="mwBSc">(</span>x<span class="p" id="mwBSg">)</span> <span class="w" id="mwBSk"> </span><span class="k" id="mwBSo">if</span><span class="w" id="mwBSs"> </span><span class="nb" id="mwBSw">size</span><span class="p" id="mwBS0">(</span><span class="n" id="mwBS4">x</span><span class="p" id="mwBS8">,</span><span class="mi" id="mwBTA">1</span><span class="p" id="mwBTE">)</span><span class="w" id="mwBTI"> </span><span class="o" id="mwBTM"><</span><span class="w" id="mwBTQ"> </span><span class="mi" id="mwBTU">2</span><span class="w" id="mwBTY"> </span><span class="nb" id="mwBTc">error</span><span class="p" id="mwBTg">(</span><span class="s" id="mwBTk">'dimension must be greater one'</span><span class="p" id="mwBTo">);</span><span class="w" id="mwBTs"> </span><span class="k" id="mwBTw">end</span> <span class="w" id="mwBT0"> </span><span class="n" id="mwBT4">f</span><span class="w" id="mwBT8"> </span><span class="p" id="mwBUA">=</span><span class="w" id="mwBUE"> </span><span class="mi" id="mwBUI">100</span><span class="o" id="mwBUM">*</span><span class="nb" id="mwBUQ">sum</span><span class="p" id="mwBUU">((</span><span class="n" id="mwBUY">x</span><span class="p" id="mwBUc">(</span><span class="mi" id="mwBUg">1</span><span class="p" id="mwBUk">:</span><span class="k" id="mwBUo">end</span><span class="o" id="mwBUs">-</span><span class="mi" id="mwBUw">1</span><span class="p" id="mwBU0">)</span><span class="o" id="mwBU4">.^</span><span class="mi" id="mwBU8">2</span><span class="w" id="mwBVA"> </span><span class="o" id="mwBVE">-</span><span class="w" id="mwBVI"> </span><span class="n" id="mwBVM">x</span><span class="p" id="mwBVQ">(</span><span class="mi" id="mwBVU">2</span><span class="p" id="mwBVY">:</span><span class="k" id="mwBVc">end</span><span class="p" id="mwBVg">))</span><span class="o" id="mwBVk">.^</span><span class="mi" id="mwBVo">2</span><span class="p" id="mwBVs">)</span><span class="w" id="mwBVw"> </span><span class="o" id="mwBV0">+</span><span class="w" id="mwBV4"> </span><span class="nb" id="mwBV8">sum</span><span class="p" id="mwBWA">((</span><span class="n" id="mwBWE">x</span><span class="p" id="mwBWI">(</span><span class="mi" id="mwBWM">1</span><span class="p" id="mwBWQ">:</span><span class="k" id="mwBWU">end</span><span class="o" id="mwBWY">-</span><span class="mi" id="mwBWc">1</span><span class="p" id="mwBWg">)</span><span class="o" id="mwBWk">-</span><span class="mi" id="mwBWo">1</span><span class="p" id="mwBWs">)</span><span class="o" id="mwBWw">.^</span><span class="mi" id="mwBW0">2</span><span class="p" id="mwBW4">);</span> <span class="k" id="mwBW8">end</span>
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 , 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
the covariance matrix adapts to the inverse of the Hessian matrix , up to a scalar factor and small random fluctuations. More general, also on the function , where is strictly increasing and therefore order preserving, the covariance matrix adapts to , up to a scalar factor and small random fluctuations. For selection ratio (and hence population size ), the selected solutions yield an empirical covariance matrix reflective of the inverse-Hessian even in evolution strategies without adaptation of the covariance matrix. This result has been proven for on a static model, relying on the quadratic approximation.
Maximum-likelihood updates
The update equations for mean and covariance matrix maximize a likelihood while resembling an expectation–maximization algorithm. The update of the mean vector maximizes a log-likelihood, such that
where
denotes the log-likelihood of from a multivariate normal distribution with mean and any positive definite covariance matrix . To see that is independent of remark first that this is the case for any diagonal matrix , because the coordinate-wise maximizer is independent of a scaling factor. Then, rotation of the data points or choosing non-diagonal are equivalent.
The rank- update of the covariance matrix, that is, the right most summand in the update equation of , maximizes a log-likelihood in that
for (otherwise is singular, but substantially the same result holds for ). Here, denotes the likelihood of from a multivariate normal distribution with zero mean and covariance matrix . Therefore, for and , 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. and Glasmachers et al. 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 (to be minimized), where the expectation is taken under the sample distribution. With the parameter setting of and , i.e. without step-size control and rank-one update, CMA-ES can thus be viewed as an instantiation of Natural Evolution Strategies (NES). 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 can be expressed as
where depends on the parameter vector . The so-called score function, , indicates the relative sensitivity of p w.r.t. θ, and the expectation is taken with respect to the distribution p. The natural gradient of , complying with the Fisher information metric (an informational distance measure between probability distributions and the curvature of the relative entropy), now reads
where the Fisher information matrix is the expectation of the Hessian of −lnp and renders the expression independent of the chosen parameterization. Combining the previous equalities we get
A Monte Carlo approximation of the latter expectation takes the average over λ samples from p
where the notation from above is used and therefore are monotonically decreasing in .
Ollivier et al. finally found a rigorous derivation for the weights, , as they are defined in the CMA-ES. The weights are an asymptotically consistent estimator of the CDF of at the points of the th order statistic , as defined above, where , composed with a fixed monotonically decreasing transformation , that is,
These weights make the algorithm insensitive to the specific -values. More concisely, using the CDF estimator of instead of itself let the algorithm only depend on the ranking of -values but not on their underlying distribution. This renders the algorithm invariant to strictly increasing -transformations. Now we define
such that is the density of the multivariate normal distribution . Then, we have an explicit expression for the inverse of the Fisher information matrix where is fixed
and for
and, after some calculations, the updates in the CMA-ES turn out as
and
where mat forms the proper matrix from the respective natural gradient sub-vector. That means, setting , the CMA-ES updates descend in direction of the approximation of the natural gradient while using different step-sizes (learning rates 1 and ) for the orthogonal parameters and respectively. More recent versions allow a different learning rate for the mean as well. The most recent version of CMA-ES also use a different function for and 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 , we find that
and under some mild additional assumptions on the initial conditions
and with an additional minor correction in the covariance matrix update for the case where the indicator function evaluates to zero, we find
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 , in that for any the behavior is identical on for all strictly increasing . This invariance is easy to verify, because only the -ranking is used in the algorithm, which is invariant under the choice of .
- Scale-invariance, in that for any the behavior is independent of for the objective function given and .
- Invariance under rotation of the search space in that for any and any the behavior on is independent of the orthogonal matrix , given . More general, the algorithm is also invariant under general linear transformations when additionally the initial covariance matrix is chosen as .
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 . 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 and . Empirically, the fastest possible convergence rate in for rank-based direct search methods can often be observed (depending on the context denoted as linear convergence or log-linear or exponential convergence). Informally, we can write
for some , and more rigorously
or similarly,
This means that on average the distance to the optimum decreases in each iteration by a "constant" factor, namely by . The convergence rate is roughly , given is not much larger than the dimension . Even with optimal and , the convergence rate cannot largely exceed , given the above recombination weights are all non-negative. The actual linear dependencies in and are remarkable and they are in both cases the best one can hope for in this kind of algorithm. Linear convergence of CMA-ES with probability one has been demonstrated for convex quadratic functions.
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, mainly because the sampling equation
can be equivalently expressed in an "encoded space" as
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. 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, , and the initial step-size, . 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 various applications and is considered to be particularly useful on non-convex, non-separable, ill-conditioned, multi-modal or noisy objective functions. One survey of Black-Box optimizations found it outranked 31 other optimization algorithms, performing especially strongly on "difficult functions" or larger-dimensional search spaces.
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 , 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 or SLSQP are typically at least ten times faster;
- on functions that can already be solved with a comparatively small number of function evaluations, say no more than , 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 function evaluations, the CMA-ES shows most often superior performance.
Variations and extensions
The (1+1)-CMA-ES generates only one new solution per iteration step which becomes the new distribution mean if it is better than the current mean. For 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 ) 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. Another remarkable extension has been the addition of a negative update of the covariance matrix with the so-called active CMA. Using the additional active CMA update is considered as the default variant nowadays.

