Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Quadratic forms, entropy, KL — closed-form Gaussian quantities

Why is variational inference with Gaussian distributions so much faster than VI with anything else? Because every quantity you need — log-density, entropy, score, KL, expected log-likelihood, mutual information — has a closed form in terms of μ\boldsymbol{\mu}, Σ\boldsymbol{\Sigma}, and a Cholesky factor. No Monte Carlo, no quadrature, just linear algebra. This notebook is the catalog.

What you’ll learn

  1. The quadratic form 12(x−μ)⊤Σ−1(x−μ)\tfrac{1}{2}(\mathbf{x}-\boldsymbol{\mu})^\top\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu}) — the workhorse, computed via Cholesky and triangular solves.
  2. Score ∇xlog⁡p(x)\nabla_{\mathbf{x}}\log p(\mathbf{x}) — fundamental for HMC, Langevin, diffusion, score matching.
  3. Entropy and cross-entropy, and the identity that links them to KL.
  4. KL between two Gaussians — full closed form, asymmetry, mode-covering vs mode-seeking.
  5. Expected log-likelihood under a Gaussian — the data-fit term of every Gaussian ELBO.
  6. Mutual information between sub-blocks — closed-form information geometry of an MVN.
  7. A one-step ELBO putting the closed-form KL and ELL together.

1. The quadratic form δ⊤Σ−1δ\delta^\top \boldsymbol{\Sigma}^{-1}\delta

What it is. The bilinear form below is the squared Mahalanobis distance from x\mathbf{x} to the mean. Geometrically it’s the squared Euclidean distance after whitening — i.e. after rotating and rescaling so that Σ\boldsymbol{\Sigma} looks like the identity. So contours of constant QQ are exactly the Mahalanobis ellipsoids of 0.1 §2.

Continuous form.

Q(x;μ,Σ)=(x−μ)⊤Σ−1(x−μ).Q(\mathbf{x}; \boldsymbol{\mu}, \boldsymbol{\Sigma}) = (\mathbf{x}-\boldsymbol{\mu})^\top\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu}).

Numerical recipe. With Cholesky Σ=LL⊤\boldsymbol{\Sigma} = \mathbf{L}\mathbf{L}^\top and the whitened residual z=L−1(x−μ)\mathbf{z} = \mathbf{L}^{-1}(\mathbf{x}-\boldsymbol{\mu}), equation ((1)) collapses to a single triangular solve plus a dot product:

Q=z⊤z=∑izi2.Q = \mathbf{z}^\top\mathbf{z} = \sum_i z_i^2.

Two reasons this is the right way to compute equation ((1)):

  • Don’t form Σ−1\boldsymbol{\Sigma}^{-1}. As argued in 0.1 §6, Cholesky-factor once and do triangular solves — explicit inversion is O(d3)O(d^3) with worse constants and worse stability.
  • Stability is square-rooted. The condition number of L\mathbf{L} is κ(Σ)\sqrt{\kappa(\boldsymbol{\Sigma})}, much friendlier than κ(Σ)\kappa(\boldsymbol{\Sigma}). Explicit-inverse routes lose precision an order faster on borderline-PD covariances.

Interpretation & where it shows up. Equation ((1)) is the atom of every Gaussian closed form below — log-density, KL, expected log-likelihood. When x∼N(μ,Σ)\mathbf{x}\sim\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma}), QQ is χd2\chi^2_d-distributed, which is why “kk-sigma” outliers are diagnosed by their Mahalanobis distance. gaussx.quadratic_form(operator, x) returns x⊤A−1x\mathbf{x}^\top\mathbf{A}^{-1}\mathbf{x} via this Cholesky route.

  quadratic_form (gaussx) : 1.2320539338
  manual L^-1 then ||.||² : 1.2320539338
  naive  δᵀ Σ⁻¹ δ via inv : 1.2320539338

2. The score ∇xlog⁡p(x)\nabla_{\mathbf{x}}\log p(\mathbf{x})

What it is. The score is the gradient of the log-density with respect to x\mathbf{x} — a vector field on Rd\mathbb{R}^d that points in the direction of locally increasing density. For Gaussians it is linear in x\mathbf{x}; this is the only family for which the score is exactly affine, and that linearity is the reason so many Gaussian-based algorithms (Langevin, HMC, diffusion) have closed-form drift terms.

Continuous form.

