VAE and diffusion: two different learning problems
Work a Gaussian KL, reparameterize a latent, and distinguish corruption from denoising.
Preparation: Means, noise and squares; probability densities for college.
Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.
FULL LOCAL NARRATION
Follow the complete explanation.
Narration includes worked solutions. Pause at each practice prompt before continuing. Formula notation has a spoken explanation; all teaching text remains readable.
High-school path. Work a Gaussian KL, reparameterize a latent, and distinguish corruption from denoising.
Preparation: Means, noise and squares; probability densities for college. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.
An autoencoder maps an input into a smaller representation and tries to reconstruct it. A variational autoencoder represents a distribution of possible latent codes rather than only one fixed code. Diffusion learns to reverse a specified corruption process. These ideas can be combined, but they are different jobs. A latent diffusion system may first encode an image, then learn a diffusion process in that latent space.
Worked step 1. Encoder: input x becomes parameters of a latent distribution.
Worked step 2. Decoder: a sampled latent z produces a reconstruction distribution.
Worked step 3. Diffusion: a clean sample is progressively corrupted and a reverse process is learned.
Try it yourself. Does training a VAE automatically train a diffusion denoiser?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. The models solve different objectives. A combined system needs the relevant components trained or supplied separately.
Section 02 / 07
Balance reconstruction and the latent prior
A VAE should reconstruct useful details, but it also encourages its latent distributions to stay related to a simple prior. One loss term penalizes poor reconstruction. Another, called KL divergence, measures a mismatch between distributions. In a loss that we minimize, both appear with the appropriate positive sign. Making reconstruction perfect by ignoring the latent structure, or matching the prior while ignoring the image, can each be unhelpful.
Worked step 1. Write a reconstruction penalty that decreases when the decoder fits the input.
Worked step 2. Add the posterior-to-prior KL term for negative ELBO.
Worked step 3. Check whether your code minimizes loss or maximizes a bound before choosing signs.
−ELBO = E_q[−log p(x|z)] + KL(q(z|x)||p(z))
Negative ELBO is expected negative reconstruction log likelihood plus posterior-to-prior KL divergence.
Try it yourself. Why is subtracting a nonnegative KL from a minimized reconstruction loss suspicious?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. It would reward increasing that divergence under the basic negative-ELBO objective. Always check objective direction and the intended variant.
Section 03 / 07
Compute one Gaussian KL
Consider a latent bell curve with mean one and spread one, compared with a standard bell curve centered at zero. Their spreads match but their centers differ. The one-dimensional KL is one half in this example. If both mean and spread match the prior, the KL becomes zero. The formula uses variance, which is the square of standard deviation. Mixing up those two quantities changes the answer.
Worked step 1. Set μ=1 and σ²=1.
Worked step 2. Compute 0.5×(1+1−1−0)=0.5.
Worked step 3. Set μ=0 with the same variance to obtain zero.
KL = ½(μ²+σ²−1−log σ²)
Half the sum of mean squared and variance, minus one and log variance.
Try it yourself. What is the KL at μ=0 and variance four?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. One half times four minus one minus log four, approximately 0.8069. It is positive despite the matching mean.
Section 04 / 07
Move randomness into a standard sample
To sample from a bell curve with mean μ and spread σ, start with a standard random draw ε, multiply by σ, and add μ. For mean one, spread two and draw minus one half, the result is zero. This rewrite makes the learned mean and spread explicit in the calculation. It helps a training system track how changing them changes the sampled latent and the reconstruction.
Worked step 1. Choose μ=1, σ=2 and ε=−0.5.
Worked step 2. Multiply two by minus one half to get minus one.
Worked step 3. Add the mean one to obtain z=0.
z=μ+σ⊙ε; ε~N(0,I)
Sample standard normal noise, scale it by standard deviation and add the mean.
Try it yourself. If the network outputs log variance, should you exponentiate it directly to get standard deviation?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. Exponentiating log variance gives variance. Standard deviation is the exponential of half the log variance.
Section 05 / 07
Forward noise uses sampled noise
Diffusion training creates a corrupted sample from a clean one and fresh random noise. It does not use the model's predicted noise to create the training target. With cumulative signal fraction 0.64, the signal coefficient is 0.8 and the noise coefficient is 0.6. The square roots matter because the fractions describe variance. The denoiser then tries to infer information about the corruption from the noisy sample and its time step.
Worked step 1. Set x₀=1, ᾱ=0.64 and ε=−1.
Worked step 2. Compute 0.8×1+0.6×(−1)=0.2.
Worked step 3. The known training noise is minus one, even before the denoiser makes a prediction.
x_t=√ᾱ_t x₀+√(1−ᾱ_t)ε
Multiply the clean signal by the square root of cumulative alpha and noise by the square root of one minus cumulative alpha.
Try it yourself. Why are 0.64 and 0.36 not the coefficients used directly here?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. They are variance fractions. The amplitude coefficients are their square roots, 0.8 and 0.6.
Section 06 / 07
Separate an oracle check from generation
If you know the exact noise used to corrupt a sample, you can undo this equation algebraically. A real model does not know that hidden noise; it predicts from the noisy input. Workbench first checks the algebra with known numbers. That is useful, but it is not evidence that a trained generator can recover any original image. Generation begins with noise and follows a learned sampling process, often making many steps.
Worked step 1. From x_t=0.2 and ε=−1, add 0.6 to recover 0.8.
Worked step 2. Divide by 0.8 to recover x₀=1.
Worked step 3. An imperfect predicted noise would produce a different reconstruction.
Try it yourself. Does exact recovery with known noise prove the denoiser is accurate?
Pause the recording and write your reasoning before continuing. The worked solution follows.
Reveal worked solution
Worked solution. No. It checks algebra with information the model does not receive. Learned prediction quality requires separate evaluation.
Section 07 / 07
Mastery and transfer
Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.
Forward corruption uses… Option 1: Fresh sampled noise. Option 2: Only the model’s predicted noise. Option 3: No randomness.
Pause here and choose an answer before continuing. The checkpoint explanation follows.
Reveal worked solution
The correct choice is option 1: Fresh sampled noise. The training corruption is constructed with sampled noise.
Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.
Reveal worked solution
Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.
WORKBENCH / PREDICT → TEST → EXPLAIN
Inspect exact numerical data
These are computed teaching fixtures. No remote AI model or GPU is called by the experiment.
CHECK YOUR UNDERSTANDING
Commit to an explanation.
Keep your learning record.
Sources and scope
Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.