Master the essential mathematical toolkit underpinning diffusion models: Gaussian distributions, Markov chains, KL divergence, variational inference, stochastic differential equations, and Langevin dynamics. These foundations are critical for understanding both the theory and implementation of modern diffusion-based generative models.
Diffusion models rest on a surprisingly elegant mathematical framework. At their core, they define a forward process that gradually destroys data by adding Gaussian noise, and a learned reverse process that reconstructs data from pure noise. Understanding why this works---and how to train it efficiently---requires fluency in several branches of mathematics.
We begin with Gaussian distributions, the building block of the noise process. Every step of diffusion adds Gaussian noise, and the remarkable closure properties of Gaussians make the entire forward process analytically tractable. Next, Markov chains formalize the sequential structure: each noising step depends only on the previous state, enabling efficient factorization of joint distributions.
KL divergence measures how one probability distribution differs from another, and it is the natural loss function for training generative models. Variational inference provides the framework for optimizing intractable likelihoods by maximizing a tractable lower bound (the ELBO), which is exactly how diffusion models are trained.
Finally, the continuous-time perspective connects diffusion models to stochastic differential equations and Langevin dynamics. Score-based generative models use the score function (gradient of the log-density) to reverse the noising process, unifying denoising diffusion with classical MCMC sampling.
This chapter covers:
Click any topic to jump in
Properties of Gaussians and reparameterization — the building block of diffusion.
Sequential structure and optimization target
Transition kernels and stationary distributions — the sequential structure of diffusion.
Measuring distribution distance — the objective connecting forward and reverse processes.
The Gaussian (normal) distribution is the most important distribution in diffusion models. Every forward step adds Gaussian noise, and the reverse process predicts Gaussian parameters. The remarkable algebraic properties of Gaussians---closure under addition, linear transformation, conditioning, and marginalization---make the entire diffusion framework analytically tractable.
A deep understanding of multivariate Gaussians, their parameterizations, and the reparameterization trick is essential before proceeding to later chapters.
The univariate Gaussian is parameterized by mean and variance . The multivariate generalization replaces the scalar mean with a vector and the variance with a covariance matrix . In diffusion models, the covariance is typically isotropic: , meaning noise is added independently to each dimension with equal variance.
The Gaussian is the maximum entropy distribution for a given mean and variance — it makes the fewest assumptions beyond those two moments. In diffusion, isotropic noise treats all dimensions equally, which is essential: the forward process should not favor any direction in data space. The normalization constant ensures the density integrates to 1 over .
Write the PDF of a 2D isotropic Gaussian with mean and variance .
Any affine transformation of a Gaussian random variable remains Gaussian. This is fundamental to diffusion: the forward step is a linear combination of a Gaussian input and Gaussian noise, so is also Gaussian. This closure property allows us to compute in closed form for any without iterating through intermediate steps.
Closure means the family of Gaussians is preserved under affine maps: if , then . In DDPM, is affine in both and . Since both are Gaussian, is Gaussian with analytically computable moments — no simulation needed to characterize the distribution at any timestep.
If and where is independent, what is the distribution of ?
Sampling from is non-differentiable with respect to and . The reparameterization trick rewrites the sample as a deterministic function of the parameters plus fixed noise . This makes the sampling operation differentiable, enabling backpropagation through the sampling step. It is essential for training both VAEs and diffusion models.
Sampling is a stochastic operation with no gradient through or . The trick decomposes sampling into a deterministic differentiable path (multiply and add) plus fixed randomness (). The pathwise gradient and enable backpropagation through the sampling step — critical for training both VAEs and diffusion models.
Show how to compute gradients of with respect to using the reparameterization trick.
In the DDPM forward process, where . Derive this closed-form expression starting from the single-step transition .