∇xlog⁡p(x)=−Σ−1(x−μ).\nabla_{\mathbf{x}}\log p(\mathbf{x}) = -\boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu}).

Numerical recipe. A single solve against Σ\boldsymbol{\Sigma}:

s(x)=−solve(Σ,x−μ),s(\mathbf{x}) = -\mathrm{solve}(\boldsymbol{\Sigma}, \mathbf{x}-\boldsymbol{\mu}),

reusing the same Cholesky factor used for equation ((2)).

Interpretation & where it shows up.

  • Langevin dynamics. The SDE dXt=∇log⁡p(Xt) dt+2 dWtd\mathbf{X}_t = \nabla\log p(\mathbf{X}_t)\,dt + \sqrt{2}\,d\mathbf{W}_t targets pp as its stationary distribution. The drift is exactly equation ((3)) for Gaussian pp.
  • HMC / NUTS. The leapfrog integrator pushes momentum proportional to the score — for a Gaussian target, that step is one solve.
  • Score matching and diffusion models. The training objective is to learn sθ(x)≈∇log⁡p(x)s_\theta(\mathbf{x}) \approx \nabla\log p(\mathbf{x}). For a Gaussian noise model the target is exactly equation ((3)), which is why the analytic Gaussian denoiser is the canonical baseline.
  • Fisher score for parameter estimation. Differentiating wrt parameters θ\boldsymbol{\theta} rather than wrt x\mathbf{x} gives the gradient used in MLE; the same machinery underpins natural-gradient methods in 0.4.
score (closed form) : [-1.15744937  1.40495788 -1.21047334  0.83763447]
score (jax.grad)    : [-1.15744937  1.40495788 -1.21047334  0.83763447]
max |Δ|             : 0.00e+00

3. Entropy

What it is. Differential entropy is the continuous analogue of Shannon entropy: the expected negative log-density, measured in nats per draw. For Gaussians it depends only on the covariance — the mean is a translation, which doesn’t change spread.

Continuous form.

H(p)=−Ep[log⁡p(x)]=12log⁡ ⁣((2πe)d ∣Σ∣).H(p) = -\mathbb{E}_p[\log p(\mathbf{x})] = \tfrac{1}{2}\log\!\big((2\pi e)^d\,\lvert\boldsymbol{\Sigma}\rvert\big).

The derivation uses equation ((1)): log⁡p\log p is a constant plus a linear function of Q(x)Q(\mathbf{x}), and Ep[Q(x)]=d\mathbb{E}_p[Q(\mathbf{x})] = d since z=L−1(x−μ)∼N(0,I)\mathbf{z}=\mathbf{L}^{-1}(\mathbf{x}-\boldsymbol{\mu})\sim\mathcal{N}(\mathbf{0},\mathbf{I}).

Numerical recipe. Equation ((5)) reduces to a single log-determinant:

H(p)=d2(1+log⁡2π)+12log⁡∣Σ∣=d2(1+log⁡2π)+∑ilog⁡Lii,H(p) = \tfrac{d}{2}(1 + \log 2\pi) + \tfrac{1}{2}\log\lvert\boldsymbol{\Sigma}\rvert = \tfrac{d}{2}(1 + \log 2\pi) + \sum_i \log L_{ii},

so the same Cholesky factor used in ((2)) gives entropy “for free” via the diagonal of L\mathbf{L}.

Interpretation & where it shows up.

  • Log-volume of the Mahalanobis ellipsoid. ∣Σ∣\sqrt{\lvert\boldsymbol{\Sigma}\rvert} is proportional to the volume of the unit Mahalanobis ball; equation ((5)) is its log up to a dd-dependent constant.
  • Maximum-entropy distributions. Among distributions on Rd\mathbb{R}^d with a fixed mean and covariance, the Gaussian is the unique maximiser of ((5)). Picking a Gaussian prior is the most-uncertain choice consistent with what you know about the first two moments.
  • Building block. Equation ((5)) is a component of mutual information ((18)), KL ((11)), and the ELBO ((20)).
H (gaussx)        : 5.063043
H (manual log|Σ|) : 5.063044
H (MC, 20k samples): 5.055965

4. Cross-entropy and the H / KL / cross-entropy identity

What it is. Cross-entropy is the expected negative log-likelihood of qq when reality is pp. It’s the foundation of every probabilistic loss function — log-loss, NLL, log-likelihood — and decomposes neatly into entropy plus KL.

