ID-5-02 (TO) · Mathematical Foundations of Diffusion Models · Lecture 1 demo

The World's Smallest Diffusion Model

Two data points, one line of Bayes' rule, and a complete generative model — every step below is computed exactly, with no neural network anywhere.

Act I · ForwardNoise melts the data

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.

Density of the noised data pσ(x) N(0, 1+σ²)
Hover to read off x and pσ(x). The vertical scale re-normalizes as σ changes.

Act II · DenoiseBayes' rule hands us the optimal denoiser

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).

The optimal denoiser tanh(x/σ²) identity
Horizontal gridlines mark the two data points ±1 — the denoiser's only possible verdicts as σ → 0.

Act III · ReverseRun the diffusion backwards: noise becomes data

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.

64 particles · noise (top) → data (bottom) trajectories density pσ
The shaded field shows the shape of the exact density pσ(x), contrast-enhanced and rescaled at each noise level (brightness compares within a level, not across levels) — the trajectories follow its ridges down to the data. The vertical axis is the step index, so σ falls geometrically from 3 to 0.03.

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.