Reading evolution, learning, and consciousness through a single gradient
Over the series so far, we've picked up two ways of "going downhill." One is Episode 2's backpropagation (BP) ── differentiate the loss, compute the gradient \(\nabla L\) straight, and descend: a sharp, local tool. The other is Episode 4's evolution strategies (ES) ── use no differentiation at all; scatter many perturbations and average the "directions that turned out good": a blunt but robust, population-level tool. Learning that differentiates and evolution that doesn't. In philosophy the two look diametrically opposed. And yet, in truth, the two are computing exactly the same gradient. ES is BP wearing the face of "integration," and BP is ES wearing the face of "differentiation." What proves this coincidence is a classic of statistics ── Stein's lemma. This episode is the heart of the series. Skipping not a single step of the derivation, let's walk on our own two feet all the way to the final identity.
First, let's set the two side by side. Let's borrow ahead of time the smoothed loss (Gaussian smoothing) that will be the star of Episode 7. It's the loss \(L\) "leveled out" by blurring it around the center \(\theta\) with Gaussian noise \(\varepsilon\) of standard deviation \(\sigma\).
Lowering this \(L_\sigma\) is the shared goal of the two. So how do the two get their hands on its gradient \(\nabla L_\sigma(\theta)\)?
ES (the evolution, integration face). Scatter \(N\) perturbations \(\varepsilon_1,\dots,\varepsilon_N\) from the center \(\theta\) using a Gaussian, and measure only the evaluation value \(L(\theta+\varepsilon_i)\) of each. No differentiation. Then take "the average of the perturbations weighted by their evaluation values" ── this is ES's gradient estimate. A global operation that gathers the values of the loss and integrates (averages) them.
ES: average of (evaluation value × perturbation) (no differentiation, global)
$$\hat{g}_{\mathrm{ES}}\;=\;\frac{1}{\sigma^2}\cdot\frac{1}{N}\sum_{i=1}^{N} L(\theta+\varepsilon_i)\,\varepsilon_i$$BP: average of gradients in a neighborhood (with differentiation, local)
$$\hat{g}_{\mathrm{BP}}\;=\;\frac{1}{N}\sum_{i=1}^{N}\nabla L(\theta+\varepsilon_i)\quad\bigl(\text{as}\ N\to\infty,\ \mathbb{E}[\nabla L(\theta+\varepsilon)]\bigr)$$BP (the learning, differentiation face). At each point, differentiate the loss and read the gradient \(\nabla L\) directly. For the gradient of the blurred loss, just average the gradients in the neighborhood. A local operation that gathers the slopes of the loss.
One is an integral of values, the other a differential of slopes. The information used and the computational philosophy differ. And yet these two converge to the same quantity. The bridge is Stein's lemma.
The key is one beautiful equation the Gaussian distribution possesses. The average of a quantity "multiplied" by Gaussian noise turns into the average of that quantity "differentiated" ── a theorem that bridges integration (averaging) and differentiation, made exactly for this episode.
(\(f\) is taken to be a sufficiently nice function ── differentiable, and not blowing up as \(\varepsilon\) heads off to infinity.)
The left side is the average of "the product of the noise \(\varepsilon\) and the function value \(f\)"; the right side is the average of "the derivative of \(f\)." Left is an integral of values, right is an average of slopes. This is exactly the skeleton of the ES–BP relationship. Why does this equation hold ── it comes out in one line from a single property of the Gaussian density. In the next section let's prove the one-dimensional case all the way to the end (the multidimensional case is just applying the same argument to each component).
The heart of the proof is a differential equation satisfied by the Gaussian density \(p(\varepsilon)\). Differentiate the Gaussian and it comes back as itself, multiplied by \(-\varepsilon/\sigma^2\) ── from this single point, integration by parts does everything else for us.
① The Gaussian density, and its derivative
$$p(\varepsilon)=\frac{1}{\sqrt{2\pi}\,\sigma}\,e^{-\varepsilon^2/(2\sigma^2)} \qquad\Longrightarrow\qquad p'(\varepsilon)=-\frac{\varepsilon}{\sigma^2}\,p(\varepsilon)$$② So "ε × density" can be rewritten as "the derivative of the density"
$$\varepsilon\,p(\varepsilon)\;=\;-\,\sigma^2\,p'(\varepsilon)$$③ Substitute this into the average \(\mathbb{E}[\varepsilon f(\varepsilon)]\)
$$\mathbb{E}\!\left[\varepsilon f(\varepsilon)\right] =\int_{-\infty}^{\infty}\!\varepsilon\, f(\varepsilon)\,p(\varepsilon)\,d\varepsilon =-\,\sigma^2\!\int_{-\infty}^{\infty}\! f(\varepsilon)\,p'(\varepsilon)\,d\varepsilon$$④ Integrate by parts (the boundary term vanishes as \(p\to 0\))
$$\int f\,p'\,d\varepsilon =\underbrace{\bigl[\,f(\varepsilon)\,p(\varepsilon)\,\bigr]_{-\infty}^{\infty}}_{=\,0} -\int f'(\varepsilon)\,p(\varepsilon)\,d\varepsilon =-\int f'(\varepsilon)\,p(\varepsilon)\,d\varepsilon$$⑤ Put it back into ③, and the two minus signs line up
$$\mathbb{E}\!\left[\varepsilon f(\varepsilon)\right] =-\,\sigma^2\left(-\int f'(\varepsilon)\,p(\varepsilon)\,d\varepsilon\right) =\sigma^2\!\int f'(\varepsilon)\,p(\varepsilon)\,d\varepsilon =\sigma^2\,\mathbb{E}\!\left[f'(\varepsilon)\right]$$And so \(\mathbb{E}[\varepsilon f(\varepsilon)]=\sigma^2\,\mathbb{E}[f'(\varepsilon)]\) ── Stein's lemma (one-dimensional) is rigorously proved. No approximation whatsoever. Just the Gaussian density's property \(p'=-(\varepsilon/\sigma^2)p\) and integration by parts. The boundary term vanishes because, as long as \(f\) is gentler than the Gaussian's tail, \(f(\varepsilon)p(\varepsilon)\to 0\).
The preparations are complete. Substitute \(f(\varepsilon)=L(\theta+\varepsilon)\) into Stein's lemma. From the chain rule, note that the gradient with respect to \(\varepsilon\) equals the gradient with respect to \(\theta\) ── \(\nabla_\varepsilon L(\theta+\varepsilon)=\nabla_\theta L(\theta+\varepsilon)\).
① Put \(f(\varepsilon)=L(\theta+\varepsilon)\) into Stein's lemma
$$\mathbb{E}\!\left[\varepsilon\,L(\theta+\varepsilon)\right]\;=\;\sigma^2\,\mathbb{E}\!\left[\nabla L(\theta+\varepsilon)\right]$$② Divide both sides by \(\sigma^2\)
$$\frac{1}{\sigma^2}\,\mathbb{E}\!\left[L(\theta+\varepsilon)\,\varepsilon\right]\;=\;\mathbb{E}\!\left[\nabla L(\theta+\varepsilon)\right]$$③ Swap the averaging and differentiation (\(\nabla_\theta\) can come outside the average over \(\varepsilon\))
$$\mathbb{E}\!\left[\nabla_\theta L(\theta+\varepsilon)\right]\;=\;\nabla_\theta\,\mathbb{E}\!\left[L(\theta+\varepsilon)\right]\;=\;\nabla L_\sigma(\theta)$$Stringing the three together on one line, the backbone identity of this series appears.
The far left is ES ── a global "integral" quantity, using no differentiation, that averages the evaluation values \(L(\theta+\varepsilon)\) weighted by the perturbations \(\varepsilon\). The middle is BP ── a local "differential" quantity that averages the gradients obtained by differentiating at infinitely many neighboring points. These two are exactly equal. And moreover both are nothing but the gradient \(\nabla L_\sigma\) of the smoothed loss \(L_\sigma\).
ES is BP on the smoothed loss.
Evolution and learning were computing the same gradient.
It's not an approximation. It's not a finite difference. Stein's lemma, an exact equation, ties the two worlds together with a single line. Evolution that doesn't differentiate and learning that does were merely computing the same gradient of the same terrain \(L_\sigma\), just wearing different faces.
The figure below is a visualization of the identity itself. On top of a two-dimensional loss terrain (contour lines) we place a single point \(\theta\) (red), and from there scatter \(N\) Gaussian perturbations (amber dots). The green arrow is the ES estimate \(\hat{g}\), built from the left-side formula using only the evaluation values of the scattered points. The black arrow is the true smoothed gradient \(\nabla L_\sigma\) (the right side), which can be computed analytically for this terrain. Turn \(N\) up ── the ES arrow converges toward the true gradient as if drawn to it (the estimate's scatter is \(\propto 1/N\)). Change \(\sigma\) and the strength of the blur ── i.e., the true gradient itself ── changes.
What about \(N=2\)? The green arrow points in a wildly different direction each time, and its length is all over the place too ── no wonder, since we're trying to guess a gradient from just two evaluation values. But raise \(N\) to a few hundred and green lands exactly on black. Just by gathering evaluation values and averaging, without differentiating, the gradient you'd get by differentiating is recovered. The readout's "angle difference" heads toward \(0^\circ\), and the "magnitude ratio" toward \(1\). This is the visible meaning of "ES is an unbiased estimate of BP."
Using the language of nonstandard analysis from last time (Episode 5), this convergence becomes even more transparent. Rather than making the population size \(N\) large while keeping it finite, let's take \(N\) to be hyperfinite (an infinite hypernatural number). Then the ES sum becomes a hyperfinite sum.
The evaluation-value-weighted average over a population of infinitely many individuals. Its standard part \(\mathrm{st}\) (the "visible value" with the infinitesimal fluctuation shaved off) matches exactly the right-side expectation ── the true gradient. As we saw in Episode 5, each individual of the population is an infinitesimal perturbation filling the monad (infinitesimal neighborhood) of the center \(\theta\), and the consensus of those infinitesimals recovers the gradient of the standard world. For finite \(N\), a fluctuation of \(\propto 1/N\) (the deviation from the infinitesimal, in Episode 5's terms) remains in this consensus; but if \(N\) is hyperfinite, that deviation is infinitesimal and \(\mathrm{st}\) erases it.
This coincidence is powerful, but exactly what it claims needs to be judged carefully. Let's put three common turns of phrase, all three, on trial.
| Claim | Examination | Verdict |
|---|---|---|
| "ES is a finite-difference approximation of BP (just mimicking the derivative with a difference quotient)." | No. ES isn't numerically differentiating the raw \(L\); it's an unbiased estimate of the gradient of the smoothed loss \(L_\sigma\). Not a finite difference, but a rigorous average quantity given by Stein's identity. | ✗ (rejected) |
| "ES and BP coincide exactly on the raw loss \(L\)." | What coincides is the gradient of the σ-blurred \(L_\sigma\), not the gradient of the raw \(L\). The two coincide only in the limit \(\sigma\to 0\) (and when \(L\) is smooth). | handle with care |
| "Stein's identity is exact (not an approximation)." | Correct. Under mild assumptions of integrability and smoothness, it's a complete equation derived from integration by parts. In Section 3 we proved it using no approximation at all. | survives |
The identity \(\tfrac{1}{\sigma^2}\mathbb{E}[L(\theta+\varepsilon)\,\varepsilon]=\nabla L_\sigma(\theta)\) is an exact equation from Stein's lemma (under mild assumptions of integrability and smoothness). But the sense in which ES and BP are "the same" here is only about the gradient of the smoothed loss \(L_\sigma\). As long as \(\sigma\) is finite, \(\nabla L_\sigma\) deviates from the gradient \(\nabla L\) of the raw loss ── the true nature of this deviation, and the role \(\sigma\) plays, is precisely next time's subject.
Even so, the claim is plenty strong. Evolution (ES) and learning (BP) are not separate principles but two faces (integration and differentiation) of one and the same gradient computation. One gathers the population's values, the other differentiates at a single point ── the apparatus is completely different, yet the gradient they point to is the same. This is the backbone of this series. Next time we'll reread this \(\sigma\) as "resolution / temperature," and watch how blurring smooths the terrain and fills in local minima.
ES is a global tool that only integrates evaluation values; BP is a local tool that differentiates to get the gradient (STEP 01). What bridges the two is Stein's lemma \(\mathbb{E}[\varepsilon f(\varepsilon)]=\sigma^2\mathbb{E}[\nabla f]\) (STEP 02), which can be proved rigorously from just the Gaussian density's \(p'=-(\varepsilon/\sigma^2)p\) and integration by parts (STEP 03). Putting in \(f(\varepsilon)=L(\theta+\varepsilon)\) and tidying up gives the central identity \(\tfrac1{\sigma^2}\mathbb{E}[L(\theta+\varepsilon)\varepsilon]=\mathbb{E}[\nabla L(\theta+\varepsilon)]=\nabla L_\sigma(\theta)\) ── ES = BP = the gradient of the smoothed loss (STEP 04). In the figure, the higher \(N\) goes the more the ES estimate converges to the true gradient (STEP 05), and in nonstandard analysis the standard part of the hyperfinite sum recovers the gradient (STEP 06). But what is "the same" is the gradient of \(L_\sigma\), not the raw \(L\) (STEP 07).
Evolution that doesn't differentiate and learning that does were not different things. They were merely computing the same gradient of the same terrain \(L_\sigma\), through the two faces of integration and differentiation ── this coincidence is the heart of this series. Only one question remains. So then, what is \(\sigma\)?
Print / PDF: ⌘+P (Ctrl+P on Windows). On screen, raising "Population size N" makes the green ES-estimate arrow converge to the black true gradient ∇Lσ. Use "Blur σ" to change the strength of the smoothing, and "Redraw" to redraw the perturbations. "See the answer" opens each solution.