Continuous form.

H(p,q)=−Ep[log⁡q(x)].H(p, q) = -\mathbb{E}_p[\log q(\mathbf{x})].

For two Gaussians this is closed-form, with two extra terms beyond equation ((5)) accounting for mean and covariance mismatch:

H(p,q)=d2log⁡2π+12log⁡∣Σq∣+12tr(Σq−1Σp)+12(μq−μp)⊤Σq−1(μq−μp).H(p, q) = \tfrac{d}{2}\log 2\pi + \tfrac{1}{2}\log\lvert\boldsymbol{\Sigma}_q\rvert + \tfrac{1}{2}\mathrm{tr}(\boldsymbol{\Sigma}_q^{-1}\boldsymbol{\Sigma}_p) + \tfrac{1}{2}(\boldsymbol{\mu}_q-\boldsymbol{\mu}_p)^\top\boldsymbol{\Sigma}_q^{-1}(\boldsymbol{\mu}_q-\boldsymbol{\mu}_p).

The clean identity that ties everything together is

KL(p ∥ q)=H(p,q)−H(p),\mathrm{KL}(p \,\Vert\, q) = H(p, q) - H(p),

which is why minimising NLL is exactly minimising KL (for any fixed reference pp).

Numerical recipe. Don’t recompute the trace and quadratic terms by hand — let gaussx evaluate H(p)+KL(p∥q)H(p) + \mathrm{KL}(p\Vert q) via equation ((9)), since both pieces share Cholesky factors with everything else in the notebook.

Interpretation & where it shows up.

  • NLL = cross-entropy. Training a model by minimising negative log-likelihood is minimising H(pdata,qθ)H(p_{\text{data}}, q_\theta) where qθq_\theta is the model. The data entropy H(pdata)H(p_{\text{data}}) is constant, so this is equivalent to minimising KL(pdata∥qθ)\mathrm{KL}(p_{\text{data}}\Vert q_\theta) — the population analogue of MLE.
  • ELBO decomposition. Rearranging equation ((9)) for variational inference gives the form log⁡p(y)=ELBO(q)+KL(q∥ppost)\log p(\mathbf{y}) = \mathrm{ELBO}(q) + \mathrm{KL}(q\Vert p_{\text{post}}) that we’ll exploit in §10.
  • Strictly proper scoring rules. H(p,q)H(p, q) is the expected log-score of qq; equation ((9)) shows that this score is strictly proper — uniquely minimised at q=pq = p, with no degenerate plateaus.
H(p, q) closed form  : 3.760488
H(p) + KL(p||q)      : 3.760488
max |Δ|              : 3.13e-08

5. KL between two Gaussians

What it is. Relative entropy. The expected log-ratio between pp and qq, in nats per draw. It is not a metric — it isn’t symmetric and doesn’t satisfy the triangle inequality — but it is the unique divergence with the right invariances for Bayesian inference.

Continuous form. From the definition plus equation ((9)):

KL(p ∥ q)=Ep ⁣[log⁡p(x)q(x)]=H(p,q)−H(p).\mathrm{KL}(p\,\Vert\,q) = \mathbb{E}_p\!\left[\log\frac{p(\mathbf{x})}{q(\mathbf{x})}\right] = H(p, q) - H(p).

For two Gaussians, combining equation ((8)) with −H(p)-H(p) from ((5)) gives

KL(p ∥ q)=12[tr(Σq−1Σp)+(μq−μp)⊤Σq−1(μq−μp)−d+log⁡∣Σq∣∣Σp∣].\mathrm{KL}(p\,\Vert\,q) = \tfrac{1}{2}\bigl[\mathrm{tr}(\boldsymbol{\Sigma}_q^{-1}\boldsymbol{\Sigma}_p) + (\boldsymbol{\mu}_q-\boldsymbol{\mu}_p)^\top\boldsymbol{\Sigma}_q^{-1}(\boldsymbol{\mu}_q-\boldsymbol{\mu}_p) - d + \log\tfrac{\lvert\boldsymbol{\Sigma}_q\rvert}{\lvert\boldsymbol{\Sigma}_p\rvert}\bigr].

