Course contents 07 / 34

07 / 34 · Variational Autoencoders

Variational autoencoders

How an autoencoder becomes a generator: a latent-variable model trained through the evidence lower bound, an encoder that approximates the posterior, the reparameterization trick, what the prior constrains, posterior collapse, and the conditional VAE.

On this page 10

An autoencoder learns to reconstruct observed inputs. That objective alone does not specify a distribution for new latent codes, or constrain every gap between the training codes. Good reconstructions therefore do not establish that drawing a random code will produce useful new data.

The variational autoencoder (VAE) of Kingma and Welling (2014), proposed at the same time by Rezende, Mohamed and Wierstra (2014), builds that in. Each image is encoded to a Gaussian instead of a point, and all these Gaussians are pulled toward one fixed distribution. It is also the first neural model of the course trained by a bound on maximum likelihood, the objective the entropy note singled out.

From autoencoders to generation#

The autoencoder maps xx to zz and back to x^\hat x. Drawing zz from a convenient Gaussian is an extra modeling choice: the reconstruction objective has not required the codes to follow it. Fitting a density to the codes is possible, but its fit and the decoder’s behavior on its samples need separate evaluation.

A small constructed example exposes the missing constraint. Take three scalar training observations x∈{−2,0,2}x\in\{-2,0,2\} and encoder z=xz=x. Both decoders g0(z)=zg_0(z)=z and g1(z)=z+34z(z2−4)g_1(z)=z+\tfrac34z(z^2-4) reconstruct every training point exactly. At the unseen code z=1z=1, however, they output 11 and −1.25-1.25. The training loss cannot choose between them.

This is an identifiability example with explicit functions, not a trained digit experiment. Architectural smoothness or additional regularization can restrict the alternatives; reconstruction alone does not.

Figure

Same reconstructions, different unseen outputs

Two decoders pass through three training pointsBlue g0(z) = z; red g1(z) = z + 0.75z(z² − 4). Both pass through (−2,−2), (0,0), (2,2). At z = 1 the outputs are 1 and −1.25.g₀(z) = zg₁(z) = z + ¾z(z² − 4)-4-2024-2021−1.25unseen code z = 1zTwo decoders pass through three training pointsBlue g0(z) = z; red g1(z) = z + 0.75z(z² − 4). Both pass through (−2,−2), (0,0), (2,2). At z = 1 the outputs are 1 and −1.25.g₀(z) = zg₁(z) = z + ¾z(z² − 4)-4-2024-2021−1.25unseen code z = 1z
With encoder z = x, two explicit decoders reconstruct −2, 0, 2 exactly. At unseen z = 1 they give 1 and −1.25. This counterexample tests what reconstruction alone establishes; no network or external data is used.

A VAE makes a generative distribution part of the model and trains it with a tractable likelihood bound.

The latent-variable model and its posterior#

Start from the simplest model of this kind. Probabilistic PCA draws a code z∈Rdz \in \mathbb R^d from a prior and places the image x∈RDx \in \mathbb R^D, with d<Dd < D, near a linear function of it:

z∼N(0,I),x∣z∼N(Wz+μ,σ2I).\begin{aligned} z &\sim \mathcal N(0, I), \\ x \mid z &\sim \mathcal N(Wz + \mu, \sigma^2 I) . \end{aligned}

Everything is Gaussian, so both the evidence and the posterior have closed forms. The image x=Wz+μ+εx = Wz + \mu + \varepsilon, with noise ε∼N(0,σ2I)\varepsilon \sim \mathcal N(0, \sigma^2 I), is an affine map of the Gaussian pair (z,ε)(z, \varepsilon), so x∼N(μ,WW⊤+σ2I)x \sim \mathcal N(\mu, WW^\top + \sigma^2 I) by the affine-map rule. Completing the square in zz (folded below) gives the posterior

p(z∣x)=N(M−1W⊤(x−μ), σ2M−1),M=W⊤W+σ2I.\begin{aligned} p(z \mid x) &= \mathcal N\big(M^{-1} W^\top (x - \mu),\ \sigma^2 M^{-1}\big), \\ M &= W^\top W + \sigma^2 I . \end{aligned}
Derivation of the posterior

Bayes’ rule keeps only the factors that depend on zz; the rest is a constant:

log⁡p(z∣x)=log⁡p(x∣z)+log⁡p(z)+const=−∥x−μ−Wz∥22σ2−z⊤z2+const=−12 z⊤Mσ2 z+z⊤W⊤(x−μ)σ2+const.\begin{aligned} \log p(z \mid x) &= \log p(x \mid z) + \log p(z) + \text{const} \\ &= -\frac{\lVert x - \mu - Wz\rVert^2}{2\sigma^2} - \frac{z^\top z}{2} + \text{const} \\ &= -\tfrac12\, z^\top \frac{M}{\sigma^2}\, z + z^\top \frac{W^\top (x - \mu)}{\sigma^2} + \text{const} . \end{aligned}

The third line expands the square and collects z⊤z+z⊤W⊤Wz/σ2=z⊤(M/σ2) zz^\top z + z^\top W^\top W z/\sigma^2 = z^\top (M/\sigma^2)\, z. A Gaussian N(m,P−1)\mathcal N(m, P^{-1}) has the log density −12z⊤Pz+z⊤Pm+const-\tfrac12 z^\top P z + z^\top P m + \text{const}. Matching the quadratic term gives P=M/σ2P = M/\sigma^2, and matching the linear term, Pm=W⊤(x−μ)/σ2Pm = W^\top (x - \mu)/\sigma^2, gives m=M−1W⊤(x−μ)m = M^{-1} W^\top (x - \mu).

Maximum likelihood sets μ\mu to the data mean, where the gradient ∑nC−1(xn−μ)\sum_n C^{-1}(x_n - \mu) of a Gaussian log-likelihood vanishes for any covariance CC. EM fits WW and σ2\sigma^2 by alternating two exact steps: set q(z)q(z) to this posterior, then maximize the expected log joint (EM as coordinate ascent). Probabilistic PCA is thus a VAE with a linear decoder and an exact Gaussian encoder (probabilistic PCA), diagonal when the columns of WW are orthogonal and MM is diagonal.

A linear subspace can be too restrictive for complex observations. The VAE keeps this two-stage model and replaces Wz+μWz+\mu with a neural network. In the Gaussian version used here, the decoder pθ(x∣z)p_\theta(x\mid z) has a mean, and possibly a variance, supplied by that network. This PPCA-to-VAE route follows BMML lecture 6, §§6.1–6.2; the adapted exposition is credited under its MIT documentation license. The model distribution is the marginal of pθ(x,z)=pθ(x∣z)p(z)p_\theta(x,z)=p_\theta(x\mid z)p(z) (joint and marginal densities), called the evidence:

