Summary
A variational autoencoder fits a latent-variable model using approximate posterior inference. Its encoder estimates latent uncertainty for observed data; its decoder specifies an observation distribution, not merely a reconstructed mean.
Task: observe under and . Use approximate posterior , where the second argument denotes variance. Compute the training bound and compare it with the exact log-likelihood. This scalar teaching model is solvable; neural models often make the marginal integral difficult.
The model
Generally, and the encoder is . Parameters define the generative model; defines its approximate inference network. One encoder shares inference parameters across observations: amortization does not make each inferred posterior exact.
Read the training lane and generation lane as different computations.
One model, two execution paths
Generation samples the prior without an observed input or encoder
Derivation
Which latent source is used when no observed input exists?
The ELBO
For these everywhere-positive Gaussian densities, insert and apply Jensen’s inequality:
Call the final expression , the evidence lower bound, or ELBO. Bayes’ rule also gives the exact gap identity:
The penalty inside compares with the prior; the gap compares with the model posterior. These are different distributions.
For the fixture, . For a Gaussian encoder with mean and variance , the prior KL is .
| Quantity, natural-log units | Calculation | Value |
|---|---|---|
| Expected reconstruction log density | ||
| Prior KL | ||
| ELBO | Reconstruction minus prior KL | |
| Exact log-likelihood, |
The exact posterior is . Directly computing its KL from gives , exactly the likelihood-minus-bound gap.
Improve inference variance
New task: change ‘s variance from to the exact posterior variance . Update both reconstruction and prior KL, not just the penalty. Check: reconstruction becomes , prior KL , and ELBO . The posterior gap is zero. Use when: the inference family can better represent the model posterior.
Change the KL weight
New task: keep the original but optimize reconstruction minus times prior KL, with . Check: the objective becomes , exceeding the exact log-likelihood . It is not the ordinary ELBO; its usual lower-bound guarantee cannot be asserted. Use when: deliberately changing a representation or rate-distortion tradeoff rather than claiming the same likelihood objective.
The reparameterization trick
Write , with parameter-independent . For log variance , use , not . The randomness remains; its sampling law no longer depends on . See the pathwise-gradient derivation for conditions and alternatives.
Reconstruct: which observed enters the encoder during unconditional generation?
Answer
None. Sample from the prior, then sample or summarize the decoder distribution . Reconstruction instead conditions on a supplied observation through the encoder.
What VAEs are good and bad at
Continuous latent models can support interpolation and learned compression, including latent representations used by downstream diffusion models. Their usefulness depends on the learned distribution and reconstruction contract, not continuity alone. Gaussian squared error corresponds to a specified decoder variance; it is not a universal reconstruction likelihood. Blur depends on that likelihood, uncertainty, architecture, and optimization, not simply the VAE name. No universal stability or sample-quality ranking follows against GANs or diffusion.
Common pitfalls
Posterior collapse means inferred latents carry little observation-specific information and the decoder can ignore them. An expressive autoregressive decoder can still produce varied outputs; collapse does not imply a constant image. Annealing, free bits, decoder changes, and inference improvements alter different parts of training and offer no universal cure. Not using a pathwise estimator does not uniquely force REINFORCE; other estimators depend on the latent family. Check likelihood sums, minibatch reductions, and KL units before interpreting their relative weight.
Variants
- Beta-VAE: changes the KL weight; disentanglement is not guaranteed by that coefficient alone.
- VQ-VAE: introduces discrete codebooks and a different training construction, not Gaussian reparameterization unchanged.
- IWAE: uses an importance-weighted objective with its own support and sampling conditions.
- NVAE and hierarchical VAEs: introduce multiple conditional latent levels, retaining a distinct factorization.
The IWAE bound is an expectation, not an exact likelihood correction. A single Monte Carlo realization need not lie below log-likelihood.
Related
- Reparameterization trick. The gradient enabler.
- Autoregressive vs. diffusion. Alternative generative paradigms.