Numerical recipe. Three diagnostic limits sharpen what each term in ((11)) is doing:

  • Same distribution (p=qp = q): trace gives dd, Δμ=0\Delta\boldsymbol{\mu} = \mathbf{0}, log-ratio of dets is 0. KL collapses to zero — the only fixed point. ✓
  • Same covariance, different means (Σp=Σq=Σ\boldsymbol{\Sigma}_p = \boldsymbol{\Sigma}_q = \boldsymbol{\Sigma}): trace = dd, log-ratio = 0, only the quadratic-form term ((1)) survives. So KL=12Q(μp;μq,Σ)\mathrm{KL} = \tfrac{1}{2}Q(\boldsymbol{\mu}_p; \boldsymbol{\mu}_q, \boldsymbol{\Sigma}) — half the Mahalanobis distance between the means.
  • Same mean, different covariances: quadratic vanishes. What’s left is a function of the spectrum of Σq−1Σp\boldsymbol{\Sigma}_q^{-1}\boldsymbol{\Sigma}_p — small when the two ellipsoids are similar in shape, large when one is much elongated relative to the other.

gaussx.dist_kl_divergence(p_loc, p_cov, q_loc, q_cov) evaluates equation ((11)) directly via Cholesky, sharing factors with ((6)) and ((2)).

Interpretation & where it shows up.

  • Variational gap. The ELBO is log⁡p(y)−KL(q∥ppost)\log p(\mathbf{y}) - \mathrm{KL}(q\Vert p_{\text{post}}) — fitting qq to ppostp_{\text{post}} is exactly minimising this KL. We use it concretely in §10.
  • Bayesian model comparison. Posterior agreement between two models is bounded by the KL between their predictive distributions; equation ((11)) is the closed form when both predictives are Gaussian.
  • Information bottleneck, β-VAEs, mutual-information regularisers. All use ((11)) (or ((14)) below) as a scalable, differentiable proxy for “how different are these two distributions”.
  • Asymmetry matters. That KL(p∥q)≠KL(q∥p)\mathrm{KL}(p\Vert q) \ne \mathrm{KL}(q\Vert p) is the headline of §6.
KL(p||p)            : 0.00e+00
KL (same Σ)         : 0.519802
½ Mahalanobis(Δμ)   : 0.519802
KL (same μ)         : 0.598431

6. Forward vs reverse KL — mode-covering vs mode-seeking

What it is. Equation ((11)) is asymmetric — swapping pp and qq gives a different answer. Which direction you minimise determines which mismatches between pp and qq get punished most:

  • Forward / inclusive / zero-avoiding: KL(p∥q)\mathrm{KL}(p\Vert q) blows up wherever p>0p > 0 but q→0q\to 0. So the optimal qq ends up mode-covering — it spreads to cover all of pp’s support, even at the cost of putting mass where pp is small.
  • Reverse / exclusive / zero-forcing: KL(q∥p)\mathrm{KL}(q\Vert p) blows up wherever q>0q > 0 but p→0p\to 0. So the optimal qq ends up mode-seeking — it concentrates on the densest region(s) and ignores the rest.

Continuous-form recipes for the optimal diagonal-Gaussian fit. Restrict qq to mean-field N(m,diag(σi2))\mathcal{N}(\mathbf{m}, \mathrm{diag}(\sigma_i^2)) with p=N(μp,Σp)p = \mathcal{N}(\boldsymbol{\mu}_p, \boldsymbol{\Sigma}_p). The closed-form optima are

argminq KL(p ∥ q):m∗=μp,σi∗ 2=(Σp)ii,\mathrm{argmin}_q \,\mathrm{KL}(p\,\Vert\,q): \quad \mathbf{m}^* = \boldsymbol{\mu}_p, \quad \sigma_i^{*\,2} = (\boldsymbol{\Sigma}_p)_{ii},
argminq KL(q ∥ p):m∗=μp,σi∗ 2=1/[Σp−1]ii.\mathrm{argmin}_q \,\mathrm{KL}(q\,\Vert\,p): \quad \mathbf{m}^* = \boldsymbol{\mu}_p, \quad \sigma_i^{*\,2} = 1/[\boldsymbol{\Sigma}_p^{-1}]_{ii}.

Equation ((12)) matches marginal variances; equation ((13)) matches conditional precisions. The two recipes give qualitatively different σ’s whenever Σp\boldsymbol{\Sigma}_p has off-diagonal mass, and are identical only when the target is already diagonal.