pθ(x)=∫pθ(x∣z) p(z) dz.p_\theta(x) = \int p_\theta(x \mid z)\, p(z)\, dz .

Maximum likelihood maximizes log⁡pθ(x)\log p_\theta(x) over the training images. The reverse question, which codes explain a given image, is answered by the posterior:

pθ(z∣x)=pθ(x∣z) p(z)pθ(x).p_\theta(z \mid x) = \frac{p_\theta(x \mid z)\, p(z)}{p_\theta(x)} .

A general neural decoder leaves no closed-form integral, so an exact posterior E-step is generally unavailable. Approximate inference will replace it.

Figure

An observation updates the code distribution

Observation density and latent density updateThe upper plot shows the Gaussian density of x, marking x = 0.7. The lower plot shows the blue standard normal prior and a narrower red posterior with mean 0.422414. Vertical axes show density; horizontal axes show the respective variable.Before observing: p(x)N(0, 2.32)00.10.2x = 0.7-303xAfter x = 0.7: p(z | x)00.51p(z)p(z | x)-303z
Explicit model: z ~ N(0, 1), x | z ~ N(1.4z, 0.36). Above: x has density N(0, 2.32). Observing x = 0.7 yields posterior z ~ N(0.422414, 0.155172), the red curve below. This is exact Gaussian conditioning, without neural-network training.

Why not estimate the integral by sampling? Draw z1,…,znz_1, \dots, z_n from the prior and average pθ(x∣zk)p_\theta(x \mid z_k). The nn terms are independent with mean p(x)p(x), so the average is unbiased, with variance (Ep(z)[p(x∣z)2]−p(x)2)/n\big(\mathbb E_{p(z)}[p(x \mid z)^2] - p(x)^2\big)/n. Relative to p(x)2p(x)^2 it is

Var⁡[p^(x)]p(x)2=1n(Ep(z)[p(x∣z)2]p(x)2−1).\frac{\operatorname{Var}\big[\hat p(x)\big]}{p(x)^2} = \frac1n \left(\frac{\mathbb E_{p(z)}\big[p(x \mid z)^2\big]}{p(x)^2} - 1\right) .

When prior samples rarely explain an observation well, a few large likelihoods can dominate the average. Consider this explicit example: let each of dd coordinates be independent, with zj∼N(0,1)z_j \sim \mathcal N(0, 1) and xj∣zj∼N(zj,0.1)x_j \mid z_j \sim \mathcal N(z_j, 0.1). At x=0x = 0 every coordinate multiplies the ratio inside the brackets by 11/21≈2.4011/\sqrt{21} \approx 2.40, and n≥100((11/21)d−1)n \ge 100\big((11/\sqrt{21})^d-1\big) samples bring the relative error, the square root of the relative variance, to at most 10%:

ddratio (11/21)d(11/\sqrt{21})^dsamples for a 10% relative error
12.4141
106350.83634,983
1001.1⋅10381.1 \cdot 10^{38}1.1⋅10401.1 \cdot 10^{40}
Where 2.40 comes from

For one coordinate with noise variance v=0.1v = 0.1, p(x=0∣z)=(2πv)−1/2e−z2/(2v)p(x = 0 \mid z) = (2\pi v)^{-1/2} e^{-z^2/(2v)} and, by the affine-map rule, p(x=0)=(2π(1+v))−1/2p(x = 0) = \big(2\pi(1 + v)\big)^{-1/2}. The square of the likelihood is again a Gaussian shape in zz, and the Gaussian integral ∫e−az2/2dz=2π/a\int e^{-a z^2/2} dz = \sqrt{2\pi/a} with a=2/v+1a = 2/v + 1 gives

Ep(z)[p(0∣z)2]=12πv∫e−z2/v−z2/22π dz=12πv (1+2v)−1/2,Ep(z)[p(0∣z)2]p(0)2=1+vv2+2v=1.10.21≈2.40.\begin{aligned} \mathbb E_{p(z)}\big[p(0 \mid z)^2\big] &= \frac{1}{2\pi v} \int \frac{e^{-z^2/v - z^2/2}}{\sqrt{2\pi}}\, dz \\ &= \frac{1}{2\pi v}\, \Big(1 + \frac 2v\Big)^{-1/2}, \\ \frac{\mathbb E_{p(z)}\big[p(0 \mid z)^2\big]}{p(0)^2} &= \frac{1 + v}{\sqrt{v^2 + 2v}} = \frac{1.1}{\sqrt{0.21}} \approx 2.40 . \end{aligned}

The coordinates are independent, so with dd of them both numerator and denominator are products over coordinates, and the ratio is (11/21)d(11/\sqrt{21})^d.

The cost grows exponentially in this particular independent-coordinate construction, not in every latent-variable model. It illustrates the difficulty of prior sampling discussed by Isachenko (2025), lecture 3. An encoder can concentrate samples in regions that help explain the observation.

Variational approximation and the ELBO#

The way out keeps EM’s lower bound and gives up the exact E-step: qq is restricted to a simple family and optimized together with θ\theta. Replacing an intractable posterior by the closest member of a simple family is variational inference, the subject of the variational inference note of the Bayesian Methods course.

The plainest choice gives each training image xix_i its own diagonal Gaussian q(zi)=N(mi,Si)q(z_i) = \mathcal N(m_i, S_i). That works, but the variational parameters grow with the data, and every new image needs its own optimization. The VAE replaces the table of (mi,Si)(m_i, S_i) by an encoder network with parameters φ\varphi:

qφ(z∣x)=N(μφ(x),diag⁡σφ2(x)).q_\varphi(z \mid x) = \mathcal N\big(\mu_\varphi(x), \operatorname{diag}\sigma_\varphi^2(x)\big) .

One network that outputs qq for any xx is amortized inference: the cost of inference is paid once, in training the encoder (Kingma and Welling, 2019, section 2.1; amortization in numbers).

Encoder and decoder are trained together by maximizing the evidence lower bound (ELBO), derived below:

L(x)=Eqφ(z∣x)[log⁡pθ(x∣z)]−DKL(qφ(z∣x) ∥ p(z))≤log⁡pθ(x).\begin{aligned} \mathcal L(x) ={}& \mathbb E_{q_\varphi(z \mid x)}\big[\log p_\theta(x \mid z)\big] \\ &- D_{\mathrm{KL}}\big(q_\varphi(z \mid x) \,\|\, p(z)\big) \\ \le{}& \log p_\theta(x) . \end{aligned}

