A step-by-step derivation of the Evidence Lower Bound (ELBO), from intractable posteriors to the reconstruction-regularisation decomposition used in VAEs.
Notation Reference
Symbol
Meaning
x
Observed data
z
Latent variables
p(z∣x)
True (intractable) posterior
p(x∣z)
Likelihood
p(z)
Prior distribution
p(x)
Marginal likelihood (evidence)
qφ(z∣x)
Variational approximation to the posterior
θ
Generative model parameters
φ
Variational parameters
L(θ,φ)
Evidence Lower Bound (ELBO)
DKL(q∣p)
KL divergence from q to p
Eq[⋅]
Expectation under distribution q
μq,σq
Mean and std. dev. of the variational distribution
μ∗,σ∗
Mean and std. dev. of the true posterior
σℓ
Likelihood standard deviation
N(μ,σ2)
Gaussian distribution with mean μ and variance σ2
Let’s say we’ve observed the data x and we want to know the conditional probability of the latent variables z. The conditional probability distribution p(z∣x) can be then formulated with the Bayes’ rule as
p(z∣x)=p(x)p(x∣z)p(z)
Now the problem is that the denominator that acts as a regularizer
p(x)=∫p(x∣z)p(z)dz
is often intractable [1]. When something is intractable, it means that it is theoretically solvable but can’t be solved in a practical amount of time or with practical computational resources.
Variational Inference: Approximating the Posterior
With variational inference, we introduce a tractable approximation qφ(z∣x) and find the parameters φ that approximate the intractable posterior pθ(z∣x) as well as possible. The closeness is measured by KL-divergence. Even though KL-divergence is a good measure for determining the closeness of two distributions, it requires knowing the true posterior, which we don’t know because we don’t know the denominator which we’re trying to solve, but we need the posterior to solve the denominator. Using KL-divergence alone will not solve the approximation problem so we maximize a quantity called Evidence Lower BOund (ELBO).
Now our goal is to transform the intractable integral pθ(x) into a tractable approximation qφ(x). Instead of approximating pθ(x) we approximate logpθ(x). So we start from
Since KL divergence is always non-negative, the ELBO is a lower bound on the log evidence:
logpθ(x)≥Eqφ(z∣x)[logqφ(z∣x)pθ(x,z)]
The notation L(θ,φ) is used for the ELBO, so I’ll be also using it to simplify the math notation.
What is the ELBO Optimising?
Our original goal was to find a tractable distribution qφ(x) that approximates pθ(x). A novel solution to this is to maximize the ELBO. With logpθ(x) being fixed, maximizing the ELBO minimizes the KL-divergence.
The ELBO can be further decomposed by factoring using the chain rule of probability and splitting the log. This decomposition is a necessary tool for variational autoencoders (VAEs).
Here the reconstruction term measures how well the model recovers x from samples of the latent space and the regularisation term penalises qφ(z∣x) for deviating from the prior p(z).
A Simple Example
Model:
p(z)=N(0,1),p(x∣z)=N(z,σℓ2)
True posterior (conjugate, so tractable here):
p(z∣x)=N(μ∗,σ∗2),μ∗=σℓ2+1x,σ∗2=σℓ2+1σℓ2
Variational family:q(z)=N(μq,σq2).
We optimise (μq,σq) by gradient ascent on the ELBO and compare with the truth.
Figure 1: VI convergence: the variational q approaches the true posterior. Drag the slider to step through iterations. Dashed blue line is the true posterior; solid orange line is the current q.
Figure 2: ELBO rises monotonically during VI optimisation.
True log p(x) (numerical): -2.0289
Final ELBO: -2.0289
Difference: 0.0000
As can be seen in Figure 1, the approximation approaches the true distribution. This is verified numerically in the code block above. The code block shows that the KL divergence has converged to zero meaning that the distributions are the same up until numerical precision.
Summary
In the beginning, we motivated the need for variational inference to solve intractable posteriors. Then we derived ELBO and showed that maximizing it is equivalent to minimizing the KL divergence between the approximation and the true posterior. Then finally, we used the theory on a simple Gaussian example confirming that we were able to approximate the posterior well.
References
[1] C. M. Bishop, Pattern Recognition and Machine Learning. Springer, 2006.
[2] U. Jamil, “Variational Autoencoder - Model, ELBO, loss function and maths explained easily!,” 2023. [Online]. Available: https://www.youtube.com/watch?v=iwEzwTTalbg. YouTube video, accessed March 31, 2026.