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 using only the gradient of its log-density. The update rule is:
- : The Score Function. It points towards regions of higher density (the "hill").
- : 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:
Crucially: In Diffusion models, predicting the noise 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:
And more importantly, there exists a Reverse SDE that can turn noise back into data:
Why this matters: If we can estimate the score , 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.
| Perspective | Discrete (DDPM) | Continuous (SDE) |
|---|---|---|
| Process | Markov Chain | Stochastic Flow |
| Objective | Predict Noise | Estimate Score |
| Sampling | Ancestral Sampling | SDE/ODE Solver |