act.Algorithmic Creativity Team
Diffusion model lecture
Interactive course companion

Probability · Geometry · Generative processes

Diffusion Exploratorium

Follow Gaussian noise all the way to a concrete shape. See the noising process, inspect the score, and understand how reverse dynamics transport probability.

How does Gaussian noise become a shape?

Follow the same particles from an unstructured cloud to a star. Then open the mechanism: a noisy density, its score, and a sequence of small transport steps.

A WORKED EXAMPLE · SIX STEPS

Preparing a reproducible particle trajectory…

600 transported samplesTracked sampleTarget contour

Scrub to any solver step or play the full process. A path belongs to one sample; the complete cloud is a probability distribution. The selected shape determines the score used at every step.

One trajectory, six moments

Same seed · same particle identities · same spatial scale
01

Turn a shape into a probability distribution

The target tells the sampler what counts as a plausible outcome.

Grey: component centres μⱼ, equally spaced along the contour. Blue: independent samples from p₀. The faint circle shows one component’s 2σ₀ radius.

Choose M = 64 points μ₁,…,μM along the selected outline. Give each a small Gaussian neighbourhood with σ₀ = 0.08. The resulting smooth density concentrates around a recognizable contour:

p₀(x) = 1M ∑j=1M 𝒩(x; μj, σ₀²I),   x ∈ ℝ².

To sample it directly, draw a uniform component index J and z ∼ 𝒩(0,I), then set x₀ = μJ + σ₀z. The walkthrough uses these known components to compute a score exactly.

What is being generated? Each dot is one 2D sample. Many samples trace the shape. This is a diffusion model of a contour distribution; an image diffusion model instead treats an entire pixel or latent array as one sample.

The target has nonzero thickness. A perfectly thin curve would be a singular distribution with no ordinary smooth density on ℝ² at t = 0.

02

Erase structure with a known noising process

Learning the reverse direction begins with a forward process we can sample exactly.

Signal a = 1.000Noise σ = 0.000a² + σ² = 1

This slider reuses the same x₀ and ε at each t to compare marginals smoothly. It is a coupling of noisy snapshots, not a Brownian sample path. The Diffusion lab has full forward OU paths.

Use the variance-preserving Ornstein–Uhlenbeck process

dXt = −½Xtdt + dWt.

Its transition from a clean point is Gaussian. An integrating factor gives Xt = e−t/2X₀ + ∫₀ᵗe−(t−r)/2dWr; the integral has covariance (1−e−t)I. Thus each noisy marginal can be sampled as

xt = a(t)x₀ + σ(t)ε,   ε ∼ 𝒩(0,I),
a(t) = e−t/2,   σ(t)² = 1−e−t.

The signal shrinks while the Gaussian perturbation grows. Our Gaussian mixture stays analytically tractable:

pt(x) = 1/M ∑j 𝒩(x; aμj, vI),
v(t) = a²σ₀² + σ².

Keep the two variances separate: σ² is added noise conditional on x₀; v also includes the clean component’s thickness. As t → ∞, a → 0, σ → 1, and pt approaches 𝒩(0,I).

03

Use the score to read the noisy distribution

A noisy observation is ambiguous. The score combines all plausible clean explanations.

Noisy density pₜScore directionsProbe xₜConditional clean mean

Drag or click the plot; arrow keys move the probe. Shading is density divided by its maximum in this view. Arrow lengths are compressed. Grey links show the four strongest component responsibilities.

The score is the spatial gradient of log density:

st(x) = ∇x log pt(x).

For this mixture, Bayes’ rule gives a responsibility for each component. Differentiating the log of the mixture yields

wj(x,t) = exp(−‖x−aμj‖² / 2v)∑ℓ exp(−‖x−aμℓ‖² / 2v),
st(x) = [a∑jwjμj − x] / v.

The score pulls toward a weighted mean of plausible noisy components. At large t these overlap almost completely; at small t the weights become localized near the contour.

Why noise prediction learns this vector

∇x log q(x|x₀) = −(x−ax₀)/σ² = −ε/σ,
st(x) = 𝔼[−ε/σ | Xt = x].

A network trained with 𝔼‖ε−εθ(xt,t)‖² learns the conditional mean ε* = 𝔼[ε|xt] at the population optimum. Hence sθ ≈ −εθ/σ. This expectation, rather than the particular hidden noise realization, is what the squared-error objective identifies.

x̂₀(x,t) = 𝔼[X₀|x] = [x + σ²st(x)] / a.

The purple marker is this conditional clean mean. It can fall between modes, away from the contour. A one-shot conditional mean is generally not a sample from p₀; generation updates the noisy state over many noise levels. These identities use t > 0 and a > 0.

04

Take a small reverse step, then recompute

The sampler repeatedly asks for the score at the current location and current noise level.

In generation time u = T−t, the deterministic probability-flow velocity and stochastic reverse process are

bODE(x,t) = ½x + ½st(x),
dYu = [½Yu + st(Yu)]du + dBu.

The factor ½ on the ODE score is essential. The reverse SDE uses a full score and injects new noise; removing its noise without changing the drift gives the wrong density evolution.

What the numerical solver does

ODE predictor: x̃ = x + h bODE(x,t),
ODE corrector: x′ = x + ½h[bODE(x,t) + bODE(x̃,t−h)],
SDE update: x′ = x + h[½x+st(x)] + √h ξ,
ξ ∼ 𝒩(0,I),   h = t−t′ > 0.

The ODE uses Heun’s method; the SDE uses Euler–Maruyama. The quadratic grid tk = 12(1−k/480)² spends smaller steps near the narrow final density. Switch the dynamics above to see the different updates.

