Brownian Motion, Langevin and Fokker–Planck: The Physics of a Sampler

6 minute read

Published:

TL;DR: Brownian motion spreads as \(\sqrt{t}\), not \(t\). Fick's law plus conservation gives the diffusion equation; adding a drift gives the Langevin equation \(dx = -\nabla U\,dt + \sqrt{2D}\,dW\), whose density obeys the Fokker–Planck equation and settles to \(p_\infty \propto e^{-U/D}\). Choose \(U = -\log p_{\text{data}}\) and the stationary distribution is the data distribution — the drift term is then the score, and you have the sampler used by score-based generative models.

The Wiener process

Einstein’s 1905 account of Brownian motion explained the jitter of pollen grains as the accumulated effect of molecular collisions. Its mathematical idealisation is the Wiener process $W_t$: $W_0 = 0$, independent increments, $W_t - W_s \sim \mathcal N(0, t-s)$ for $t>s$, and continuous sample paths.

The defining scaling is $\mathbb E[W_t^2] = t$, so typical displacement grows like $\sqrt t$. Over an interval $\Delta t$ the increment has size $\sqrt{\Delta t}$, which dwarfs $\Delta t$ as $\Delta t\to 0$ — this is why Wiener paths are nowhere differentiable and why stochastic calculus needs its own rules rather than the ordinary chain rule.

Concretely, a 1 µm-diameter bead in water at 20 °C has $D = kT/(6\pi\eta a) \approx 0.43\ \mathrm{µm^2\,s^{-1}}$. Its root-mean-square displacement along one axis is $\sqrt{2Dt}$:

elapsed timeRMS displacement (one axis)
1 s0.93 µm
10 s2.93 µm
100 s9.27 µm

A hundredfold increase in time buys only a tenfold increase in distance. Diffusion is a poor way to travel and an excellent way to explore.

Fick’s law and the diffusion equation

Particles flow from crowded regions to empty ones, at a rate proportional to the concentration gradient — Fick’s first law, $\mathbf J = -D\nabla\rho$, with $\mathbf J$ the flux and $\rho$ the density. Combine it with conservation, $\partial_t\rho + \nabla\cdot\mathbf J = 0$, and the diffusion equation follows:

\[ \frac{\partial \rho}{\partial t} \;=\; D\,\nabla^2\rho . \]

Started from a point source in one dimension, the solution is a Gaussian \(\rho(x,t) = (4\pi D t)^{-1/2}\exp\!\left(-x^2/4Dt\right)\) of variance $2Dt$ — the same $\sqrt t$ spreading, now as a statement about the whole density rather than one path.

Gaussian spreading of a diffusing density at three timesThree nested Gaussian curves from a point source under the diffusion equation, at times t equals 1, 4 and 9. Their standard deviations are 1, 2 and 3 units respectively, so the width grows as the square root of time while the peak height falls as one over the square root of time. t = 1, σ = 1 t = 4, σ = 2 t = 9, σ = 3 position x — width σ = √(2Dt), peak height ∝ 1/√t
Notice that quadrupling the time only doubles the width. The area under each curve is the same; the density does not vanish, it flattens.

The Langevin equation

Add a force. A heavy particle in a potential $V$, in a medium with friction coefficient $\gamma$, in the overdamped limit where inertia is negligible, obeys

\[ dx \;=\; -\frac{1}{\gamma}\nabla V(x)\,dt \;+\; \sqrt{\tfrac{2kT}{\gamma}}\;dW . \]

Two terms, two roles: the drift $-\nabla V/\gamma$ pulls downhill, the noise kicks in random directions with a strength set by temperature. Their ratio is fixed by the fluctuation–dissipation relation, not free to choose — the same collisions that cause friction cause the kicks. The Einstein relation $D = \mu kT$, with mobility $\mu = 1/\gamma$, is exactly that statement.

Fokker–Planck: what the density does

Track the density instead of the path. For $dx = f(x)\,dt + \sqrt{2D}\,dW$ the density evolves as

