Search

Search papers and lessons

Evolution Strategies

Level 3 · 13 min read

Evolution strategies improve a model by trying many randomly perturbed copies of it and moving toward the ones that scored best, which needs only scores and no gradients of the objective.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Discrete math
  • Linear algebra
  • Losses & regularization
  • Optimizers
  • Sign in to see your progress

TL;DR

An evolution strategy (ES) improves a model by sampling many slightly different copies of its parameters, scoring each copy with the objective, and moving the parameters toward the copies that scored well. It never differentiates the objective, so it works when the score is a black box: a simulator, a game return, or a pass rate. The update it makes is a gradient estimate built from random perturbations.

Where you'll see it: tuning the controller of a small agent in a simulator, hyperparameter and policy search where backpropagation is impossible, and CMA-ES, the standard derivative-free optimiser for problems with a few hundred parameters or fewer.

Intuition

Feel the hill with random steps

Picture standing on a foggy hillside and wanting to climb. You cannot see the slope, but you have an altimeter. Throw a handful of pebbles in random directions near where you stand, read the altimeter at each landing spot, and then take a step in the direction of the pebbles that landed higher. Repeat. Nobody told you the slope; you inferred it from a cloud of random probes.

That is the whole method. The parameters are your position. Each random probe is a perturbed copy of the parameters. The score is the altitude. Averaging the perturbations weighted by how high they landed points you uphill, and it works even when the landscape is noisy, jagged, or computed by a program you cannot differentiate.

Why bother when Gradient Descent exists? Gradient descent needs the derivative of the objective with respect to the parameters. In reinforcement learning the objective is the total reward of an episode, which depends on the environment's dynamics through a chain of actions the optimiser cannot see into. Evolution strategies sidestep that. They only need the scores, so they can run on any simulator, on many machines in parallel (each worker needs one number back), and without storing a computation graph.

−1012345−8−6−4−20parameter θscore
  • F(x), the score at x
  • smoothed J(x)
The smoothed objective J is the average score under random perturbations of width σ = 1. It peaks at the same place as F, and its value at θ = 0 is −5 (the marked point).

The dashed curve is the quantity an ES actually climbs. It is the average score over random perturbations, so it is smoother than the original score and has a gradient even where the original is jagged.

flowchart LR
    A[Current parameters θ] --> B[Sample N random noises ε_i]
    B --> C[Evaluate score F at θ + σ ε_i]
    C --> D[Weight each noise by its score]
    D --> E[Move θ uphill along the weighted sum]
    E --> A

The math

Definition: Evolution strategy (maximising form)

Given an objective FF that maps parameters θ∈Rd\theta \in \mathbb{R}^d to a score, and a noise scale σ>0\sigma \gt 0, the smoothed objective is J(θ)=Eε∼N(0,I)[F(θ+σε)]J(\theta) = \mathbb{E}_{\varepsilon \sim \mathcal{N}(0, I)}\left[F(\theta + \sigma\varepsilon)\right], where ε\varepsilon is a standard Gaussian vector of the same dimension as θ\theta. An ES climbs JJ by stochastic gradient ascent, using only values of FF.

Here θ\theta is the vector of model parameters, II is the identity matrix, and σ\sigma controls how far the probes spread. The expectation averages over every possible perturbation, weighted by its Gaussian probability (see Gaussian (Normal) Distribution).

The gradient estimate

Substitute x=θ+σεx = \theta + \sigma\varepsilon. The expectation becomes an integral against the density of a Gaussian centred at θ\theta with covariance σ2I\sigma^2 I:

J(θ)=∫F(x) N(x; θ,σ2I) dxJ(\theta) = \int F(x)\, \mathcal{N}(x;\, \theta, \sigma^2 I)\, dx

Differentiate the density with respect to its mean. For a Gaussian, ∇θN(x;θ,σ2I)=N(x;θ,σ2I) (x−θ)/σ2\nabla_\theta \mathcal{N}(x; \theta, \sigma^2 I) = \mathcal{N}(x; \theta, \sigma^2 I)\,(x - \theta)/\sigma^2. Substituting x−θ=σεx - \theta = \sigma\varepsilon gives

∇θJ(θ)=∫F(x) N(x; θ,σ2I) x−θσ2 dx=1σ Eε[F(θ+σε) ε]\nabla_\theta J(\theta) = \int F(x)\, \mathcal{N}(x;\, \theta, \sigma^2 I)\, \frac{x-\theta}{\sigma^2}\, dx = \frac{1}{\sigma}\, \mathbb{E}_{\varepsilon}\big[F(\theta + \sigma\varepsilon)\, \varepsilon\big]

This is the score-function identity from Score Function, applied to a Gaussian. The derivative lands on the sampling distribution, not on FF, so FF never has to be differentiated. Replacing the expectation by an average over NN samples gives the estimator

g^=1Nσ∑i=1NF(θ+σεi) εi,θ←θ+α g^\hat g = \frac{1}{N\sigma} \sum_{i=1}^{N} F(\theta + \sigma \varepsilon_i)\, \varepsilon_i, \qquad \theta \leftarrow \theta + \alpha\, \hat g