The first term is the expected reconstruction log likelihood. For a fixed decoder with a finite maximum, concentrating qq near a maximizer of log⁡pθ(x∣z)\log p_\theta(x\mid z) can improve this term alone: an average cannot exceed the maximum. This does not require a unique best code, and a flat decoder is a counterexample to inevitable concentration. The second term, the KL penalty, charges for departures from the prior, including variance shrinking to zero. The two-term interpretation adapts BMML lecture 6 §6.3 under the same notice.

Figure

The two terms of the ELBO

Reconstruction and regularization terms of the ELBOThe formula L(x) = E over q(z given x) of log p(x given z), minus KL of q(z given x) from p(z). A brace under the first term is labelled reconstruction: how well we reconstruct, comparing the real image with the image after real to latent to real; with a Gaussian decoder it reduces to the summed squared-error reconstruction loss. A small sketch shows x, encoder, z, decoder, x hat, and a red double arrow labelled compare between x and x hat. A brace under the second term is labelled regularization: how close the posterior q(z given x) is to the prior p(z). A sketch shows dashed concentric circles for p(z) and a small blue ellipse q(z given x) off-centre inside them, with red arrows pulling it toward the centre and outward, labelled pull q toward p; penalty on μ and σ.ℒ(x) =Eq(z|x)[log p(x | z)]−KL(q(z | x) ‖ p(z))reconstructionregularizationhow well we reconstructcompare real → latent → realxzx̂comparedecoder: N(x̂, ½I)(summed squared error ‖x − x̂‖²)how close the posterior q(z | x)is to the prior p(z)p(z)q(z | x)pull qtoward ppenalty on μ and σReconstruction and regularization terms of the ELBOTop: the first ELBO term, E over q(z given x) of log p(x given z), labelled reconstruction, how well we reconstruct, with a sketch of x, encoder, z, decoder, x hat and a red compare arrow; with a Gaussian decoder it reduces to the summed squared-error loss. Bottom: minus KL of q(z given x) from p(z), labelled regularization, how close the posterior is to the prior, with a sketch of a small blue ellipse q inside dashed circles p(z) and red arrows pulling it toward the centre and outward.ℒ(x) =Eq(z|x)[log p(x | z)]reconstructionhow well we reconstruct: real → latent → realxzx̂comparedecoder: N(x̂, ½I)(summed squared error ‖x − x̂‖²)− KL(q(z | x) ‖ p(z))regularizationhow close the posterior q(z | x) is to the prior p(z)p(z)q(z | x)pull qtoward ppenalty on μ and σ
Expected log likelihood measures reconstruction. KL penalizes departure of q from p. The illustrated q is already Gaussian, off-centre and narrow: KL alone favors zero mean and unit variance. Summed squared error assumes fixed decoder variance ½; its additive constant is omitted.

With a Gaussian decoder of fixed variance s2s^2, whose network outputs the mean x^(z)\hat x(z), the reconstruction term is a squared error:

−log⁡pθ(x∣z)=∥x−x^(z)∥22s2+D2log⁡(2πs2).-\log p_\theta(x \mid z) = \frac{\lVert x - \hat x(z)\rVert^2}{2s^2} + \frac D2 \log(2\pi s^2) .

The last term does not depend on the networks. With s2=12s^2 = \tfrac12 the expected squared error, summed over the DD pixels, plus the KL term is the negative ELBO up to a constant; a mean over pixels corresponds to s2=D/2s^2 = D/2. Any other s2s^2 reweights the two terms: multiplying by 2s22s^2 gives the squared error plus 2s22s^2 times the KL, the weight β\beta of the β-VAE.

If the decoder also learns its variance, the log-variance term must remain. For one variance shared by all observations and coordinates, its optimum depends on the average expected squared residual, not on one image’s residual. If all relevant residuals can vanish, a Gaussian likelihood can become unbounded as the variance tends to zero; a variance floor avoids that degeneracy. Binary observations can instead use a Bernoulli decoder and binary cross-entropy (the two readings).

The loss with a learned shared variance

Hold the encoder and decoder mean fixed and let R=1N∑iEqi∥xi−x^(z)∥2R=\frac1N\sum_i\mathbb E_{q_i}\lVert x_i-\hat x(z)\rVert^2. The mean negative reconstruction log likelihood, up to a constant, is R/(2s2)+(D/2)log⁡s2R/(2s^2)+(D/2)\log s^2. Differentiating in s2s^2 gives −R/(2s4)+D/(2s2)-R/(2s^4)+D/(2s^2), so for R>0R>0 the unique optimum is s2=R/Ds^2=R/D. Substitution gives (D/2)log⁡(R/D)(D/2)\log(R/D) plus a constant. This is the logarithm of the overall expected MSE; it is not an average of separate per-image logarithms.

With fixed decoder variance s2=12s^2=\tfrac12, one sampled code per image gives an unbiased estimate of the negative ELBO up to a constant:

LVAE(x)=∥x−x^(z)∥2+DKL(N(μ,σ2) ∥ N(0,I)),\begin{aligned} \mathcal L_{\text{VAE}}(x) ={}& \big\lVert x - \hat x(z)\big\rVert^2 \\ &+ D_{\mathrm{KL}}\big(\mathcal N(\mu, \sigma^2) \,\|\, \mathcal N(0, I)\big), \end{aligned}

with z∼N(μ,σ2)z \sim \mathcal N(\mu, \sigma^2), where μ\mu and σ2\sigma^2 are the encoder’s outputs for xx and the variance is applied coordinate-wise. Neither term contains the posterior pθ(z∣x)p_\theta(z \mid x) or the evidence: the loss needs only the encoder, the prior and the decoder, which we can all evaluate.

The weights θ\theta and φ\varphi are point estimates, fitted by stochastic gradient ascent on the ELBO like the parameters of an M-step (the VAE as variational EM). Only the code is integrated over and sampled, as are the noisy images of the later diffusion models. A distribution over the weights too would make a Bayesian neural network.

The reparameterization trick#

For a sum of nn per-image ELBOs, an unbiased minibatch gradient is nn times the average per-image gradient in a uniformly sampled minibatch. For the mean objective no such factor is needed. Assume differentiation can pass through the expectation and the density has parameter-independent support. For a function ff with no direct φ\varphi dependence, differentiating the encoder density gives:

