4.5.3 · D1Generative Models

Foundations — Variational Autoencoders (VAE) theory

2,513 words11 min readBack to topic

The parent note on VAE theory moves fast — it assumes you already read its vectors, distributions, averages, integrals, and divergences fluently. This page slows all the way down and earns each of those symbols from nothing. We introduce them one at a time, in an order where every symbol depends only on the ones already defined. Nothing below is used before it appears in its own boxed definition.


1. Data as a point in a huge space:

The picture. Imagine every image you could ever draw. A image has pixels, so it is a single point in a space with axes. You cannot draw axes, so we always pretend it is a 2D or 3D space — one dot = one whole image.

Why the topic needs it. VAEs are generative: we want to invent new points that look like they came from the same cloud of real data. So we must first agree that a data example is a point in a space. The bold font just says "this is a vector, not a single number."


2. The hidden cause: latent variable

The picture. Squeeze the giant -cloud down onto a tiny 2D map. Nearby points on the map should decode to similar images. That tiny map is the latent space, and a point on it is .

Why the topic needs it. The whole latent variable model idea is: "data is complicated, but it was generated from a few simple hidden causes." Learning those causes gives us knobs to turn to generate new data. See Latent Variable Models for the general framework.


3. Uncertainty: probability distributions and

Everything in a VAE is probabilistic — the model never says "the answer is exactly this," it says "here is a spread of plausible answers." So we need the language of distributions.

The picture. A hill. Tall where values are common, flat where they are rare. The whole hill has area .

Why the topic needs it. The VAE's generative story is written entirely in these: sample , then sample . The squiggle means "is drawn at random from."


4. The all-ones diagonal: identity matrix

Before the bell curve, we need one small piece of bookkeeping notation it will lean on.

The picture. For two dimensions, Diagonal "how much each axis wiggles"; off-diagonal "how much axes wiggle together" — here, zero.

Why the topic needs it. VAEs assume the latent dimensions are independent — turning one knob does not drag another. That independence is exactly what the s in encode, which is why the prior is written once we meet the Gaussian next.


5. The bell curve: Gaussian

Why this distribution and not another? Three reasons the parent note names:

  1. Convenient math — sums and divergences of Gaussians have clean closed forms (no messy integrals to approximate).
  2. Infinite support — every point has nonzero probability, so the latent map has no forbidden regions; you can decode anywhere.
  3. Central Limit Theorem — pile up many small random effects and the total tends to a Gaussian, so it is a natural default.

6. The average machine: expectation

The picture. Sample a million times from the hill , compute each time, and take the plain average. Common values of pull the average toward their .

Why the topic needs it. Every VAE loss term is an average of the form — "average reconstruction quality over the codes the encoder suggests." Training estimates this average with just a few samples (Monte Carlo). Understanding as "weighted average" is the key to reading every loss term you will meet later.


7. The integral — and why it is "intractable"

The picture. Slice the hill into thin vertical strips, measure each strip's area, add them all up.

Why "intractable" in the parent note. The marginal is To compute it you must visit every and ask "could this code have made ?" In a -slot or even -slot latent space, there are effectively infinite to check — no computer can sum them all. This impossibility is the entire reason VAEs exist: they dodge the integral with an approximation. That approximation is inference, formalised in the Evidence Lower Bound.


8. The logarithm — why it appears everywhere

Why this tool. Likelihoods multiply across a dataset (), giving astronomically small numbers. Taking converts that product into a sum that a computer can actually add without rounding to zero. It also linearises the Gaussian's exponential, exposing the clean quadratic terms you see in the KL derivation.


9. Comparing two distributions: KL divergence

The picture. Two bell curves. When they sit on top of each other, . Slide one away or squash its width and climbs.

Why the topic needs it. The VAE's regularization term is — it pulls the encoder's output toward the standard Gaussian prior, keeping the latent map smooth and gap-free. Full details in Kullback-Leibler Divergence.


10. Two networks and their parameters: and

The picture. An hourglass: data funnels down through the encoder into the narrow waist , then fans back out through the decoder into a reconstruction .

Why the topic needs it. Training adjusts and together to maximize the Evidence Lower Bound. is the inference machine (approximate posterior); is the generator.


Prerequisite map

Data as vector x

Latent variable z

Probability density p

Gaussian N mu sigma

Identity matrix I

Expectation E

Integral over z

Evidence Lower Bound

Intractable marginal p x

Logarithm base e

Jensen inequality

KL divergence

Encoder q phi

Reparameterization

VAE training objective


Equipment checklist

Test yourself — reveal only after answering aloud.

What does bold represent, and how is it different from ?
is one whole data example written as a vector; is a single coordinate (e.g. one pixel) of it.
What is the latent variable , and why is it smaller than ?
A short vector of hidden causes summarising ; smallness forces the model to keep only meaningful structure.
Read in plain words.
The distribution of data given a fixed latent code — the decoder's output.
What do the diagonal and off-diagonal entries of encode in ?
Diagonal s = each dimension has spread ; off-diagonal s = dimensions are uncorrelated (independent).
What do and control in ?
is the center of the bell; is its width (and the variance).
Give three reasons a Gaussian prior is chosen.
Convenient closed-form math; infinite support (no gaps); Central Limit Theorem makes it a natural default.
What does compute?
The average of weighted by how likely each is under .
Why is the marginal intractable?
It sums over every possible high-dimensional — effectively infinite, uncomputable exactly.
Which base is the in VAE formulas, and why does it matter?
Natural log, base ; it cancels cleanly with the Gaussian's exponential, and mixing bases rescales the KL term by a wrong constant.
State the two defining facts about .
It is always (zero iff ) and is not symmetric.
Why can't ordinary backprop flow through the sampling of , and what fixes it?
Random sampling is not differentiable; the reparameterization trick moves the randomness into so gradients flow through .
Which network do and parameterize?
= encoder ; = decoder .