00 · Introduction and Motivation
The first note of the course. It says what the subject is, what the rest of the material is for, and then earns the claim that organises everything with the smallest possible example. Interactive version: Sampling as a Map.
What this course is about
A generative model is a thing that produces samples. Show it a pile of handwritten digits and it should produce new handwritten digits — not ones from the pile, and not noise, but plausible new members of the same population.
The difficulty is that nobody hands you the population. You get a finite pile of examples, and from that pile you must build something that can generate more. Put formally: given samples \(x_1,\dots,x_n\) drawn from an unknown \(p_{\text{data}}\), construct a procedure that draws fresh samples from something close to \(p_{\text{data}}\).
Two observations shape everything that follows.
Sampling is not the same as knowing the density. You do not need a formula for \(p_{\text{data}}(x)\) in order to draw from it, and — as the course will show — for images you could not write one down anyway. What you need is a procedure.
Every such procedure turns simple randomness into structured output. Somewhere in the machine there is a coin flip, a uniform draw, or a burst of Gaussian noise, and everything downstream of it is arithmetic. That is the picture this note builds, and the rest of the course is about how to learn the arithmetic when the target is complicated.
The route, in one paragraph
We start with probability itself — random variables, joints, conditionals, Bayes — because generation runs forward from a latent cause to an observation while inference runs backward, and Bayes is the bridge. Then distributions and maximum likelihood in one dimension, where fitting has closed forms. Then the multivariate Gaussian, the one family closed under everything linear, which is why every tractable calculation in this subject goes through it. Then the wall: in high dimension, estimating a density directly stops working, even with structure. That failure is what forces the modern approach — stop describing distributions and start comparing them, which is why distances and divergences become central. Diffusion models are then one particular, very effective answer.
How the material is organised
Lecture Notes are the numbered spine, in reading order, and follow the lectures. Tutorials sit alongside and go deeper on one thing. The Curriculum page lists the sequence and maps it to weeks.
Where to start
Read this note, then 01 · The World’s Smallest Diffusion Model, which builds a complete working diffusion model on a dataset of two points, with every step in closed form. Nothing in it is approximated and nothing is learned — which makes it the clearest possible statement of what we are trying to do in high dimensions, and of exactly which step stops being computable once the data is images rather than two numbers.
The simplest generative model there is
The rest of this note presents one tiny generator twice — first as a hierarchy you sample conditionally (a Bayesian model), then as a deterministic map applied to uniform randomness — and then makes the claim that carries the rest of the course: every modern generative sampler, diffusion included, is the second picture, once all of its random inputs are exposed, with a learned ingredient in place of the formula.
View 1: conditional generation (a hierarchical model)
The simplest latent-variable model:
\[ \mathbb{P}(z = 1) = \pi, \quad \mathbb{P}(z = 2) = 1 - \pi, \qquad x \mid z \;\sim\; \mathcal{N}(\mu_z,\, \sigma^2). \]
Ancestral sampling generates by following the arrows: draw the latent coin \(z\), then draw \(x\) from the selected component. The observed marginal is obtained by summing out the latent:
\[ p(x) \;=\; \sum_{z} p(z)\, p(x \mid z) \;=\; \pi\, \mathcal{N}(x; \mu_1, \sigma^2) + (1-\pi)\, \mathcal{N}(x; \mu_2, \sigma^2) \]
— exactly the two-component mixture from the playground. A mixture is not just a formula; it is a generative story: population \(\to\) subpopulation \(\to\) individual.
Inference is the same hierarchy, run backwards. Given an observed \(x\), Bayes’ rule gives the posterior over the hidden coin:
\[ \mathbb{P}(z = 1 \mid x) = \frac{\pi\, \mathcal{N}(x; \mu_1, \sigma^2)} {\pi\, \mathcal{N}(x; \mu_1, \sigma^2) + (1-\pi)\, \mathcal{N}(x; \mu_2, \sigma^2)} . \]
For \(\mu_{1,2} = \mp 1\) and \(\pi = \tfrac12\) this equals \(\operatorname{sigmoid}(-2x/\sigma^2)\); its companion \(\mathbb{P}(z = 2 \mid x) = \operatorname{sigmoid}(2x/\sigma^2)\) is exactly the posterior W01 computed for the \(+1\) component, and the posterior mean of \(\mu_z\) is the tanh denoiser: W01’s denoising step was latent-variable inference all along. Generation and inference are the two directions of one arrow.
View 2: the coin disappears into a map
Theorem (inverse-CDF / probability integral transform). Let \(F\) be a CDF with generalized inverse \(F^{-1}(u) = \inf\{x : F(x) \ge u\}\), and let \(U \sim \text{Uniform}(0,1)\). Then \(X = F^{-1}(U)\) has CDF \(F\).
Proof. \(\mathbb{P}(F^{-1}(U) \le x) = \mathbb{P}(U \le F(x)) = F(x)\), since \(F^{-1}(u) \le x \iff u \le F(x)\) by monotonicity. \(\square\)
For our mixture, \(F(x) = \pi\,\Phi\!\big(\tfrac{x-\mu_1}{\sigma}\big) + (1-\pi)\,\Phi\!\big(\tfrac{x-\mu_2}{\sigma}\big)\) is continuous and strictly increasing, so \(F^{-1}\) is an honest function, and
\[ u \sim \text{Uniform}(0,1), \qquad x = F^{-1}(u) \]
generates the mixture with no coin anywhere — the explicit coin has been marginalized out. One caution about where it went: under this map, the event \(u < \pi\) selects the lowest \(\pi\)-fraction of the mixture distribution, which is not the same as the ancestral label \(z = 1\) when the components overlap — both Gaussians have full support, so each contributes on both sides of any quantile. (In the well-separated limit \(\sigma \to 0\) the two events do coincide, and the packed map below is the construction in which \(u < \pi\) genuinely encodes the coin.) Randomness in, structure out, everything in between deterministic.
The two-point limit
Send \(\sigma \to 0\) with \(\mu_{1,2} = \mp 1\). The CDF collapses to a staircase: a jump of height \(\pi\) at \(-1\), a flat plateau at height \(\pi\) across the empty middle, a jump to \(1\) at \(+1\). The map becomes
\[ x = \begin{cases} -1, & u < \pi \\ +1, & u > \pi \end{cases} \qquad\text{i.e.}\quad x = \operatorname{sign}(u - \pi), \]
W01’s dataset, generated by thresholding a uniform (almost surely: the single point \(u = \pi\) has probability zero). The plateau is the geometric image of the empty region: no value of \(u\) lands there. The map is the inverse CDF for this discrete distribution. (In the demo, slide \(\sigma\) down and watch the staircase form.)
Maps are not unique
\(F^{-1}\) is the monotone map pushing \(\text{Uniform}(0,1)\) to \(p\), but not the only map. The “packed” two-stage construction
\[ x = \begin{cases} \mu_1 + \sigma\, \Phi^{-1}\!\big(u/\pi\big), & u < \pi,\\[2pt] \mu_2 + \sigma\, \Phi^{-1}\!\big(\tfrac{u-\pi}{1-\pi}\big), & u \ge \pi, \end{cases} \]
also pushes uniform to the mixture (each branch rescales its segment of \([0,1]\) back to a full uniform — Exercise 3), and it is literally ancestral sampling written as one formula. Different map, same distribution: what is canonical is the distribution, not the transport. (In higher dimensions, choosing among the many maps is its own subject — optimal transport — which we will brush against later.)
The claim that organizes everything
Once all of its random draws are exposed, a generative sampler is a deterministic map from base randomness to a sample.
| Model | Random input(s) | Sampling mechanism | Typical fitting |
|---|---|---|---|
| This note | \(u \sim \text{U}(0,1)\) | quantile \(F^{-1}(u)\) (numerical in the demo) | the CDF is known |
| GAN | \(z \sim \mathcal{N}(0, I)\) | \(G_\theta(z)\), a network | adversarial objective |
| VAE | \(z\), plus decoder noise \(\varepsilon\) | sample \(p_\theta(x \mid z)\), i.e. \(T_\theta(z, \varepsilon)\) | ELBO / variational learning |
| Normalizing flow | \(z \sim \mathcal{N}(0, I)\) | invertible \(f_\theta(z)\) | exact likelihood (change of variables) |
| Diffusion | \(x_1 \sim \mathcal{N}\); step noise if stochastic | probability-flow ODE (deterministic) or reverse SDE | score/denoising objectives, ELBO |
The outer skeleton is shared — simple randomness, a sampling mechanism, data — while the learned object, the structural constraints, and the sampler differ. For diffusion in particular, determinism is a sampler choice: the probability-flow ODE is a deterministic map from \(x_1\); the reverse SDE consumes fresh noise at every step and is a deterministic function only of \((x_1, \text{all step noises})\).
In one dimension with a known CDF, the map is a formula. For images, the population law is unknown and no tractable multivariate inverse-CDF construction exists — so deep generative models learn a transport, density, score, or other ingredient of a sampler rather than writing the map down. And you have already run one: W01’s probability-flow ODE numerically transported a moment-matched Gaussian to within \(\approx \sigma_{\min}\) of the two-point data (W01 lists the approximations involved); with the exact terminal law, score, and integration, it is an exact deterministic transport — an inverse-CDF-like map built not from the CDF but from the score, which is exactly the object a neural network can learn in high dimension. That construction, done properly, is Modules 4–6.
Exercises
- Complete the inverse-CDF proof for a general (possibly non-strictly-increasing) \(F\) using the generalized inverse.
- Derive \(\mathbb{P}(z = 1 \mid x)\) above, and show that for \(\mu_{1,2} = \mp 1\), \(\sigma = 1\), \(\pi = \tfrac12\) its companion \(\mathbb{P}(z = 2 \mid x)\) equals W01’s \(\operatorname{sigmoid}(2x)\) posterior (mind which component carries the \(+\) sign); compute the posterior mean of \(\mu_z\).
- Verify the packed map: show that conditional on \(u < \pi\), the rescaled variable \(u/\pi\) is \(\text{Uniform}(0,1)\), and conclude that the branch produces \(\mathcal{N}(\mu_1, \sigma^2)\) with the correct probability.
- Construct the inverse-CDF map for a three-component mixture and describe its staircase limit as \(\sigma \to 0\). How many plateaus, at what heights?
- The map \(x = F^{-1}(u)\) is monotone increasing. Exhibit a decreasing map with the same pushforward, and a map that is neither monotone nor continuous. (Hint: \(1 - u\) is also uniform.)