Sampling Algorithm: Ancestral Sampling
You'll learn how diffusion models generate images by gradually removing noise step-by-step, walking backward through the entire diffusion process.
What Is Ancestral Sampling?
Ancestral sampling is the standard algorithm for generating images from a trained diffusion model. Starting from pure Gaussian noise (the final timestep T), you iteratively apply your learned denoising network at each timestep going backward (T → T-1 → T-2 → ... → 0), progressively refining the noise into a clear image.
The term "ancestral" refers to following the Markov chain backward through its ancestry—each step depends only on the previous one.
How It Works
- Start with pure noise: Sample x_T ~ N(0, I)
- Loop backward through timesteps t = T, T-1, ..., 1:
- Use your denoising network to predict the noise at timestep t
- Remove some of that predicted noise
- Add back a small amount of random noise (unless t=0)
- Result: At t=0, you have your generated image x_0
Why Add Noise Back?
This is the stochastic part! Each reverse step isn't deterministic—you add a controlled amount of fresh Gaussian noise to maintain the proper distribution. This preserves diversity in generated samples and follows the learned reverse process distribution correctly.
Think of it like sculpting: you're chiseling away randomness step-by-step, but at each stage you add tiny random variations to keep the result natural and varied, not rigid.
The Algorithm Loop
For each timestep backward, you compute the previous state using your network's prediction and the variance schedule (those beta values), then inject fresh randomness scaled appropriately for that step.
Key Takeaway: Ancestral sampling generates images by iteratively denoising from pure noise through all timesteps, adding small amounts of stochasticity at each step to preserve sample diversity.