∇φ Eqφ[f(z)]=∫f(z) ∇φqφ(z∣x) dz=Eqφ[f(z) ∇φlog⁡qφ(z∣x)].\begin{aligned} \nabla_\varphi\, \mathbb E_{q_\varphi}\big[f(z)\big] &= \int f(z)\, \nabla_\varphi q_\varphi(z \mid x)\, dz \\ &= \mathbb E_{q_\varphi}\big[f(z)\, \nabla_\varphi \log q_\varphi(z \mid x)\big] . \end{aligned}

This score-function or REINFORCE estimator can be used beyond Gaussian distributions when those regularity conditions hold. Its variance can be large because it uses f(z)f(z) multiplied by a zero-mean score, rather than the local derivative of ff. For q=N(μ,σ2)q=\mathcal N(\mu,\sigma^2), f(z)=z2f(z)=z^2 and μ=σ=1\mu=\sigma=1, the single-sample gradient in μ\mu is (1+ε)2ε(1+\varepsilon)^2\varepsilon: its mean is 22 and variance 3030. The pathwise gradient 2(1+ε)2(1+\varepsilon) has the same mean and variance 44. These moments are recomputed by the local verifier; this comparison is not a universal variance ordering. If ff also depends directly on φ\varphi, its direct derivative must be added.

A Gaussian qq also permits a pathwise estimator. Reparameterization moves the randomness into an input, as in sampling any Gaussian from standard noise:

ε∼N(0,I),z=μ+σ⊙ε,\begin{aligned} \varepsilon &\sim \mathcal N(0, I), \\ z &= \mu + \sigma \odot \varepsilon , \end{aligned}

where ⊙\odot is the element-wise product. The distribution of zz is unchanged, but now ∂zj/∂μj=1\partial z_j / \partial \mu_j = 1 and ∂zj/∂σj=εj\partial z_j / \partial \sigma_j = \varepsilon_j, so, under the differentiation assumptions, the reconstruction gradient flows back into the encoder (Kingma and Welling, 2014, section 2.4). Expectations over zz become expectations over ε\varepsilon, which does not depend on φ\varphi:

∇φ Eqφ(z∣x)[f(z)]=Eε[∇φf(μ+σ⊙ε)].\nabla_\varphi\, \mathbb E_{q_\varphi(z \mid x)}\big[f(z)\big] = \mathbb E_{\varepsilon}\big[\nabla_\varphi f(\mu + \sigma \odot \varepsilon)\big] .
Figure

Fix the noise and vary the parameters

Fixed noise values yield verifiable sample shiftsNoise ε equals −1.5, −0.5, 0.5, 1.5. Base z: −0.65, 0.05, 0.75, 1.45. With shifted mean: −0.45, 0.25, 0.95, 1.65. With increased standard deviation: −0.95, −0.05, 0.85, 1.75. Lower rows are compared with the base.ε: −1.5, −0.5, 0.5, 1.5μ = 0.4, σ = 0.7-0.650.050.751.45zμ = 0.6, σ = 0.7-0.450.250.951.65zμ = 0.4, σ = 0.9-0.95-0.050.851.75zopen circles: base z values
The same four selected ε values are used in every row. Increasing μ by 0.2 moves each z by 0.2. Increasing σ by 0.2 moves it by 0.2ε: left points leftward, right points rightward. These computed z = μ + σε values demonstrate derivatives 1 and ε.

The KL term needs no sampling. Between two Gaussians it has a closed form, derived below:

DKL=−12∑j=1d(1+log⁡σj2−μj2−σj2).D_{\mathrm{KL}} = -\frac12 \sum_{j=1}^{d} \big(1 + \log \sigma_j^2 - \mu_j^2 - \sigma_j^2\big) .

The encoder outputs log⁡σ2\log \sigma^2 rather than σ2\sigma^2. In exact arithmetic, exponentiating a finite log⁡σ2\log\sigma^2 is positive; implementations still need to avoid floating-point underflow and overflow. A linear layer can output any real number, a tiny variance such as 10−410^{-4} becomes a moderate −9.2-9.2, and the KL is written directly in log⁡σ2\log \sigma^2.

What the organized latent space buys#

The KL term encourages the encoder distributions toward the prior, but does not guarantee that prior samples land where the decoder is reliable. Generation follows the model: draw z∼N(0,I)z\sim\mathcal N(0,I), then x∼pθ(x∣z)x\sim p_\theta(x\mid z). The encoder is not needed. Showing only a Gaussian decoder’s mean x^(z)\hat x(z) omits observation noise; it is not a complete model sample. With s2=12s^2=\tfrac12, a sample adds independent noise of standard deviation 0.710.71 per coordinate.

For a continuous decoder mean, x^((1−λ)za+λzb)\hat x((1-\lambda)z_a+\lambda z_b) changes continuously, but continuity alone says nothing about semantic quality. Our three-pixel illustration below uses an explicitly defined sigmoid map; it shows the calculation, not learned image quality. In high dimension the midpoint of two independent N(0,Id)\mathcal N(0,I_d) codes follows N(0,12Id)\mathcal N(0,\tfrac12I_d): its norm concentrates near 0.71d0.71\sqrt d rather than d\sqrt d, inside the prior’s typical shell.

Figure

Interpolation through an explicit decoder

Five points on a latent segment and three intensities for eachRows show λ = 0, 0.25, 0.5, 0.75, 1, the interpolated latent coordinates, three pixels, and their computed intensities between zero and one.λz = (z₁, z₂)three pixels0(-1.00, 1.50)0.23 / 0.74 / 0.080.25(-0.38, 1.00)0.39 / 0.67 / 0.200.5(0.25, 0.50)0.57 / 0.59 / 0.440.75(0.88, 0.00)0.74 / 0.50 / 0.711(1.50, -0.50)0.86 / 0.41 / 0.88
Each strip contains three computed mean pixels: σ(1.2z₁), σ(0.7z₂), σ(z₁ − z₂), where σ is sigmoid. We interpolate between (−1, 1.5) and (1.5, −0.5). Smoothness follows from this chosen formula; no VAE training or semantic image quality is demonstrated.

An attribute direction can be a useful empirical heuristic. Carter and Nielsen (2017) demonstrate a font-bolding direction, and explicitly show artifacts and limitations. Such a direction is not a consequence of the ELBO; no fonts or trained model from that example are used here.

