← Notes · December 2026
A short tour of score-based diffusion models for readers who know probability and differential equations.
Diffusion models are behind much of modern generative AI, but underneath the neural networks they are classical objects: stochastic differential equations, the Fokker–Planck equation, and the continuity equation. For anyone trained in differential equations, they are a good reason to revisit old tools. These notes outline the main ideas.
For a density \(p(y)\), the score is the gradient of its log-density, \(\nabla_y \log p(y)\). It does not need the normalising constant, which is usually the hard part of a density. Diffusion models learn the score instead of the density, and use it to generate samples.
The same holds for conditional distributions. If we want to sample \(y\) given some observed \(x\), Bayes' rule gives
\[ \nabla_y \log p(y \mid x) \;=\; \nabla_y \log p(x \mid y) \;+\; \nabla_y \log p(y), \]since the normalising constant \(p(x)\) does not depend on \(y\). A conditional model can learn the left-hand side directly.
The variance-preserving SDE gradually turns data into standard Gaussian noise:
\[ dY_t = -\tfrac12 \beta(t)\, Y_t\, dt + \sqrt{\beta(t)}\, dW_t, \qquad t \in [0,1]. \]Its transition is Gaussian in closed form. With \(\bar\alpha(t) = \exp\!\big(-\tfrac12\int_0^t \beta(s)\,ds\big)\) and \(\sigma_t^2 = 1-\bar\alpha(t)^2\),
\[ Y_t = \bar\alpha(t)\, Y_0 + \sigma_t\, \varepsilon, \qquad \varepsilon \sim \mathcal N(0,1). \]The density \(p_t\) of \(Y_t\) evolves by the Fokker–Planck equation
\[ \partial_t p_t = \partial_y\!\big(\tfrac12\beta(t)\, y\, p_t\big) + \tfrac12 \beta(t)\, \partial_y^2 p_t , \]so the particle picture (the SDE) and the density picture (the PDE) describe the same process. By \(t=1\), \(p_t\) is close to \(\mathcal N(0,1)\) whatever the data looked like.
Draw a data point \(y_0\), a time \(t\), and noise \(\varepsilon\), form \(y_t = \bar\alpha(t) y_0 + \sigma_t \varepsilon\), and train a network \(s_\theta(y_t, t)\) to minimise
\[ \mathcal L(\theta) = \mathbb E\Big[\, \big\| s_\theta(y_t,t) + \varepsilon/\sigma_t \big\|^2 \Big]. \]This is denoising score matching (Vincent, 2011). The minimiser of a squared loss is a conditional expectation, and
\[ \mathbb E\big[-\varepsilon/\sigma_t \,\big|\, y_t, t\big] = \nabla_{y} \log p_t(y_t). \]So ordinary least-squares regression on the injected noise learns the score at every noise level, without ever evaluating a density.
Anderson's (1982) theorem says the forward SDE can be run backwards in time:
\[ dY_t = \Big[-\tfrac12\beta(t)\, Y_t - \beta(t)\, \nabla_y \log p_t(Y_t)\Big] dt + \sqrt{\beta(t)}\, d\bar W_t, \]with time running from \(t=1\) to \(t=0\). Replacing the score by the trained network gives a sampler: start from Gaussian noise, take Euler–Maruyama steps backwards, and the end point is a draw from the data distribution. Repeating gives as many samples as needed, and their spread describes the uncertainty.
Intuitively, the forward drift pulls everything toward zero. In reverse, the score term pushes \(y\) uphill on \(p_t\), toward likely values, while the noise keeps samples spread over the whole distribution instead of collapsing to its mode.
There is also a deterministic sampler with the same marginals:
\[ \frac{dy}{dt} = -\tfrac12\beta(t)\, y - \tfrac12 \beta(t)\, \nabla_y \log p_t(y). \]An ODE \(\dot y = v(y,t)\) moves densities by the continuity equation \(\partial_t p = -\partial_y(v\,p)\). With this choice of \(v\), the right-hand side equals the Fokker–Planck right-hand side above, so the ODE retraces the same \(p_t\). This is where generative modeling meets numerical analysis: fast samplers are high-order ODE solvers, and flow matching learns the velocity field \(v\) directly.
If the data are Gaussian, \(Y_0 \sim \mathcal N(\mu, v)\), then \(p_t = \mathcal N\big(\bar\alpha\mu,\ \bar\alpha^2 v + \sigma_t^2\big)\) and
\[ \nabla_y \log p_t(y) = -\frac{y - \bar\alpha(t)\mu}{\bar\alpha(t)^2 v + \sigma_t^2}. \]The score is linear in \(y\). For skewed, multimodal or heavy-tailed data the score becomes nonlinear, and that is what a neural network is for. A useful exercise: for a two-component Gaussian mixture, show that the score is a weighted average of the component scores, with weights given by the posterior probability of each component.
Diffusion models make old questions new again: how errors in the learned score affect the samples, how to choose step sizes near \(t=0\), and how well these models capture tails and rare events. These questions matter for scientific data, including environmental data, where uncertainty is often as important as the prediction.