where α\alpha is the learning rate. Each sample contributes its noise vector εi\varepsilon_i weighted by its score. Probes that landed higher pull θ\theta toward themselves, and low-scoring probes push it away.

Antithetic sampling

A common variant draws each noise in a mirrored pair, ε\varepsilon and −ε-\varepsilon, and uses the difference of their scores:

g^=12Nσ∑i=1N[F(θ+σεi)−F(θ−σεi)] εi\hat g = \frac{1}{2N\sigma} \sum_{i=1}^{N} \big[F(\theta + \sigma \varepsilon_i) - F(\theta - \sigma \varepsilon_i)\big]\, \varepsilon_i

This is still unbiased: the term F(θ−σε)(−ε)F(\theta - \sigma\varepsilon)(-\varepsilon) has the same expectation as F(θ+σε)εF(\theta + \sigma\varepsilon)\varepsilon, by the substitution ε→−ε\varepsilon \to -\varepsilon. Pairing cancels the part of the score that does not depend on the direction of the probe, which is usually the largest source of noise.

Covariance adaptation (CMA-ES)

The estimator above uses one fixed noise scale in every direction. The covariance matrix adaptation evolution strategy (CMA-ES) instead samples from a full Gaussian with a learned Covariance Matrix CC, so the search stretches along directions that have been paying off. It also adapts σ\sigma from the success of recent steps. Hansen's tutorial is the standard reference for its update rules, and it is the version most people mean when they say "CMA-ES".

Worked examples

Example
One dimension, four probes

Take F(x)=−(x−2)2F(x) = -(x - 2)^2. It peaks at x=2x = 2. At θ=0\theta = 0 with σ=1\sigma = 1, the true smoothed gradient is available in closed form. Since J(θ)=−((θ−2)2+1)J(\theta) = -((\theta - 2)^2 + 1), we get ∇J(0)=−2(0−2)=4\nabla J(0) = -2(0 - 2) = 4.

Draw four noises ε=1,−1,0.5,−0.5\varepsilon = 1, -1, 0.5, -0.5 and compute the estimator with N=4N = 4:

  1. Probe positions xi=θ+σεix_i = \theta + \sigma\varepsilon_i: 1,−1,0.5,−0.51, -1, 0.5, -0.5.
  2. Scores F(xi)=−(xi−2)2F(x_i) = -(x_i - 2)^2: −1,−9,−2.25,−6.25-1, -9, -2.25, -6.25.
  3. Products F(xi) εiF(x_i)\,\varepsilon_i: (−1)(1)=−1(-1)(1) = -1; (−9)(−1)=9(-9)(-1) = 9; (−2.25)(0.5)=−1.125(-2.25)(0.5) = -1.125; (−6.25)(−0.5)=3.125(-6.25)(-0.5) = 3.125.
  4. Sum: −1+9−1.125+3.125=10-1 + 9 - 1.125 + 3.125 = 10.
  5. Divide by Nσ=4N\sigma = 4: g^=2.5\hat g = 2.5.

The estimate is 2.5 against a true gradient of 4. With four samples the estimate is noisy but points the right way. Interpretation: the probes that landed to the right of 0, where the score is higher, carried the most weight, so the update pushes θ\theta right.

Example
One update step

Continue with the same example and learning rate α=0.1\alpha = 0.1:

  1. Update: θ←0+0.1×2.5=0.25\theta \leftarrow 0 + 0.1 \times 2.5 = 0.25.
  2. Smoothed objective before: J(0)=−(4+1)=−5J(0) = -(4 + 1) = -5.
  3. Smoothed objective after: J(0.25)=−((0.25−2)2+1)=−(3.0625+1)=−4.0625J(0.25) = -((0.25 - 2)^2 + 1) = -(3.0625 + 1) = -4.0625.
  4. The smoothed objective rose from −5-5 to −4.0625-4.0625 in one step.

Interpretation: one noisy step moved the parameters in the right direction without ever differentiating FF. In practice a run uses many more samples per step (large populations are common) and many more steps, and the estimate becomes accurate as NN grows.

Example
A realistic setting: a policy with no gradient

Suppose θ\theta holds the weights of a small neural network controller, and F(θ)F(\theta) is the average return of that controller over several simulated episodes. FF depends on the simulator's physics and on the controller's actions, which are sampled, so no backpropagation path leads from the return to θ\theta. The ES recipe still works: sample NN perturbations of θ\theta, run episodes with each, and feed the returns into the estimator. Each worker only has to send back a single number per perturbation, which is why the method scales to many machines. Salimans and colleagues used this setting to show that ES can be competitive with Reinforcement Learning methods on standard control benchmarks, as an alternative to a Policy Gradient method.

Tradeoffs and failure modes