Two separate mechanisms can hurt samples. First, the aggregate encoder distribution can differ from the prior, leaving prior regions poorly represented during reconstruction training. Second, with a fixed-variance Gaussian decoder and overlapping encoder distributions, one code can correspond to several observations; the optimal decoder mean is their conditional average. That average can blur distinct details. Diagonal Gaussian posteriors do have overlapping support; neither their separation nor a particular amount of blur is guaranteed.

A second view relates the average ELBO to a joint forward KL, under the density and finiteness assumptions stated below (Kingma and Welling, 2019, §2.7). In a restricted model family this objective penalizes low model density where the data-encoder joint has mass; the resulting compromise depends on the family. It does not prove that every VAE overestimates variance or produces blurry images.

The average ELBO as a forward KL

Assume the population data distribution and the model have densities with respect to a common base measure, with finite terms in the identity below. Combine pdata(x)p_{\text{data}}(x) and the encoder into qφ(x,z)=pdata(x)qφ(z∣x)q_\varphi(x,z)=p_{\text{data}}(x)q_\varphi(z\mid x). Then:

DKL(qφ(x,z) ∥ pθ(x,z))=Eqφ(x,z) ⁣[log⁡pdata(x)+log⁡qφ(z∣x)pθ(x,z)]=−H(pdata)−Epdata(x)[L(x)].\begin{aligned} &D_{\mathrm{KL}}\big(q_\varphi(x, z) \,\|\, p_\theta(x, z)\big) \\ &\quad= \mathbb E_{q_\varphi(x, z)}\!\left[\log p_{\text{data}}(x) + \log \frac{q_\varphi(z \mid x)}{p_\theta(x, z)}\right] \\ &\quad= -H(p_{\text{data}}) - \mathbb E_{p_{\text{data}}(x)}\big[\mathcal L(x)\big] . \end{aligned}

The data entropy is constant in the parameters, so maximizing the mean ELBO minimizes this KL. For an empirical distribution of point masses against a continuous observation model, the joint KL is instead infinite: that finite-KL interpretation must not be applied literally. The per-observation ELBO and its sample average remain well-defined whenever their own terms are finite.

Sample fidelity and coverage need separate measurement for both VAEs and adversarial models. Richer observation distributions and hierarchical latents can improve the basic Gaussian VAE. For example, Vahdat and Kautz (2020) reported successful NVAE generation at 256×256256\times256 resolution; that published result is not reproduced here, and no images, weights or dataset from it are included.

Where the ELBO comes from#

Drop θ\theta and φ\varphi for the derivation. Multiply the integrand of the evidence by q(z∣x)/q(z∣x)q(z \mid x)/q(z \mid x), which needs q>0q > 0 wherever p(x,z)>0p(x, z) > 0, true for a nondegenerate Gaussian qq:

log⁡p(x)=log⁡∫p(x,z) dz=log⁡Eq(z∣x) ⁣[p(x,z)q(z∣x)]≥Eq(z∣x) ⁣[log⁡p(x,z)q(z∣x)]=L(x).\begin{aligned} \log p(x) &= \log \int p(x, z)\, dz \\ &= \log \mathbb E_{q(z \mid x)}\!\left[\frac{p(x, z)}{q(z \mid x)}\right] \\ &\ge \mathbb E_{q(z \mid x)}\!\left[\log \frac{p(x, z)}{q(z \mid x)}\right] = \mathcal L(x). \end{aligned}

The inequality is Jensen’s for the concave logarithm, log⁡E[Y]≥E[log⁡Y]\log \mathbb E[Y] \ge \mathbb E[\log Y].

Figure

Jensen's inequality for the concave logarithm

The chord of log y lies below the curveThe concave curve y = log of Y for Y from 0.3 to 6.2. Two points on it, at Y = 0.6 and Y = 5.4, are joined by a straight dashed chord. At the mean E[Y] = 3, the curve is at log E[Y] = 1.10 and the chord is lower, at E[log Y] = 0.59. An amber segment between them is labelled Jensen gap. A box states log E[Y] is greater than or equal to E[log Y].-1012Ylog YaE[Y]b(a, log a)(b, log b)log E[Y] = 1.10E[log Y] = 0.59Jensen gapchord lies below the concave curvelog E[Y] ≥ E[log Y]The chord of log y lies below the curveThe concave curve y = log of Y for Y from 0.3 to 6.2. Two points on it, at Y = 0.6 and Y = 5.4, are joined by a straight dashed chord. At the mean E[Y] = 3, the curve is at log E[Y] = 1.10 and the chord is lower, at E[log Y] = 0.59. An amber segment between them is labelled Jensen gap. A box states log E[Y] is greater than or equal to E[log Y].-1012Ylog YaE[Y]b(a, log a)(b, log b)log E[Y] = 1.10E[log Y] = 0.59Jensen gapchord lies below the concave curvelog E[Y] ≥ E[log Y]
Y takes the values 0.6 and 5.4 with probability ½ each. The chord between the two points lies below the concave log curve, so E[log Y] = 0.59 is below log E[Y] = log 3 = 1.10. For a convex f the inequality flips.

Writing p(x,z)=p(x∣z) p(z)p(x, z) = p(x \mid z)\, p(z) splits the bound into the two terms used above:

L(x)=Eq ⁣[log⁡p(x∣z)+log⁡p(z)q(z∣x)]=Eq[log⁡p(x∣z)]−DKL(q(z∣x) ∥ p(z)).\begin{aligned} \mathcal L(x) &= \mathbb E_{q}\!\left[\log p(x \mid z) + \log \frac{p(z)}{q(z \mid x)}\right] \\ &= \mathbb E_{q}\big[\log p(x \mid z)\big] - D_{\mathrm{KL}}\big(q(z \mid x) \,\|\, p(z)\big) . \end{aligned}

Jensen shows that the bound holds; it does not say how loose it is. Writing p(x,z)=p(z∣x) p(x)p(x, z) = p(z \mid x)\, p(x) instead gives the exact gap:

log⁡p(x)−L(x)=Eq ⁣[log⁡p(x)−log⁡p(z∣x) p(x)q(z∣x)]=Eq[log⁡q(z∣x)−log⁡p(z∣x)]=DKL(q(z∣x) ∥ p(z∣x))≥0.\begin{aligned} \log p(x) - \mathcal L(x) &= \mathbb E_{q}\!\left[\log p(x) - \log\frac{p(z\mid x)\,p(x)}{q(z \mid x)}\right] \\ &= \mathbb E_{q}\big[\log q(z \mid x) - \log p(z \mid x)\big] \\ &= D_{\mathrm{KL}}\big(q(z \mid x) \,\|\, p(z \mid x)\big) \ge 0 . \end{aligned}