Numerical recipe. Equations ((12)) and ((13)) are one-liners — diagonal of Σp\boldsymbol{\Sigma}_p for the forward fit, diagonal of Σp−1\boldsymbol{\Sigma}_p^{-1} for the reverse fit. The plot below uses these analytic fits directly; no optimisation loop needed.

Interpretation & where it shows up.

  • Reverse KL is the VI default. Standard ELBO-based VI minimises KL(q∥ppost)\mathrm{KL}(q\Vert p_{\text{post}}) because −KL(q∥p)≤log⁡p(y)-\mathrm{KL}(q\Vert p) \le \log p(\mathbf{y}) gives a tractable lower bound on the marginal likelihood. The price is the mode-seeking pathology.
  • Variance under-estimation. ((13)) shows σi∗ 2\sigma_i^{*\,2} is the conditional variance, which is always less than the marginal variance of ((12)) when Σp\boldsymbol{\Sigma}_p has off-diagonal mass. This is the formal reason “vanilla VI underestimates posterior variance”.
  • Expectation propagation, α-divergences. EP locally minimises forward KL, getting mode-covering behaviour at the cost of a fixed-point iteration. α-divergences interpolate between the two directions, with α = 0 ↔ reverse KL and α = 1 ↔ forward KL.
forward KL fit : std = [1. 1.]
reverse KL fit : std = [0.3122499 0.3122499]
<Figure size 1210x616 with 6 Axes>

7. The kl_standard_normal shortcut

What it is. A specialisation of equation ((11)) when q=N(0,I)q = \mathcal{N}(\mathbf{0}, \mathbf{I}). The cross-terms vanish: Σq−1=I\boldsymbol{\Sigma}_q^{-1} = \mathbf{I}, μq=0\boldsymbol{\mu}_q = \mathbf{0}, log⁡∣Σq∣=0\log\lvert\boldsymbol{\Sigma}_q\rvert = 0.

Continuous form.

KL ⁣(N(m,Σ) ∥ N(0,I))=12[tr(Σ)+m⊤m−d−log⁡∣Σ∣].\mathrm{KL}\!\bigl(\mathcal{N}(\mathbf{m}, \boldsymbol{\Sigma}) \,\Vert\, \mathcal{N}(\mathbf{0}, \mathbf{I})\bigr) = \tfrac{1}{2}\bigl[\mathrm{tr}(\boldsymbol{\Sigma}) + \mathbf{m}^\top\mathbf{m} - d - \log\lvert\boldsymbol{\Sigma}\rvert\bigr].

Numerical recipe. For diagonal Σ=diag(σ12,…,σd2)\boldsymbol{\Sigma} = \mathrm{diag}(\sigma_1^2, \dots, \sigma_d^2) equation ((14)) further specialises to

KL=12∑i(σi2+mi2−1−log⁡σi2),\mathrm{KL} = \tfrac{1}{2}\sum_i \bigl(\sigma_i^2 + m_i^2 - 1 - \log\sigma_i^2\bigr),

which is the per-coordinate formula you’ll see hard-coded in 90% of ELBO implementations.

Interpretation & where it shows up.

  • VAE prior regulariser. The KL term in the standard VAE loss is exactly equation ((15)) summed across latent dimensions and batched across data points.
  • Whitening. SVGP and Bayesian NN methods often change variables to make the prior N(0,I)\mathcal{N}(\mathbf{0}, \mathbf{I}) — every KL becomes equation ((14)) and stays cheap.
  • Easy gradients. The diagonal form ((15)) is per-coordinate and trivially differentiable, which is why mean-field variational families default to this parameterisation. Compare to the full equation ((11)), where the Cholesky of Σq\boldsymbol{\Sigma}_q shows up in every gradient.
kl_standard_normal       : 0.243427
dist_kl_divergence vs N(0,I): 0.243427
hand-rolled diagonal     : 0.243427

8. Expected log-likelihood under a Gaussian

What it is. When the latent variable f\mathbf{f} is itself uncertain (described by a Gaussian variational posterior q(f)=N(μq,Σq)q(\mathbf{f}) = \mathcal{N}(\boldsymbol{\mu}_q, \boldsymbol{\Sigma}_q)), and the observation model is Gaussian p(y∣f)=N(f,R)p(\mathbf{y}\mid\mathbf{f}) = \mathcal{N}(\mathbf{f}, \mathbf{R}), the data-fit term of the ELBO has a closed form that decomposes into “log-density at the mean” plus a “trace correction” for posterior uncertainty.

