Quant Memo
Advanced

The Evidence Lower Bound

The ELBO is a quantity you can actually compute that sits below the number you actually want, and pushing it up is how variational methods approximate a posterior distribution nobody can integrate exactly.

Prerequisites: Bayesian Inference, KL Divergence

Suppose you fit a model with a hidden variable — a regime nobody labelled, a factor nobody observed directly. Bayes' rule says the right belief about that hidden variable, given the data, is the posterior p(zx)p(z \mid x). Writing it down exactly requires dividing by p(x)p(x), the "evidence": the total probability of the data averaged over every possible value of the hidden variable. For anything beyond a toy model, that average is an integral over a space too large to sum, and it has no closed form. You know the rule but cannot evaluate it.

The analogy: appraising a house you cannot fully inspect

You want to know a house's true value. You cannot get inside every room, so an exact appraisal is out of reach. What you can do is walk the perimeter, check the neighbourhood, and build a conservative valuation from what's visible — a number you can defend as a floor: "it's worth at least this much." A better inspector, with a richer checklist, pushes that floor closer to the true value without ever proving it exact.

The evidence lower bound, or ELBO, is that floor. You cannot compute logp(x)\log p(x), the log-evidence, directly. You can compute a related quantity that is always less than or equal to it, and the closer your approximating "checklist" gets to reality, the tighter that floor becomes.

Building the bound

Introduce an approximating distribution q(z)q(z) — a guess at the posterior, chosen from a family simple enough to compute with, such as a Gaussian with parameters you control. A short algebraic identity (splitting logp(x)\log p(x) using p(x,z)=p(zx)p(x)p(x,z) = p(z \mid x) p(x)) gives:

logp(x)=Eq(z) ⁣[logp(x,z)q(z)]+KL(q(z)p(zx))\log p(x) = \mathbb{E}_{q(z)}\!\left[\log \frac{p(x,z)}{q(z)}\right] + \mathrm{KL}\big(q(z) \,\|\, p(z \mid x)\big)

In words: the true log-evidence splits into two pieces. The first piece — the ELBO — is an average, under your guess qq, of the log joint probability of data and hidden variable minus the log of your guess itself. The second piece is the KL Divergence between your guess and the true posterior, which measures how wrong your guess is. Crucially, KL divergence is never negative, so the ELBO can never exceed logp(x)\log p(x): it is a genuine lower bound, and the gap between them is exactly your guess's error.

ELBO(q)=Eq(z)[logp(x,z)]Eq(z)[logq(z)]\mathrm{ELBO}(q) = \mathbb{E}_{q(z)}[\log p(x,z)] - \mathbb{E}_{q(z)}[\log q(z)]

In words: reward qq for placing mass where the data and hidden variable are jointly plausible (first term), and reward it separately for not collapsing to a single point — the second term is qq's own entropy, and a confident, low-entropy guess that's wrong gets penalised harder than a spread-out one. Since logp(x)\log p(x) is a fixed number that does not depend on qq, maximising the ELBO over qq is mathematically identical to minimising the KL gap. You never touch the intractable quantity directly; you climb a bound instead, and the true posterior is what you land on when the family containing qq is rich enough to reach it exactly.

Worked example 1: a two-outcome hidden variable, by hand

A hidden variable zz takes value 1 (a "risk-on" regime) or 0 ("risk-off") with true posterior p(z=1x)=0.8p(z{=}1 \mid x) = 0.8 after seeing today's data — but suppose, for illustration, you cannot compute this directly and only know the unnormalised joint values p(x,z=1)=0.32p(x, z{=}1) = 0.32 and p(x,z=0)=0.08p(x, z{=}0) = 0.08, so the true evidence is p(x)=0.32+0.08=0.40p(x) = 0.32 + 0.08 = 0.40, giving logp(x)=log(0.40)=0.916\log p(x) = \log(0.40) = -0.916.

Guess q(z=1)=0.6q(z{=}1) = 0.6, q(z=0)=0.4q(z{=}0) = 0.4 — a deliberately imperfect approximation. Compute the ELBO term by term:

