Skip to main content

Stochastic Calculus: The Continuous Flow

While the original DDPM formulation uses discrete steps (e.g., 1000 steps of noise), modern diffusion models are often viewed through the lens of Stochastic Differential Equations (SDEs). This allows us to treat diffusion as a continuous "flow" of probability.


1. Langevin Dynamics

Imagine a ball rolling down a hill (the data distribution), but the ground is shaking violently (random noise).

Langevin Dynamics is a method for sampling from a distribution p(x)p(x) using only the gradient of its log-density. The update rule is:

xt+1=xt+δxlogp(xt)+2δϵx_{t+1} = x_t + \delta \nabla_x \log p(x_t) + \sqrt{2\delta} \epsilon

  • xlogp(xt)\nabla_x \log p(x_t): The Score Function. It points towards regions of higher density (the "hill").
  • ϵ\epsilon: Random Gaussian noise. It prevents the ball from getting stuck in local minima.

2. The Score Function

The "Score" is simply the gradient of the log-likelihood with respect to the input:

s(x)=xlogp(x)\mathbf{s}(x) = \nabla_x \log p(x)

Crucially: In Diffusion models, predicting the noise ϵ\epsilon is mathematically equivalent to estimating the score function. When we "denoise" an image, we are following the score gradient back towards the data manifold.


3. Diffusion as an SDE

We can model the noise injection as a Forward SDE:

dx=f(x,t)dt+g(t)dwdx = \mathbf{f}(x, t) dt + g(t) d\mathbf{w}

And more importantly, there exists a Reverse SDE that can turn noise back into data:

dx=[f(x,t)g(t)2xlogpt(x)]dt+g(t)dwˉdx = [\mathbf{f}(x, t) - g(t)^2 \nabla_x \log p_t(x)] dt + g(t) d\bar{\mathbf{w}}

Why this matters: If we can estimate the score xlogpt(x)\nabla_x \log p_t(x), we can solve this Reverse SDE using standard numerical solvers (like Euler or Runge-Kutta). This allows for faster sampling and more flexible generation.


4. Probability Flow ODE

One of the most powerful insights is that for every SDE, there is a deterministic ODE (Ordinary Differential Equation) that shares the same marginal probability densities.

This is the basis for DDIM (Denoising Diffusion Implicit Models) and Consistent Models. It allows us to generate images in as few as 1-5 steps, rather than 1000.


PerspectiveDiscrete (DDPM)Continuous (SDE)
ProcessMarkov ChainStochastic Flow
ObjectivePredict Noise ϵ\epsilonEstimate Score logp(x)\nabla \log p(x)
SamplingAncestral SamplingSDE/ODE Solver