The bound is tight exactly when qq is the true posterior. The variational inference note derives the same decomposition for any latent-variable model and explains why this objective targets the reverse KL.

The gap shows what each network does. Over the encoder, log⁡pθ(x)\log p_\theta(x) is fixed, so raising L\mathcal L only brings qφq_\varphi closer to the posterior in reverse KL. Over the decoder, L=log⁡pθ(x)−DKL(qφ ∥ pθ(z∣x))\mathcal L = \log p_\theta(x) - D_{\mathrm{KL}}\big(q_\varphi \,\|\, p_\theta(z \mid x)\big) can also rise by making the true posterior easier for qq to fit, which biases the model toward such posteriors. Maximizing the ELBO maximizes the likelihood only approximately (Kingma and Welling, 2019, section 2.2.1).

Which distribution is fixed? The prior#

The prior p(z)=N(0,I)p(z) = \mathcal N(0, I) is fixed. The posteriors are not: every image gets its own μ(x)\mu(x) and σ2(x)\sigma^2(x), and the KL term only charges for how far they stray.

For one coordinate, with q=N(μ,σ2)q = \mathcal N(\mu, \sigma^2) and p=N(0,1)p = \mathcal N(0, 1),

log⁡q(z)=−12log⁡(2πσ2)−(z−μ)22σ2,log⁡p(z)=−12log⁡(2π)−z22.\begin{aligned} \log q(z) &= -\tfrac12 \log(2\pi\sigma^2) - \frac{(z-\mu)^2}{2\sigma^2}, \\ \log p(z) &= -\tfrac12 \log(2\pi) - \frac{z^2}{2}. \end{aligned}

Under z∼qz \sim q we have E[(z−μ)2]=σ2\mathbb E[(z-\mu)^2] = \sigma^2 and E[z2]=μ2+σ2\mathbb E[z^2] = \mu^2 + \sigma^2, so

DKL(q ∥ p)=Eq[log⁡q−log⁡p]=−12log⁡σ2−12+12(μ2+σ2)=12(μ2+σ2−1−log⁡σ2).\begin{aligned} D_{\mathrm{KL}}(q \,\|\, p) &= \mathbb E_q[\log q - \log p] \\ &= -\tfrac12\log \sigma^2 - \tfrac12 + \tfrac12(\mu^2 + \sigma^2) \\ &= \tfrac12\big(\mu^2 + \sigma^2 - 1 - \log\sigma^2\big). \end{aligned}

For the diagonal encoder, both q=∏jN(μj,σj2)q = \prod_j \mathcal N(\mu_j, \sigma_j^2) and p=∏jN(0,1)p = \prod_j \mathcal N(0, 1) factorize. The log ratio log⁡q−log⁡p\log q - \log p is then a sum over jj of terms that each depend on zjz_j alone, and linearity of expectation adds the one-coordinate results (Kingma and Welling, 2014, appendix B):

DKL(q ∥ N(0,I))=12∑j=1d(μj2+σj2−1−log⁡σj2).D_{\mathrm{KL}}\big(q \,\|\, \mathcal N(0, I)\big) = \frac12 \sum_{j=1}^{d} \big(\mu_j^2 + \sigma_j^2 - 1 - \log\sigma_j^2\big) .

The value is zero only at μ=0\mu = 0, σ=1\sigma = 1, because log⁡t≤t−1\log t \le t - 1 with equality only at t=1t = 1. A full covariance Σ\Sigma gives 12(tr⁡Σ+μ⊤μ−d−log⁡det⁡Σ)\tfrac12\big(\operatorname{tr}\Sigma + \mu^\top\mu - d - \log\det\Sigma\big) by the same steps with a trace in place of each square (folded below); correlation then has its own price, −12log⁡(1−ρ2)-\tfrac12\log(1 - \rho^2) for two unit-variance coordinates with correlation ρ\rho, which the diagonal encoder never pays because it cannot correlate at all.

The trace step for a full covariance

A scalar equals its own trace, and the trace is linear and cyclic, so for z∼N(μ,Σ)z \sim \mathcal N(\mu, \Sigma)

E[(z−μ)⊤Σ−1(z−μ)]=tr⁡(Σ−1 E[(z−μ)(z−μ)⊤])=tr⁡(Σ−1Σ)=d,E[z⊤z]=tr⁡ E[zz⊤]=tr⁡Σ+μ⊤μ.\begin{aligned} \mathbb E\big[(z - \mu)^\top \Sigma^{-1} (z - \mu)\big] &= \operatorname{tr}\big(\Sigma^{-1}\, \mathbb E[(z - \mu)(z - \mu)^\top]\big) \\ &= \operatorname{tr}(\Sigma^{-1}\Sigma) = d, \\ \mathbb E[z^\top z] &= \operatorname{tr}\, \mathbb E[z z^\top] = \operatorname{tr}\Sigma + \mu^\top \mu . \end{aligned}

With log⁡q(z)=−12log⁡det⁡(2πΣ)−12(z−μ)⊤Σ−1(z−μ)\log q(z) = -\tfrac12\log\det(2\pi\Sigma) - \tfrac12 (z - \mu)^\top\Sigma^{-1}(z - \mu) and log⁡p(z)=−d2log⁡2π−12z⊤z\log p(z) = -\tfrac d2 \log 2\pi - \tfrac12 z^\top z, the 2π2\pi terms cancel and

DKL(q ∥ p)=−12log⁡det⁡Σ−d2+12(tr⁡Σ+μ⊤μ).\begin{aligned} D_{\mathrm{KL}}(q \,\|\, p) &= -\tfrac12\log\det\Sigma - \tfrac d2 + \tfrac12\big(\operatorname{tr}\Sigma + \mu^\top\mu\big) . \end{aligned}

For μ=0\mu = 0 and Σ\Sigma with unit diagonal and off-diagonal ρ\rho, tr⁡Σ=2=d\operatorname{tr}\Sigma = 2 = d and det⁡Σ=1−ρ2\det\Sigma = 1 - \rho^2, which leaves −12log⁡(1−ρ2)-\tfrac12\log(1 - \rho^2).

Read the formula as a fine:

μ\muσ\sigmaDKLD_{\mathrm{KL}} (nats)
010
110.5
212
00.50.318
020.807
00.11.808
00.014.105

