Exact values where possible; six decimal places otherwise.
STATEMENT
Derive the ELBO identity, derive the KL divergence of a Gaussian code from
the standard normal and its derivatives, and show that the encoder that
maximises the ELBO is the posterior.
GIVEN
A model p(z)p(x∣z) with evidence p(x)>0, and a
distribution q(z∣x) that is positive exactly where the
posterior is. For the last part, the linear model of
I.13.B01.
FIND
(a) logp(x)−ELBO(q) as a single divergence.
(b) KL(N(μ,s2)∥N(0,1)) and its derivatives with
respect to μ and logs2.
(c) The q=N(m,v) that maximises the ELBO of the linear model, and
the ELBO there.
STRATEGY
For (a), write logp(x) as an average under q of something that
does not depend on z. For (b), average the log-ratio of densities.
For (c), differentiate the closed-form ELBO.
SOLUTION
(a) Bayes’ rule gives
p(x)=p(x,z)/p(z∣x) for every z with
positive posterior. The left side does not depend on z, so it
equals its average under q:
logp(x)=Eq[logp(z∣x)p(x,z)]=Eq[logq(z∣x)p(x,z)]+Eq[logp(z∣x)q(z∣x)].The first average is the ELBO and the second is
KL(q(z∣x)∥p(z∣x)). Splitting
p(x,z)=p(x∣z)p(z) in the first gives the
form in (I.13.4), with −KL(q∥p(z)) as its second term.
Since a KL divergence is non-negative and zero only for equal
distributions, the ELBO is a lower bound, tight exactly at the posterior.
(b) The log-densities are
logq(z)logp(z)=−21log2πs2−2s2(z−μ)2,=−21log2π−2z2.Under q, (z−μ)2 averages to s2 and z2 to μ2+s2.
Therefore
KL=−21logs2−21+21(μ2+s2)=21(μ2+s2−1−logs2).This is (I.13.5) for one coordinate. With ℓ=logs2, so that
s2=eℓ,
∂μ∂KL∂ℓ∂KL=μ,=21(s2−1).Both vanish only at μ=0, s2=1. For example
KL(N(1,0.25)∥N(0,1))=21(0.25+1.386294)=0.818147.
(c) From B01, with a=wTx and r=∥w∥2,
the ELBO of N(m,v) is, up to a constant,
−2σ2−2am+(m2+v)r−21(m2+v−1−logv).Setting the derivative in m to zero gives a/σ2=m(r/σ2+1),
so m=a/(r+σ2). In v it gives −r/2σ2−21+1/(2v)=0,
so v=σ2/(r+σ2). These are the posterior’s mean and variance
in (I.13.2). For the point (1,2) they are 0.866025 and 0.25, and by
(a) the ELBO there equals logp(x)=−3.531024.
Answer
(a) logp(x)−ELBO(q)=KL(q(z∣x)∥p(z∣x)).
(b) 21(μ2+s2−1−logs2), with derivatives μ and
21(s2−1). (c) m=a/(r+σ2) and v=σ2/(r+σ2),
the exact posterior, where the ELBO is −3.531024.
Check — sanity
The KL in (b) is zero at the prior and positive elsewhere: for fixed s
it grows with μ2, and s2−1−logs2≥0 with equality only at
s2=1, by logt≤t−1.
Where this breaks
If q is positive somewhere the posterior is zero, the KL in (a) is
infinite and the ELBO is minus infinity. If q is zero somewhere the
posterior is not, (a) still holds but q cannot be the posterior, so the
gap never closes. A Gaussian prior and decoder make the posterior positive
everywhere, and neither case arises. If the decoder variance also depends
on z, (c) has no closed form.
Variation
For a code with k independent coordinates the KL is a sum of k copies
of (b). At the posterior of the linear model the price is
21log((r+σ2)/σ2)+21(m2+v−1). At the
maximum-likelihood w the second part averages to zero over the
data, and at every corner of the rectangle it is exactly zero, leaving
21log4=log2.