Eq[logp(x,z)]=0.6log(0.32)+0.4log(0.08)=0.6(1.139)+0.4(2.526)=0.6831.010=1.693\mathbb{E}_q[\log p(x,z)] = 0.6 \log(0.32) + 0.4 \log(0.08) = 0.6(-1.139) + 0.4(-2.526) = -0.683 - 1.010 = -1.693 Eq[logq(z)]=0.6log(0.6)+0.4log(0.4)=0.6(0.511)+0.4(0.916)=0.3070.367=0.673\mathbb{E}_q[\log q(z)] = 0.6\log(0.6) + 0.4\log(0.4) = 0.6(-0.511) + 0.4(-0.916) = -0.307 - 0.367 = -0.673 ELBO=1.693(0.673)=1.020\mathrm{ELBO} = -1.693 - (-0.673) = -1.020

Check: 1.0200.916-1.020 \le -0.916, so the bound holds, with a gap of 0.1040.104 — that gap is KL(qp)\mathrm{KL}(q \| p), and it is nonzero because q(z=1)=0.6q(z{=}1)=0.6 doesn't match the true p(z=1x)=0.32/0.40=0.8p(z{=}1 \mid x) = 0.32/0.40 = 0.8.

Worked example 2: tightening the guess

Now try q(z=1)=0.8q(z{=}1) = 0.8, q(z=0)=0.2q(z{=}0) = 0.2 — matching the true posterior exactly.

Eq[logp(x,z)]=0.8(1.139)+0.2(2.526)=0.9110.505=1.416\mathbb{E}_q[\log p(x,z)] = 0.8(-1.139) + 0.2(-2.526) = -0.911 - 0.505 = -1.416 Eq[logq(z)]=0.8log(0.8)+0.2log(0.2)=0.8(0.223)+0.2(1.609)=0.1780.322=0.500\mathbb{E}_q[\log q(z)] = 0.8\log(0.8) + 0.2\log(0.2) = 0.8(-0.223) + 0.2(-1.609) = -0.178 - 0.322 = -0.500 ELBO=1.416(0.500)=0.916\mathrm{ELBO} = -1.416 - (-0.500) = -0.916

That equals logp(x)\log p(x) exactly. When qq matches the true posterior, the KL gap vanishes and the floor touches the ceiling — this is the whole mechanism variational inference exploits: search over qq for whatever maximises the ELBO, and you are, without ever computing p(x)p(x), searching for the best available approximation to p(zx)p(z \mid x).

weak q good q log p(x) ELBO ELBO
The shaded cap is the KL gap between the guess and the truth. A weak q leaves a visible gap below log p(x); a good q closes it almost entirely.

What this means in practice

Nobody in production computes an ELBO by hand over two outcomes — the real payoff is when zz is continuous and high-dimensional, such as the latent factors in a variational autoencoder used for anomaly detection on order-book snapshots, or the latent regime in a state-space model of returns. There, p(x)p(x) truly has no closed form, and optimising the ELBO with gradient ascent (via the reparameterisation trick, so gradients can flow through the sampling step) is the only practical route to an approximate posterior. It also underlies model selection: the ELBO is sometimes used as a cheap stand-in for the evidence when comparing model families, since a model whose best achievable ELBO is higher tends to explain the data better — though this comparison inherits any bias from how tight each model's bound actually is.

Convergence explorer
true meansamples →
after n = 200estimate -0.025error 0.025std error 0.071

Watch how the tracked quantity climbs and settles as more updates accumulate — the ELBO under gradient ascent behaves the same way, rising each step and flattening out once qq stops improving, never above the true log-evidence.

The ELBO is not an approximation to logp(x)\log p(x) in the sense of being close by default — it is a provable lower bound, tight only when your approximating family can actually represent the true posterior. Maximising it is a proxy objective that happens to be exactly equivalent to minimising the one error you actually care about.

The classic confusion: assuming a rising ELBO during training always means the model is "getting better" in the sense of explaining the data better. In plain variational inference the model pp is fixed and only qq moves, so a rising ELBO purely means qq is tracking the true posterior more closely — good. But in joint training (as in a variational autoencoder, where pp's parameters and qq's parameters are optimised together), the ELBO can rise because pp itself is changing to make the data easier to explain, which is a different and sometimes undesirable effect. Always ask which side of the bound is moving before reading meaning into the number going up.

Related concepts

Practice in interviews

Further reading

  • Blei, Kucukelbir & McAuliffe, Variational Inference: A Review for Statisticians
  • Bishop, Pattern Recognition and Machine Learning, ch. 10
ShareTwitterLinkedIn