Moving the mean costs 12μ2\tfrac12\mu^2. Shrinking the variance costs about −log⁡σ−12-\log\sigma - \tfrac12, which grows only logarithmically, yet without bound: a point code, as in a plain autoencoder, would pay an infinite fine, since a point mass has no finite KL against a density. Each image can therefore afford a fairly narrow, off-centre Gaussian when that helps reconstruction, but never a single point.

Figure

The KL fine grows only logarithmically as σ → 0

KL divergence to the standard normal as a function of σ and of μTwo plots of the KL divergence from N(mu, sigma squared) to N(0, 1). First, with mu = 0, as a function of sigma from 0 to 3: a U-shaped curve with minimum 0 at sigma = 1, value 1.81 at sigma = 0.1, 0.32 at sigma = 0.5 and 0.81 at sigma = 2; for small sigma it rises like minus log sigma minus one half and goes to infinity as sigma goes to 0. Second, with sigma = 1, as a function of mu from minus 2.5 to 2.5: the parabola one half mu squared, 0.5 at mu = 1 and 2 at mu = minus 2, minimum 0 at mu = 0.μ = 0, vary σ012300.5123σKL, nats1.810.320.81≈ −log σ − ½,→ ∞ as σ → 0½σ² − log σ − ½σ = 1, vary μ0123-2-1012μKL, nats20.50½ μ²KL divergence to the standard normal as a function of σ and of μTwo plots of the KL divergence from N(mu, sigma squared) to N(0, 1). First, with mu = 0, as a function of sigma from 0 to 3: a U-shaped curve with minimum 0 at sigma = 1, value 1.81 at sigma = 0.1, 0.32 at sigma = 0.5 and 0.81 at sigma = 2; for small sigma it rises like minus log sigma minus one half and goes to infinity as sigma goes to 0. Second, with sigma = 1, as a function of mu from minus 2.5 to 2.5: the parabola one half mu squared, 0.5 at mu = 1 and 2 at mu = minus 2, minimum 0 at mu = 0.μ = 0, vary σ012300.5123σKL, nats1.810.320.81≈ −log σ − ½,→ ∞ as σ → 0½σ² − log σ − ½σ = 1, vary μ0123-2-1012μKL, nats20.50½ μ²
KL = ½(μ² + σ² − 1 − log σ²), in nats. At μ = 0, shrinking σ costs about −log σ − ½; widening costs about σ²/2. At σ = 1, shifting costs μ²/2. The only zero is μ = 0, σ = 1; the penalty diverges as σ → 0.

What does the KL term ask of the codes as a whole? Take NN training images and their aggregate posterior, the mixture of all their posteriors:

q(z)=1N∑n=1Nq(z∣xn).q(z) = \frac1N \sum_{n=1}^{N} q(z \mid x_n) .

Treat the index nn as uniform on {1,…,N}\lbrace 1, \dots, N\rbrace. The average KL term then splits in two (Hoffman and Johnson, 2016):

1N∑n=1NDKL(q(z∣xn) ∥ p(z))=Iq(n;z)+DKL(q(z) ∥ p(z)).\begin{aligned} &\frac1N \sum_{n=1}^{N} D_{\mathrm{KL}}\big(q(z \mid x_n) \,\|\, p(z)\big) \\ &\quad= I_q(n; z) + D_{\mathrm{KL}}\big(q(z) \,\|\, p(z)\big). \end{aligned}
Derivation of the split

Write q(z∣xn)/p(z)q(z \mid x_n)/p(z) as (q(z∣xn)/q(z))⋅(q(z)/p(z))\big(q(z \mid x_n)/q(z)\big)\cdot\big(q(z)/p(z)\big) and average the logarithm over nn and z∼q(z∣xn)z \sim q(z \mid x_n). The first factor averages to the mutual information between an image’s index and its code, by its definition. The second depends on zz alone, and averaging over nn then zz is averaging over the mixture q(z)q(z), which gives the marginal KL.

The mutual information is bounded by H(n)=log⁡NH(n)=\log N. Reconstructing distinguishable observations accurately may require information about their index, but duplicates and a powerful conditional decoder can change how much is necessary. The marginal KL measures aggregate mismatch; it does not certify decoder quality. In particular, Gaussian mixtures have positive density everywhere, so “holes” here mean regions of very low encoder density relative to the prior, not literally absent support.

The prior appears only in the marginal KL, so, among unrestricted prior densities with the encoder fixed, the best prior is the aggregate posterior itself. That suggests learning the prior instead of fixing it, for instance with a normalizing flow over zz. The VQ-VAE of the next note learns its prior after the autoencoder is trained.

The DDPM construction can be read as a hierarchical latent-variable model with a fixed forward noising distribution and a learned reverse chain (DDPM objective). Latent diffusion applies diffusion in an autoencoder’s lower-dimensional representation. Compression reduces the number of coordinates; a Gaussian aggregate code distribution does not follow from compression or from a finite KL penalty alone.

Where it breaks: posterior collapse#

A decoder strong enough to model the images on its own can ignore the code. The encoder then outputs the prior for every image, the KL term is zero, and the code carries nothing. This is posterior collapse (Bowman et al., 2016).

The ELBO does not prevent it, and a one-dimensional Gaussian model shows why exactly. Let the data be x∼N(0,1.1)x \sim \mathcal N(0, 1.1), the prior N(0,1)\mathcal N(0, 1), and the decoder p(x∣z)=N(wz,s2)p(x \mid z) = \mathcal N(wz, s^2) with w2+s2=1.1w^2 + s^2 = 1.1. Every such decoder gives the data its true distribution, so all of them have the same likelihood. The exact posterior is Gaussian, so the best Gaussian encoder equals it and the ELBO is tight. The rate, the average KL term, then equals the mutual information 12log⁡(1+w2/s2)\tfrac12\log(1 + w^2/s^2) (folded below):

decoderwws2s^2rate (nats)log⁡p(x=1)\log p(x = 1)
uses the code10.11.199−1.4211-1.4211
partly0.50.850.129−1.4211-1.4211
collapsed01.10−1.4211-1.4211
Where the rate comes from

With qq the exact posterior, the aggregate posterior is the prior: averaging p(z∣x)p(z \mid x) over the model’s own p(x)p(x), which here is the data distribution, returns p(z)p(z). The marginal KL of the ELBO surgery vanishes, and the rate is the mutual information I(x;z)=H(z)−H(z∣x)I(x; z) = H(z) - H(z \mid x). By the conditional formula with Var⁡z=1\operatorname{Var} z = 1, Cov⁡(x,z)=w\operatorname{Cov}(x, z) = w and Var⁡x=w2+s2\operatorname{Var} x = w^2 + s^2, the posterior variance is 1−w2/(w2+s2)=s2/(w2+s2)1 - w^2/(w^2 + s^2) = s^2/(w^2 + s^2), the same for every xx. A Gaussian of variance vv has entropy 12log⁡(2πev)\tfrac12\log(2\pi e v); the 2πe2\pi e cancels in the difference, so