\[ \frac{\partial p}{\partial t} \;=\; -\nabla\!\cdot\!\big(f(x)\,p\big) \;+\; D\,\nabla^2 p \;=\; -\nabla\!\cdot\! J, \qquad J = f p - D\nabla p . \]

The first term transports probability along the drift; the second smooths it. Setting $f = -\nabla U$ and trying \(p_\infty \propto e^{-U/D}\) gives \(D\nabla p_\infty = -\nabla U\,p_\infty = f p_\infty\), so the current $J$ vanishes identically. The stationary state is not merely stationary but has zero flux — detailed balance. With $U = V$ and $D = kT/\gamma$ this reproduces the Boltzmann distribution \(p_\infty \propto e^{-V/kT}\): equilibrium statistical mechanics falls out of a stochastic differential equation.

The line to score-based generative models

Now run the argument backwards. You want to sample from \(p_{\text{data}}\). Pick \(U = -\log p_{\text{data}}\) and $D = \tfrac12$:

\[ dx \;=\; \tfrac12 \nabla_x \log p_{\text{data}}(x)\,dt \;+\; dW \quad\Longrightarrow\quad p_\infty = p_{\text{data}} . \]

Discretised with step $\eta$, this is \(x_{k+1} = x_k + \tfrac{\eta}{2}\nabla_x\log p(x_k) + \sqrt{\eta}\,z_k\) with $z_k\sim\mathcal N(0,I)$ — unadjusted Langevin. The only thing needed is the score $\nabla_x\log p$, which is free of the intractable normaliser, and that is precisely what a score network is trained to estimate. Song & Ermon (2019) run this at a ladder of noise levels, annealing from large to small; the continuous-time generalisation and its reverse-time SDE are covered in score-based SDEs.

Interview trap: the noise is not an implementation detail or a regulariser. Delete it and the update is plain gradient ascent on \(\log p\), which converges to a single mode — a point mass, not a sample. The noise term is what makes the stationary distribution \(p\) itself, and the fluctuation–dissipation ratio between drift and noise is what fixes which distribution you get. A second frequent slip: plain Langevin also struggles because the score is badly estimated where the data density is tiny, which is the motivation for annealing over noise scales rather than any property of the sampler itself.
Key Insight — optimisation and sampling are one algorithm: \(x \leftarrow x + \tfrac{\eta}{2}\nabla\log p(x)\) is gradient ascent; add \(\sqrt{\eta}\,z\) and it is a sampler. Cooling the noise to zero interpolates continuously between them, which is why simulated annealing, stochastic gradient Langevin dynamics and annealed score-based sampling are the same object at different noise schedules.

Recap

  • Wiener process: independent Gaussian increments with \(\mathbb{E}[W_t^2]=t\), so displacement scales as \(\sqrt{t}\) and paths are nowhere differentiable.
  • Fick's law \(J=-D\nabla\rho\) plus conservation gives \(\partial_t\rho = D\nabla^2\rho\), with point-source variance \(2Dt\).
  • Langevin combines drift and noise, tied together by fluctuation–dissipation; the Einstein relation is \(D=\mu kT\).
  • Fokker–Planck governs the density; for \(f=-\nabla U\) the zero-current stationary state is \(p_\infty\propto e^{-U/D}\).
  • Setting \(U=-\log p_{\text{data}}\) makes Langevin a sampler for the data distribution driven only by the score — the basis of score-based generative models.

References

  1. Einstein, A. Über die von der molekularkinetischen Theorie der Wärme geforderte Bewegung von in ruhenden Flüssigkeiten suspendierten Teilchen. Annalen der Physik, 322(8):549–560, 1905.
  2. Risken, H. The Fokker–Planck Equation: Methods of Solution and Applications, 2nd ed. Springer, 1989.
  3. Welling, M., & Teh, Y. W. Bayesian Learning via Stochastic Gradient Langevin Dynamics. ICML 2011.
  4. Song, Y., & Ermon, S. Generative Modeling by Estimating Gradients of the Data Distribution. NeurIPS 2019.
  5. Song, Y., Sohl-Dickstein, J., Kingma, D. P., Kumar, A., Ermon, S., & Poole, B. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021.