---
title: For a latent-variable model p(x, z) with an approximate posterior q(z|x), derive the evidence lower bound and identify…
url: https://gurkanozkan.ai/learn/questions/research-deriving-the-elbo-015/
markdown: https://gurkanozkan.ai/learn/questions/research-deriving-the-elbo-015.md
kind: question
role: Research
stage: Technical
difficulty: Hard
json: https://gurkanozkan.ai/api/learn/questions/research-deriving-the-elbo-015.json
robots: noindex
---

# For a latent-variable model p(x, z) with an approximate posterior q(z|x), derive the evidence lower bound and identify exactly what the gap between log p(x) and the ELBO is.

Research · Technical · Hard

Theme reported publicly: [Google DeepMind](https://www.algomindset.com/blog/google-deepmind-research-engineer-interview-guide)

## Answer

*Model answer, written in a candidate's voice*

### In short

- Write log p(x) as log E_q[p(x,z)/q(z|x)] and apply Jensen to get the ELBO.
- Expand the ELBO as E_q[log p(x|z)] - KL(q(z|x)||p(z)).
- Show the gap log p(x) - ELBO equals KL(q(z|x)||p(z|x)), which is >= 0 and zero iff q equals the true posterior.
- For a VAE, reparameterisation z = g_phi(epsilon,x) gives low-variance pathwise gradients, and inference is amortised through a shared q_phi(z|x).

### In full

Start from log p(x) = log ∫ p(x,z) dz = log E_q[p(x,z)/q(z|x)], then Jensen gives log p(x) >= E_q[log p(x,z) - log q(z|x)], the ELBO. Rewriting the integrand as p(x,z)=p(x|z)p(z) gives ELBO = E_q[log p(x|z)] - KL(q(z|x)||p(z)). The exact gap is log p(x) - ELBO = E_q[log q(z|x) - log p(z|x)] = KL(q(z|x)||p(z|x)), which is nonnegative and equals zero exactly when q(z|x) equals the true posterior p(z|x) almost everywhere. In a VAE this becomes E_q[log p_theta(x|z)] - KL(q_phi(z|x)||p(z)), and the reparameterisation trick z = g_phi(epsilon,x) with epsilon ~ p(epsilon) turns the expectation into a differentiable pathwise estimate with much lower variance than score-function gradients. Amortised inference shares one inference network q_phi(z|x) across examples instead of optimising a separate variational distribution per data point, trading a little per-example flexibility for fast, scalable posterior approximation.

*Checked against sources by an independent AI reviewer.*

## What a strong answer covers

- Jensen's inequality on log E_q[p(x,z)/q].
- The ELBO rewritten as E_q[log p(x|z)] − KL(q(z|x)‖p(z)).
- The gap is KL(q(z|x)‖p(z|x)) ≥ 0, so the bound is tight when q equals the true posterior.
- For a VAE: the reparameterisation trick gives low-variance gradients; inference is amortised.

## Common mistakes

- Writing the gap's KL in the wrong direction.
- Forgetting how to get gradients through sampling.
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