I(x;z)=12log⁡1−12log⁡s2w2+s2=12log⁡(1+w2s2).\begin{aligned} I(x; z) &= \tfrac12 \log 1 - \tfrac12 \log \frac{s^2}{w^2 + s^2} \\ &= \tfrac12 \log\Big(1 + \frac{w^2}{s^2}\Big) . \end{aligned}

For w=1w = 1, s2=0.1s^2 = 0.1 this is 12ln⁡11=1.199\tfrac12\ln 11 = 1.199; the likelihood column is log⁡N(1; 0, 1.1)\log \mathcal N(1;\, 0,\, 1.1) for all three.

In this constructed population example the bound is equally good at all three solutions, so it does not identify how much information the code should carry. A fixed-variance factorized Gaussian that ignores zz has only one unconditional mean; its squared-error optimum is the data mean. An expressive autoregressive decoder can model much richer data without zz, making collapse a practical concern. KL annealing gradually raises the KL weight from zero to one (Bowman et al., 2016). Free bits replace the KL cost for each latent group by max⁡(λ,D‾KL,j)\max(\lambda,\overline{D}_{\mathrm{KL},j}), with the bar an average over a minibatch in the formulation of Kingma and Welling (2019), §2.8.1. Below the threshold, reducing KL no longer improves that term. Both modify the optimization incentives; neither guarantees useful codes.

Conditioning on a label: the conditional VAE#

The basic VAE cannot be told what to generate. The conditional VAE (CVAE) adds an observed condition cc, such as a class label or a vector of binary attributes, to every part of the model (Sohn, Yan and Lee, 2015, section 4): a prior pθ(z∣c)p_\theta(z \mid c), often simply N(0,I)\mathcal N(0, I) for every cc; a decoder pθ(x∣z,c)p_\theta(x \mid z, c); and an encoder qφ(z∣x,c)q_\varphi(z \mid x, c). The derivation of the ELBO goes through with everything conditioned on cc:

log⁡pθ(x∣c)≥Eqφ(z∣x,c)[log⁡pθ(x∣z,c)]−DKL(qφ(z∣x,c) ∥ pθ(z∣c)),\begin{aligned} \log p_\theta(x \mid c) \ge{}& \mathbb E_{q_\varphi(z \mid x, c)}\big[\log p_\theta(x \mid z, c)\big] \\ &- D_{\mathrm{KL}}\big(q_\varphi(z \mid x, c) \,\|\, p_\theta(z \mid c)\big), \end{aligned}

with the gap DKL(qφ(z∣x,c) ∥ pθ(z∣x,c))D_{\mathrm{KL}}\big(q_\varphi(z \mid x, c) \,\|\, p_\theta(z \mid x, c)\big). With the fixed prior, training uses the same reparameterization and the same closed-form KL; a learned Gaussian prior needs the general KL between two Gaussians. In the networks, cc is usually concatenated to the encoder’s input and to zz before the decoder.

Conditioning gives the decoder information it need not transmit through zz, but does not ensure disentanglement. A transparent constructed example is x∣z,c∼N(1.4z+0.8c,0.36)x\mid z,c\sim\mathcal N(1.4z+0.8c,0.36) with c∈{−1,1}c\in\{-1,1\}. Holding z=1z=1 fixed gives means 0.60.6 and 2.22.2, a shift of 1.61.6. Here that behavior is guaranteed by the chosen formula. In a learned image model, keeping zz and changing cc need not preserve identity, pose or any other unconditioned attribute. The conditional GAN uses an adversarial objective for a related conditioning task.

What you should remember#

  • log⁡pθ(x)=L(x)+DKL(qφ(z∣x)∥pθ(z∣x))\log p_\theta(x)=\mathcal L(x)+D_{\mathrm{KL}}(q_\varphi(z\mid x)\|p_\theta(z\mid x)); the prior KL inside L\mathcal L is a different quantity from this posterior gap.
  • Prior Monte Carlo can require exponentially many samples, as the independent-coordinate example demonstrates.
  • Reparameterization z=μ+σ⊙εz=\mu+\sigma\odot\varepsilon provides a pathwise gradient under the differentiation conditions; diagonal-Gaussian KL is analytic.
  • Fixed decoder variance s2=12s^2=\tfrac12 gives summed squared error plus KL; a shared learned variance depends on the overall expected MSE.
  • Prior mismatch and conditional averaging are separate sample-quality problems; continuous interpolation does not guarantee meaningful intermediate objects.
  • Collapse can coexist with an optimal ELBO. Annealing and free bits change the training objective, without guaranteeing informative codes.

Notebook#

Run python3 scripts/notes/generative-practice.py vae. The standalone script uses four newly specified scalar observations, −1.3,−0.2,0.7,1.8-1.3,-0.2,0.7,1.8, a standard normal latent variable and a decoder with mean 1.4z1.4z and variance 0.36. It evaluates an encoder with mean 0.5x0.5x and variance 0.4. All Gaussian parameters and observations are defined in the file.

  • Calculate expected reconstruction log probability and prior KL separately. Their difference is the ELBO. The saved results give mean ELBO −1.996397 and mean log likelihood −1.633903; their gap 0.362494 equals the average KL to the exact posterior.
  • Check the exact posterior: mean 0.603448x0.603448x and variance 0.155172. An encoder can have nonzero KL to the prior while having zero gap to the posterior; the two KL terms answer different questions.
  • At x=0.7x=0.7, generate 40,000 reparameterized latent samples. Their mean reconstruction log probability is −1.564136, close to the analytic −1.558252. This checks the stochastic expectation and the sign of the bound. It does not train a convolutional VAE or measure generated-image quality.

The example, script and observations were newly authored for this course with Codex assistance; the numerical results are from the linked run.

The analytic checks and both new illustrative decoders are reproduced by python3 scripts/notes/check-vae-renewal.py. Its saved output also checks the shared-variance optimum, estimator moments, aggregate-KL split and collapse table. These are constructed calculations, not image-model benchmarks.

Next#

The VAE gives a tractable learning objective for a latent-variable generator. Its inference family, observation model and prior each impose constraints. The next note changes those choices through weighted KL penalties and discrete codes with a separately trained prior.

References#