In a VAE with prior and diagonal Gaussian encoder , how do you derive the closed-form KL divergence , and what does each term encourage?
Deep learning, Variational autoencoders
Level L3 Intermediate. Length Long. Nature Mat Mathematical.
What's being asked
Whether you can integrate the KL between two diagonal Gaussians from first principles and interpret the resulting regulariser.
Key idea
Because both and factorise across the coordinates, the KL splits into a sum of 1-D integrals, giving .
Steps
- Factorise across dimensions: since covariance is diagonal, , so it suffices to compute one 1-D integral.
- Write : using and , the constants cancel: .
- Take the expectation under : use and .
- Substitute and simplify: . Sum over .
- Sanity check and interpretation: at , the term is ; at , it is . Minimising this pulls (centring codes near the origin) and (preventing the encoder from collapsing posteriors to zero-variance points).
Common mistakes
- Forgetting and writing only, which drops the penalty.
- Getting the overall minus sign wrong (the expression inside parentheses is , so the leading makes ).
How long your answer should be
About one page; 5–7 minutes.
Last checked on 4 December 2026.
Read this
Previous in Deep learning: How does a DenseNet block differ from a ResNet block in how earlier features are combined, what is the channel count entering layer (with initial channels and growth rate ), and what is the trade-off between parameter efficiency and GPU memory?
Next in Deep learning: For the minimax GAN objective , how do you derive the optimal discriminator for a fixed generator , and show that substituting reduces the generator objective to ?