Continuous form.

Eq[log⁡p(y∣f)]=−m2log⁡2π−12log⁡∣R∣−12(y−μq)⊤R−1(y−μq)−12tr(R−1Σq).\mathbb{E}_q[\log p(\mathbf{y}\mid\mathbf{f})] = -\tfrac{m}{2}\log 2\pi - \tfrac{1}{2}\log\lvert\mathbf{R}\rvert - \tfrac{1}{2}(\mathbf{y}-\boldsymbol{\mu}_q)^\top\mathbf{R}^{-1}(\mathbf{y}-\boldsymbol{\mu}_q) - \tfrac{1}{2}\mathrm{tr}(\mathbf{R}^{-1}\boldsymbol{\Sigma}_q).

The first three terms are just the log-density of a Gaussian (cf. 0.1 §1) evaluated at the posterior mean. The fourth — the trace correction 12tr(R−1Σq)\tfrac{1}{2}\mathrm{tr}(\mathbf{R}^{-1}\boldsymbol{\Sigma}_q) — is new.

Numerical recipe. All four terms reuse the same Cholesky of R\mathbf{R}:

Eq[log⁡p(y∣f)]=log⁡N(y;μq,R)−12tr(R−1Σq).\mathbb{E}_q[\log p(\mathbf{y}\mid\mathbf{f})] = \log\mathcal{N}(\mathbf{y}; \boldsymbol{\mu}_q, \mathbf{R}) - \tfrac{1}{2}\mathrm{tr}(\mathbf{R}^{-1}\boldsymbol{\Sigma}_q).

The trace can be written tr(LR−1ΣqLR−⊤)\mathrm{tr}(\mathbf{L}_R^{-1}\boldsymbol{\Sigma}_q\mathbf{L}_R^{-\top}) with R=LRLR⊤\mathbf{R} = \mathbf{L}_R\mathbf{L}_R^\top, sharing factors with ((2)) and ((6)).

Interpretation & where it shows up.

  • Trace correction = “uncertainty tax”. It vanishes as Σq→0\boldsymbol{\Sigma}_q\to\mathbf{0} (deterministic limit) and grows as Σq\boldsymbol{\Sigma}_q inflates. So an over-confident qq — small Σq\boldsymbol{\Sigma}_q — has a small ELL penalty but pays through the KL term ((11)); an over-spread qq is the opposite. Balancing the two is what variational fitting does.
  • SVGP / VGP / Bayesian NN ELBOs. Every Gaussian-likelihood variational ELBO has equation ((16)) (or its sum across data points) as its data-fit term.
  • Conjugate identity. When qq equals the true Gaussian-conjugate posterior, equation ((16)) plus the prior KL ((11)) collapses to log⁡p(y)\log p(\mathbf{y}) — the marginal likelihood of the data. We see this concretely in §10.

gaussx.gaussian_expected_log_lik(y, q_mu, q_cov, noise) evaluates equation ((16)) directly.

ELL (gaussx primitive)   : -0.502938
ELL (manual closed form) : -0.502938
ELL (MC, 50k samples)    : -0.500431

9. Mutual information between blocks

What it is. Mutual information I(Xa;Xb)=H(Xa)+H(Xb)−H(Xa,Xb)I(X_a; X_b) = H(X_a) + H(X_b) - H(X_a, X_b) measures the reduction in uncertainty about XaX_a obtained by observing XbX_b (and vice versa — it’s symmetric, despite KL not being). For Gaussians the entropies all simplify via equation ((5)), leaving a ratio of log-determinants.

Continuous form. Partition x=(xa,xb)\mathbf{x} = (\mathbf{x}_a, \mathbf{x}_b) as in 0.1 §4. Substituting equation ((5)) for each entropy term and cancelling the additive constants:

I(Xa;Xb)=12log⁡ ⁣∣Σaa∣ ∣Σbb∣∣Σ∣.I(X_a; X_b) = \tfrac{1}{2}\log\!\frac{\lvert\boldsymbol{\Sigma}_{aa}\rvert\,\lvert\boldsymbol{\Sigma}_{bb}\rvert}{\lvert\boldsymbol{\Sigma}\rvert}.

