ID-5-02 (TO) · Mathematical Foundations of Diffusion Models · Lecture 1 demo
Two data points, one line of Bayes' rule, and a complete generative model — every step below is computed exactly, with no neural network anywhere.
Our entire dataset is two points, x₀ = −1 and x₀ = +1, equally likely. Corrupt a sample with Gaussian noise, xσ = x₀ + σz with z ∼ N(0,1). The density of the corrupted data is a two-bump mixture:
pσ(x) = ½ N(x; −1, σ²) + ½ N(x; +1, σ²).
Drag σ (or press Play) and watch the two spikes melt into a single Gaussian. By σ ≈ 3 the mixture is indistinguishable from N(0, 1 + σ²) — all structure destroyed, destination fully known.
Now the inverse problem: you observe a noisy xσ — what was the clean point? The best guess (in mean-squared error) is the posterior mean, and for a two-point prior it comes out in closed form:
E[x₀ | xσ = x] = tanh(xσ²).
The optimal denoiser is a tanh — an activation function every ML student knows, produced here by nothing but Bayes' rule. At small σ it is a hard threshold (snap to the nearer point); at large σ it shrinks everything toward 0 (the noise is too loud to trust the observation).
Start particles from pure noise at σmax = 3 and lower σ step by step, each time nudging every particle in the direction its denoiser suggests:
y ← y + σk² − σk+1²2 · tanh(y/σk²) − yσk²
The cloud splits and condenses onto the two data points −1 and +1: generation. The deterministic rule is the probability-flow ODE; the stochastic variant re-injects noise at every step (the reverse-time SDE) and lands in the same place.
The whole course in one demo. For images, the posterior mean E[x₀ | xσ] has no formula — training a network to predict the clean sample (equivalently, the noise) from the noisy one is precisely how that tanh gets replaced. Everything else — the forward melt, Bayes, the reverse flow — survives unchanged.