Equations · Kingma and Welling, “Auto-Encoding Variational Bayes” (2014)
The reparameterization trick (z = μ + σ ⊙ ε), explained
A VAE's encoder outputs a Gaussian over latent codes, and the loss needs a sample from it. Sampling directly would block backpropagation, since you cannot differentiate through a random draw. The trick draws standard noise separately, then builds the sample as a differentiable function of the encoder's outputs.
Term by term
The mean and standard deviation of the encoder's Gaussian , one entry per latent dimension. Encoders usually output and exponentiate, to keep positive.
Standard normal noise, independent of the parameters. All the randomness lives here. is a random vector, not a small constant.
Epsilon · Distributed as (tilde) · Normal distribution · Identity matrix
Elementwise product: each noise entry scaled by its dimension's standard deviation.
The latent sample, distributed as , exactly as if drawn directly. Now and , so gradients reach the encoder.
A small worked example
One latent dimension: , , drawn . Then . If the loss has gradient with respect to , the encoder receives for and for .
In code
import torch
def reparameterize(mu, logvar):
std = torch.exp(0.5 * logvar) # sigma from log sigma^2
eps = torch.randn_like(std) # the randomness, outside the graph
return mu + std * epsEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)