Numerical recipe. Three log-determinants, no quadratic forms — equation ((18)) is computed entirely from Cholesky factors of Σaa\boldsymbol{\Sigma}_{aa}, Σbb\boldsymbol{\Sigma}_{bb}, and the joint Σ\boldsymbol{\Sigma}. For the 2D case with correlation ρ it collapses to

I(Xa;Xb)=−12log⁡(1−ρ2),I(X_a; X_b) = -\tfrac{1}{2}\log(1 - \rho^2),

a recovery of the classical information-theoretic measure of correlation strength.

Interpretation & where it shows up.

  • Conditional independence. I(Xa;Xb)=0I(X_a; X_b) = 0 iff Σab=0\boldsymbol{\Sigma}_{ab} = \mathbf{0}, in which case the joint factorises as the product of marginals. Equation ((18)) is therefore a quantitative diagnostic for how strongly two blocks interact — exactly the question Gaussian graphical models try to answer.
  • Sensor placement / experimental design. Choose observations xb\mathbf{x}_b that maximise II with the quantity of interest xa\mathbf{x}_a — equivalently, that shrink the determinant of the conditional covariance via the Schur identity from 0.1 §5.
  • Bayesian active learning. Predictive entropy search and BALD use equation ((18)) (often with a non-Gaussian likelihood, but Gaussian-approximated) to score candidate queries.
  • Information bottleneck. The IB objective is a difference of MI terms; for Gaussian-process variants both pieces have closed forms via ((18)).
<Figure size 594x374 with 1 Axes>

10. Putting it together: a one-step ELBO

What it is. The Evidence Lower BOund (ELBO) is the workhorse of variational inference. It decomposes as data-fit minus prior penalty: the expected log-likelihood ((16)) of the data under qq, minus the KL ((11)) between qq and the prior.

Continuous form.

ELBO(q)=Eq[log⁡p(y∣f)]⏟data fit  −  KL ⁣(q(f) ∥ p(f))⏟prior penalty.\mathrm{ELBO}(q) = \underbrace{\mathbb{E}_q[\log p(\mathbf{y}\mid\mathbf{f})]}_{\text{data fit}} \;-\; \underbrace{\mathrm{KL}\!\bigl(q(\mathbf{f}) \,\Vert\, p(\mathbf{f})\bigr)}_{\text{prior penalty}}.

Numerical recipe. Plug equation ((16)) and equation ((11)) into ((20)). Both pieces share Cholesky factors with everything in this notebook. For the toy below we sweep qq’s mean over a grid; in real use you’d differentiate the ELBO and run gradient ascent — every term in the gradient is also closed-form.

Interpretation.

  • Variational identity. log⁡p(y)−ELBO(q)=KL(q∥ppost)≥0\log p(\mathbf{y}) - \mathrm{ELBO}(q) = \mathrm{KL}(q\Vert p_{\text{post}}) \ge 0, with equality iff qq equals the true posterior. Maximising the ELBO over qq minimises the variational gap.
  • Conjugate sanity check. For Gaussian-Gaussian conjugate models, the optimum qq is the true posterior, and the ELBO equals log⁡p(y)\log p(\mathbf{y}) exactly. The toy below illustrates this: the ELBO peak lands on the conjugate posterior mean.
  • Scales linearly. Add data points → sum more gaussian_expected_log_lik terms; add latent dimensions → bigger Cholesky. No new closed forms ever needed.
true posterior     : N(0.7273, 0.0909)
argmax ELBO over m : 0.7288
<Figure size 594x374 with 1 Axes>

11. Recap & where to go next

QuantityContinuous form (equation)Numerical (equation)gaussx entry point
Quadratic form((1))((2))quadratic_form
Score((3))((4))solve (or jax.grad of gaussian_log_prob)
Entropy((5))((6))gaussian_entropy
Cross-entropy((8))via identity ((9))H(p)+KL(p∥q)H(p) + \mathrm{KL}(p\Vert q)
KL divergence((11))reuses Cholesky factorsdist_kl_divergence
KL vs N(0,I)\mathcal{N}(0,I)((14))diagonal: ((15))kl_standard_normal
Expected log-likelihood((16))((17))gaussian_expected_log_lik
Mutual information((18))2D special case ((19))sum of gaussian_entropy calls
ELBO((20))ELL − KLcombine the two above

Next up.