Read one step

Pause the main trajectory, choose a tracked sample, and press “One solver step.” Compare its drift, correction or noise, and actual displacement in the magnified view.

Local coordinates are displacements from the current sample. The zoom adapts to the step size. Blue is the drift prediction; violet is the correction (ODE) or random increment (SDE); orange is the next state.

Numerical values for the tracked sample
QuantityValue
05

Understand why moving particles transports probability

The reverse process is justified at the level of densities, not by a visual resemblance.

The forward OU process satisfies the Fokker–Planck equation:

∂tp = ½∇·(xp) + ½Δp.

Since p st = ∇p, this can be written as a continuity equation

∂tp + ∇·(p vt) = 0,
vt(x) = −½x − ½st(x).

Changing clocks reverses the velocity: bODE = −vt. Write ρu = pT−u; then ∂uρ + ∇·(ρbODE) = 0. If Φu is the ODE solution map,

(Φu)#pT = pT−u,
pT−u(Φu(z)) |det DΦu(z)| = pT(z).

This is the mathematical meaning of transport: the flow changes locations and local volume while preserving total probability. Along a path, d log ρu(Yu)/du = −∇·bODE.

Why the reverse SDE has the same marginals

Its drift is ½x+st, and its Brownian term adds ½Δρ. Substituting ρ = pt gives

−∇·[(½x+st)ρ] + ½Δρ
= −½∇·(xρ) − ½Δρ = −∂tpt.

Thus the exact SDE and ODE evolve the same laws from pT. Their individual paths differ; neither reconstructs the particular forward Brownian path.

Where Wasserstein geometry enters

The forward density is a W₂ gradient flow of

ℱ(ρ) = ¼∫ ‖x‖²ρ dx + ½∫ ρ log ρ dx,
∂tρ = ∇·(ρ∇[δℱ/δρ]).

It decreases ½KL(ρ‖𝒩(0,I)), up to a constant. Running the known density curve backward recovers structure. This generative flow is not generally a W₂ shortest path. The Wasserstein lab shows displacement interpolation and JKO steps separately.

Exact statements, Gaussian initialization, and numerical error

For this finite Gaussian mixture with σ₀ > 0, densities and scores are smooth on the finite time interval. The pushforward and matching-marginal identities assume exact scores, initialization from pT, and exact integration. The application uses a finite solver and finite samples.

The default instead starts from an exact standard Gaussian. At finite T = 12, pT has a tiny remaining trace of the data distribution. Coupling XT = aX₀ + σZ with Z ∼ 𝒩(0,I), independent of X₀, gives

W₂(pT, 𝒩(0,I))² ≤ a²𝔼‖X₀‖² + 2(σ−1)².

This bounds the initial discrepancy, not its amplification by the reverse solver. “Exact noisy marginal” starts from the analytic p₁₂ and removes this discrepancy. In practical diffusion models, a learned score, a finite noise schedule, and numerical integration each contribute approximation error.

06

From a two-dimensional contour to an image

The structure of the algorithm stays the same; the data space and score model become much larger.

StageThis exact, inspectable exampleAn image diffusion model
Represent datax₀ ∈ ℝ²; a cloud concentrates near a contour.x₀ ∈ ℝH×W×C in pixel space, or a learned latent array. One sample represents a complete image.
Add Gaussian noisext = a(t)x₀ + σ(t)ε.xk = √ᾱkx₀ + √(1−ᾱk)ε, with independent Gaussian entries.
Estimate the noiseCompute mixture responsibilities and the exact score.Train εθ(xk,k,c) on many noisy examples; c may encode a condition such as text.
Sample repeatedlyEvaluate a time-dependent score and advance the ODE or SDE.Apply a reverse diffusion sampler with the trained prediction at each noise level.
Read the outputMany 2D points reveal the target’s contour.A pixel array is the image; a latent array first passes through its trained decoder.

A standard discrete reverse mean

Let αk = 1−βk and ᾱk = ∏j≤kαj. A common DDPM parameterization uses

μθ(xk,k) = 1√αk[xk − βk√(1−ᾱk) εθ(xk,k)],
xk−1 = μθ(xk,k) + σk,revz.

The reverse variance is a sampler choice. One common fixed choice is β̃k = βk(1−ᾱk−1)/(1−ᾱk); implementations omit the final random increment. This discrete formula is explained here, while the live demo implements the continuous-time OU model.

What has actually been learned?

A trained network encodes a data prior through its denoising predictions. Noise alone does not contain a predetermined star, face, or scene. Here the target menu supplies that prior explicitly; in image models, training data and conditions determine it.

Repeated updates keep a sample compatible with a sequence of noisy distributions. Coarse organization becomes visible before fine details, but this is not simply subtracting a stored noise image or interpolating linearly to a chosen target.

This page runs the complete 2D sampling calculation locally. It contains no pretrained image network. The exact mixture makes the mechanism visible without hiding the score inside a neural model.
Check your understanding
  1. At a large noise level, why does the score resemble −x?
  2. Why can the conditional clean mean lie outside the target contour?
  3. What goes wrong if you remove noise from the reverse SDE and keep its full-score drift?
  4. Which assumptions are needed to claim (ΦT)#pT = p₀?

Answers: the noisy law approaches a standard Gaussian; conditional means average competing explanations; the diffusion term disappears without the compensating half-score change; and exact scores, consistent initialization, a well-defined flow, and exact integration are required.

Mathematical framework: Ho, Jain & Abbeel, DDPM (2020); Song et al., Score-based SDEs (2021). The mixture target, live score derivation, and numerical walkthrough are original teaching implementations.