Probability You Can See: Densities, Sampling & Expectation
Random variables, densities, and the idea that an expectation is just an average over samples โ the Monte-Carlo lens we use everywhere.
๐ // generative ai series ยท 2 of 20 modules live
A build-from-scratch journey through modern generative modeling which includes diffusion, score matching, and flow matching, derived from first principles, implemented in code, and made interactive so intuition sticks. This is a deliberately learner-first reordering: we build the probability you need first, go DDPM-first before any SDEs, live in 1-D/2-D where you can see the math, and arrive at flow matching as the payoff. It doubles as the backbone of a lecture I'm giving in Fall 2026.
// part 0 ยท Foundations you can see
Random variables, densities, and the idea that an expectation is just an average over samples โ the Monte-Carlo lens we use everywhere.
The Gaussian is the workhorse of generative modeling. Here's everything you need โ mean, covariance, and the one trick (x = ฮผ + ฯฮต) that makes diffusion trainable.
How distributions combine and decompose: joint densities, conditioning (slicing) and marginalizing (averaging) โ the grammar of probabilistic models.
Likelihood, cross-entropy, and KL divergence โ why fitting a distribution means minimizing KL, and what that buys us.
Transforming densities (the Jacobian and pushforwards) and a first, geometric look at the score gradient of log-density โ the compass diffusion follows.
Velocity fields and Euler integration, then an SDE is an ODE plus noise โ the minimal dynamics needed to flow a density from noise to data.
// part 1 ยท The core idea โ discrete & concrete
The one idea behind every diffusion model โ gradually destroy structure with noise, then learn to undo it โ with an interactive forward-diffusion explorable to build intuition.
The Gaussian Markov chain, the closed-form forward marginal, and how the noise schedule controls how fast structure is destroyed.
The reverse Gaussian, predicting the noise epsilon, and the simplified training loss โ why a denoiser is all you need, from scratch.
Ancestral sampling from noise to data, your first generated samples on 2-D toys (and MNIST), and what the reverse trajectory looks like.
// part 2 ยท The continuous view โ score & SDEs
Denoising score matching and Tweedie's formula โ why predicting noise is the same as estimating the score, with a visual of the learned score field.
The forward VP/VE SDE, Anderson's reverse-time SDE, and how DDPM is just a discretization of a continuous process.
The deterministic ODE with the same marginals as the SDE โ DDIM, sampler choices, and the step-count vs quality trade-off.
// part 3 ยท Flow matching โ the unifying view
Continuous normalizing flows and the likelihood bottleneck, then the flow-matching idea: just regress a velocity field.
Conditional probability paths and vector fields, and the marginalization trick that makes flow matching trainable without simulating the flow.
Recovering diffusion from the flow-matching lens, and straightening paths (rectified flow / OT) for faster, cleaner sampling.
// part 4 ยท Making it real
Conditioning on prompts and labels and the classifier-free guidance trick โ plus the quality-vs-diversity trade-off you can dial.
Time embeddings, U-Nets and Diffusion Transformers, and why moving to a VAE latent space made high-resolution generation practical.
Samplers, EMA, numerical stability, and how we actually measure generative models (FID, likelihood) โ plus the failure modes to watch for.
Diffusion beyond pixels: continuous-time Markov chains for language, and diffusion for molecules and protein structure.