SituationProblemBetter choice
Objective is differentiable and cheapES wastes evaluations estimating what a backward pass gives exactlyGradient Descent or backpropagation
Millions of parametersThe estimator's variance grows with dimension, so NN must grow with itGradient methods, or ES with a low-dimensional parametrisation
Score is very noisyProbes are dominated by noise, so the estimate needs huge populationsAntithetic pairs, averaging over episodes, or common random seeds
Few hundred parameters, smooth landscapePlain ES converges slowly along narrow valleysCMA-ES, which learns the shape of the valley
Need the gradient of the score with respect to an action or a stateES only gives a gradient of the smoothed objective over parametersPolicy Gradient or Actor-Critic Methods methods that use value estimates

The main failure mode is a σ\sigma that is too large or too small. Too large, and the probes average over a landscape so smoothed out that the optimum is blurred. Too small, and the probes land so close together that the score differences are dominated by noise. A second failure is a learning rate that is too big: a step can overshoot a ridge and make the score worse, and nothing in the estimator warns you.

Evolution strategies also do not explore in the sense a Multi-Armed Bandit does; they follow the average of the probes, so a population can converge to a local optimum and stay there.

History

Evolution strategies were developed in Germany in the 1960s and early 1970s. Ingo Rechenberg and Hans-Paul Schwefel, working at the Technical University of Berlin, used populations of mutated designs to optimise engineering shapes such as aerodynamic bodies, where no derivative was available. Rechenberg's 1973 book set out the theory, including the one-fifth success rule for adapting the mutation size.

Through the 1990s and 2000s the method stayed mostly in evolutionary computation. Hansen and Ostermeier introduced CMA-ES in the early 2000s, adding the covariance adaptation that made the method robust on ill-conditioned problems. In 2008, Wierstra and colleagues proposed natural evolution strategies, which recast the update as a natural-gradient step on the parameters of the search distribution.

The method returned to the mainstream in 2017, when Salimans and colleagues at OpenAI showed that a simple ES, distributed across many workers, could train neural network policies for standard control tasks at a competitive level with reinforcement learning. Its appeal was the tiny amount of communication it needed and its indifference to whether the reward was differentiable. Ha and Schmidhuber's world-model work, in which a small controller is trained with CMA-ES on top of learned features, popularised the same combination.

Check yourself

QuestionRecall: what does the smoothed objective J(θ)=E[F(θ+σε)]J(\theta) = \mathbb{E}[F(\theta + \sigma\varepsilon)] average over?Show answer

It averages the score FF over random perturbations of the parameters. Each perturbation is θ+σε\theta + \sigma\varepsilon with ε\varepsilon drawn from a standard Gaussian, so J(θ)J(\theta) is the expected score of a Gaussian cloud of parameter vectors centred at θ\theta with spread σ\sigma.

QuestionCompute: with θ=1\theta = 1, σ=0.5\sigma = 0.5, N=2N = 2, noises ε=2\varepsilon = 2 and ε=−1\varepsilon = -1, and scores F(x)=−x2F(x) = -x^2 at the probes, what is g^\hat g?Show answer

Probes: x1=1+0.5×2=2x_1 = 1 + 0.5 \times 2 = 2, and x2=1+0.5×(−1)=0.5x_2 = 1 + 0.5 \times (-1) = 0.5. Scores: F(2)=−4F(2) = -4 and F(0.5)=−0.25F(0.5) = -0.25. Products with the noises: (−4)(2)=−8(-4)(2) = -8 and (−0.25)(−1)=0.25(-0.25)(-1) = 0.25. Sum =−7.75= -7.75. Divide by Nσ=2×0.5=1N\sigma = 2 \times 0.5 = 1, so g^=−7.75\hat g = -7.75. The estimate is negative, pushing θ\theta left, because the probe that landed far right (x=2x = 2) scored badly and had a positive noise, which is the expected behaviour for a score that falls off away from zero.

QuestionWhy does the estimator need only the values of FF and never its derivative?Show answer

The derivative of the sampling density, not of FF, appears in the identity. Writing the gradient of E[F(θ+σε)]\mathbb{E}[F(\theta + \sigma\varepsilon)] as an integral against the Gaussian turns the derivative onto the Gaussian, which has a closed form (x−θ)/σ2(x - \theta)/\sigma^2. FF is only evaluated at sample points, so it can be a simulator, a program with branches, or anything else that returns a number.

QuestionWhy might antithetic sampling reduce noise even though it uses the same number of perturbations?Show answer

Each mirrored pair, ε\varepsilon and −ε-\varepsilon, gives probes on opposite sides of θ\theta. The difference F(θ+σε)−F(θ−σε)F(\theta + \sigma\varepsilon) - F(\theta - \sigma\varepsilon) cancels any part of the score that is the same on both sides, such as an offset or a shared random baseline in a noisy simulator. The estimator is still unbiased, so the variance drops without bias.

QuestionApplied: you are tuning 40 numbers in a robot controller whose score comes from a physics simulator that you cannot differentiate. Which method do you try first, and what do you monitor?Show answer

An evolution strategy, such as a simple Gaussian ES or CMA-ES at this dimension, is a reasonable first try because it needs only scores. Monitor the spread of the scores within each population as well as the mean score. If the spread collapses while the mean stalls, the search has converged too early, so widen σ\sigma or restart. If the mean improves but individual runs swing wildly between steps, the learning rate is too large.

Sources