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

Sampling as a Map

Generative AI in its simplest form: first generate by ancestral sampling (flip a coin, then draw), then discover the same generator is a single deterministic map applied to uniform randomness.

Act I · HierarchyConditional generation: coin first, Gaussian second

A hierarchical latent-variable model — the simplest conditional generator:

P(z = 1) = π,   P(z = 2) = 1 − π,   x | z ∼ N(μz, σ²)

Sample the latent coin z, then sample x from the chosen component. The colors below remember each sample's ancestry — and the marginal that emerges is exactly the two-component mixture p(x) = π N(x; μ₁, σ²) + (1−π) N(x; μ₂, σ²).

Ancestral sampling · histogram colored by latent z z = 1 (prob π) z = 2 (prob 1−π)
Press Sample one a few times — watch the coin, then the draw.
Generation runs the hierarchy forward: z → x. Inference runs it backward: given x, the posterior P(z | x) — for μ = ±1 and π = ½ that posterior mean was exactly W01's tanh denoiser.

Act II · The mapThe same generator as one deterministic function

Now remove the coin. Take a single uniform number u ∼ Uniform(0, 1) and push it through the inverse of the cumulative distribution function:

x = F⁻¹(u),   F(x) = π Φ((x−μ₁)/σ) + (1−π) Φ((x−μ₂)/σ)

Below, uniform points enter on the vertical axis, travel to the curve u = F(x), and drop to the x-axis. The histogram they build is the same mixture — no coin anywhere. Now slide σ → 0: the curve becomes a staircase, and the map becomes x = sign(u − π) — W01's two-point dataset, generated by thresholding a uniform.

u = F(x) · uniform in (left axis) → data out (bottom axis) uniform input CDF F
· uses the same π, μ₁, μ₂, σ sliders as Act I
The flat plateau of F (height π, between the bumps) is the empty region: no u lands there.
The staircase limit: at σ ≈ 0.05 the curve is two jumps and a plateau — every u below π maps to μ₁, every u above maps to μ₂. Pure sampling has become a deterministic formula.

The idea hiding in this demo. Once all of its random draws are exposed, a generative sampler is a deterministic map from base randomness to a sample. Here the map is explicit because the CDF is known (this page inverts it numerically). Deep generative models learn an ingredient of the map: GANs push Gaussian noise through a network; VAEs add decoder noise; normalizing flows make the map invertible; and W01's probability-flow ODE is exactly such a map — from a Gaussian to the data — built from a learned denoiser. That family is where this course is headed.