Md. Asif Uddin

    Proposition 2I.13.P0245 of 100 in the corpus

    The ELBO falls short of the log-evidence by exactly the divergence from the encoder's distribution to the posterior.

    A bound that can be computed replaces an evidence that cannot. It splits into a reconstruction term and a price on the code, and it is tight only when the encoder returns the true posterior.

    The evidence of one point and four lower boundsA dashed line marks the log-evidence of the point (1, 2), minus 3.531. Four bars rise to the bound each encoder gives: minus 5.838 for the prior, minus 5.031 with the right width but mean zero, minus 4.338 with the right mean but width one, and minus 3.531 for the true posterior. The gaps are 2.31, 1.50, 0.81 and zero.one point, four bounds−6−5−4log p(x) = −3.5312.31N(0, 1)the prior1.50N(0, ¼)width only0.81N(0.87, 1)mean onlyN(0.87, ¼)posteriorEach gap is the KL from that encoder to the posterior.
    Fig. 2 — Type B · Construction — The log-evidence of the point (1, 2) under probabilistic PCA, and the lower bound four encoders give it. The gap is the KL divergence from each encoder's distribution to the true posterior, and it closes only at the posterior.

    Two derivations of one bound

    Let q(z∣x)q(\vec z\mid\vec x) be any distribution over codes that is positive exactly where the posterior is; for Gaussian priors and decoders that is everywhere. Multiply and divide by it inside the evidence, then apply Jensen’s inequality to the concave logarithm (Jensen's inequality 0.IT.05):

    log⁡p(x)    =log⁡Eq[p(x,z)q(z∣x)]    ≥Eq[log⁡p(x,z)    −log⁡q(z∣x)].\begin{aligned} &\log p(\vec x)\\ &\;\;=\log\E_{q}\Big[\frac{p(\vec x,\vec z)}{q(\vec z\mid\vec x)}\Big]\\ &\;\;\geq\E_{q}\big[\log p(\vec x,\vec z)\\ &\;\;\qquad-\log q(\vec z\mid\vec x)\big]. \end{aligned}

    The right-hand side is the evidence lower bound, the ELBO. Jensen’s inequality is an equality only when the ratio inside is the same for every z\vec z, that is, when qq is proportional to p(x,z)p(\vec x,\vec z), which makes it the posterior.

    The second derivation gives the size of the gap. Since log⁡p(x)\log p(\vec x) does not depend on z\vec z, it equals its own average under qq. Write it as log⁡p(x,z)−log⁡p(z∣x)\log p(\vec x,\vec z)-\log p(\vec z\mid\vec x) inside that average, and add and subtract log⁡q\log q:

    log⁡p(x)=ELBO⁡(q)    +KL⁡(q(z∣x) ∥ p(z∣x)),ELBO⁡(q)=Eq[log⁡p(x∣z)]    −KL⁡(q(z∣x) ∥ p(z)).\begin{aligned} &\log p(\vec x)=\operatorname{ELBO}(q)\\ &\;\;+\KL\big(q(\vec z\mid\vec x)\,\|\,p(\vec z\mid\vec x)\big),\\[6pt] &\operatorname{ELBO}(q)=\E_{q}\big[\log p(\vec x\mid\vec z)\big]\\ &\;\;-\KL\big(q(\vec z\mid\vec x)\,\|\,p(\vec z)\big). \end{aligned}
    (I.13.4)

    The bound misses the evidence by the divergence to the posterior.

    The second line splits log⁡p(x,z)\log p(\vec x,\vec z) into log⁡p(x∣z)+log⁡p(z)\log p(\vec x\mid\vec z)+\log p(\vec z). Because a KL divergence is never negative (Kullback–Leibler divergence 0.IT.03), the first line is the bound, and it names the gap exactly. This is I.13.T1. With the model held fixed, the evidence is a constant, so raising the ELBO over qq and lowering the KL divergence from qq to the posterior are the same act.

    Reading the two terms

    The first term of the ELBO is a reconstruction term: the decoder’s log-likelihood of x\vec x, averaged over codes drawn from the encoder. With a Gaussian decoder of variance σ2\sigma^2 it is −∥x−x^∥2/(2σ2)-\|\vec x-\hat{\vec x}\|^2/(2\sigma^2) plus a constant, the loss of I.12 with the code made random.

    The second term is the price of the code: how far the encoder’s distribution sits from the prior. It is what I.12 lacked. It pulls every input’s distribution towards N(0,I)\mathcal N(\vec 0,\mat I), so the distributions of different inputs overlap and the decoder is trained on a cloud of codes around each one, not on isolated points. Proposition 4 shows what happens when that price is set too high.

    The price of a Gaussian code

    For q=N(μ,s2)q=\mathcal N(\mu,s^2) and the prior N(0,1)\mathcal N(0,1) in one dimension, the KL divergence is the average under qq of log⁡q(z)−log⁡p(z)\log q(z)-\log p(z). The log-densities are −12log⁡2πs2−(z−μ)2/2s2-\tfrac12\log2\pi s^2-(z-\mu)^2/2s^2 and −12log⁡2π−z2/2-\tfrac12\log2\pi-z^2/2. Under qq the first quadratic averages to 12\tfrac12 and z2z^2 averages to μ2+s2\mu^2+s^2. A diagonal Gaussian is a product, and its KL is the sum over coordinates:

    KL⁡(N(μ,diag⁡σ2) ∥ N(0,I))    =12∑j=1k(μj2+σj2−1−log⁡σj2).\begin{aligned} &\KL\big(\mathcal N(\vec\mu,\operatorname{diag}\vec\sigma^2)\,\|\, \mathcal N(\vec 0,\mat I)\big)\\ &\;\;=\frac12\sum_{j=1}^k\big(\mu_j^2+\sigma_j^2-1-\log\sigma_j^2\big). \end{aligned}
    (I.13.5)

    The price of a Gaussian code, coordinate by coordinate.

    Each coordinate costs nothing only at μj=0\mu_j=0, σj=1\sigma_j=1, which is the prior. Its derivatives are μj\mu_j with respect to μj\mu_j and 12(σj2−1)\tfrac12(\sigma_j^2-1) with respect to log⁡σj2\log\sigma_j^2: the term pulls every mean to zero and every variance to one. As σj→0\sigma_j\to0 the cost grows like −log⁡σj-\log\sigma_j without limit, so a point code is infinitely expensive (I.13.X04).

    One point, four bounds

    Return to probabilistic PCA on the four points, with σ2=1\sigma^2=1, w=3 u1\vec w=\sqrt3\,\vec u_1 and the point x=(1,2)\vec x=(1,2). Proposition 1 found log⁡p(x)=−3.531024\log p(\vec x)=-3.531024 and the posterior N(0.866025, 0.25)\mathcal N(0.866025,\,0.25). For any Gaussian q=N(m,v)q=\mathcal N(m,v) both terms of the ELBO have closed forms, so the figure can compare four encoders exactly:

    encoder’s qqELBOgap
    N(0,1)\mathcal N(0,1), the prior−5.837877-5.8378772.3068532.306853
    N(0,14)\mathcal N(0,\tfrac14)−5.031024-5.0310241.51.5
    N(0.866,1)\mathcal N(0.866,1)−4.337877-4.3378770.8068530.806853
    N(0.866,14)\mathcal N(0.866,\tfrac14)−3.531024-3.53102400

    Each gap is the KL divergence from that qq to the posterior, as (I.13.4) says it must be. The prior pays the most. The right width with the wrong mean, or the right mean with the wrong width, each closes part of the gap. At the posterior the reconstruction term is −2.837877-2.837877 and the price of the code is log⁡2=0.693147\log2=0.693147, and they add to the evidence exactly. I.13.B01 computes every entry.

    What maximising over the model does

    A VAE maximises the ELBO over the decoder’s parameters θ\theta and the encoder’s ϕ\phi together. Over ϕ\phi, the bound tightens. Over θ\theta, it rises in two ways: by raising the evidence, which is the intended effect, and by moving the true posterior towards distributions the encoder can represent, which shrinks the gap without improving the model. The trained model is therefore biased towards posteriors that look like diagonal Gaussians. And the encoder is shared: with one network for every input, the gap includes an amortisation part that a per-input optimisation would remove (Cremer, Li and Duvenaud 2018).

    None of this needs the evidence itself. Each training step uses one draw of z\vec z per example to estimate the reconstruction term, the closed form (I.13.5) for the price, and a gradient that proposition 3 explains.

    Reproduce the four bounds

    from math import log, pi, sqrt
    
    x, w, var = (1.0, 2.0), (0.8*sqrt(3), 0.6*sqrt(3)), 1.0
    wx, ww, xx = sum(a*b for a, b in zip(w, x)), sum(a*a for a in w), sum(a*a for a in x)
    
    def elbo(m, v):      # q = N(m, v); both terms in closed form
        recon = -log(2*pi*var) - (xx - 2*m*wx + (m*m + v)*ww)/(2*var)
        kl = 0.5*(m*m + v - 1 - log(v))
        return recon - kl
    
    for m, v in ((0, 1), (0, 0.25), (sqrt(3)/2, 1), (sqrt(3)/2, 0.25)):
        print(f"q = N({m:.3f}, {v}): ELBO {elbo(m, v):.6f}")

    It prints −5.837877-5.837877, −5.031024-5.031024, −4.337877-4.337877 and −3.531024-3.531024. The reconstruction term uses Eq∥x−wz∥2=∥x∥2−2m wTx+(m2+v)∥w∥2\E_q\|\vec x-\vec wz\|^2=\|\vec x\|^2-2m\,\vec w^{\mathsf T}\vec x+(m^2+v)\|\vec w\|^2, which holds for any qq with mean mm and variance vv.

    Sources