The Gaussian toolkit: identities, linear-algebra moves and tricks
The identities and moves that experts use without thinking and beginners struggle with: whitening, low-rank updates, Schur complements and spectra; moments, conditioning in both forms, KL, Stein, Bonnet and Price; total variance, the ELBO and Fisher information; and how all of it runs reinforcement learning. Each with a step-by-step proof.
The Gaussian is the one distribution that stays closed under almost everything we want to do: linear maps, sums, conditioning, marginalising, multiplying densities. That closure is why Gaussian processes, Kalman filters, variational inference, diffusion models and most continuous-control reinforcement learning are tractable. It is also why derivations in these areas feel either effortless or hopeless: with the right handful of moves they collapse to a few lines, and without them they sprawl.
This page collects those moves. Section 2 is the linear algebra underneath (whitening, low-rank updates, Schur complements, spectra). Sections 3 to 9 are the Gaussian identities proper. Section 10 covers the probabilistic moves that recur everywhere (total variance, moment matching, the ELBO, Fisher information), and Section 11 shows the same tools running reinforcement learning. The core results are proved step by step in Gaussian processes, from first principles and cited as “GP Lemma 5” and so on; everything else is proved here. Proofs, notes, remarks and examples are folded; the notes marked why experts reach for it are the point of the page.
Two pictures carry most of the intuition. Conditioning is a slice: fix x1=a and read off the Gaussian along that line. Marginalising is a shadow: project the whole cloud onto the x2 axis. Move ρ and a: the slice is always narrower than the shadow, and its centre moves along the dashed regression line.
Notation
Plain italic letters are scalars, bold italic lower-case letters are vectors (x,μ∈RD), bold upright capitals are matrices (Σ, P=Σ−1, A). N(x∣μ,Σ) is the density
N(x∣μ,Σ)=(2π)−D/2∣Σ∣−1/2exp(−21(x−μ)⊤Σ−1(x−μ)).
1. Where the constant comes from
Proposition 1 (The Gaussian integral)
For symmetric positive definite P∈RD×D, ∫RDexp(−21x⊤Px)dx=(2π)D/2∣P∣−1/2.
Proof
Step 1. Rotate to the eigenbasis. Write P=QΛQ⊤ with Q orthogonal and Λ=diag(λ1,…,λD), λi>0. Substitute y=Q⊤x; since ∣detQ∣=1, dx=dy.
Step 2. The exponent separates.x⊤Px=y⊤Λy=∑iλiyi2, so the integrand is a product of one-dimensional factors:
Step 3. Each factor. Substituting yi=s/λi and using ∫e−s2/2ds=2π, each factor is 2π/λi.
Step 4. Multiply.∏i2π/λi=(2π)D/2(∏iλi)−1/2=(2π)D/2∣P∣−1/2, since the determinant is the product of the eigenvalues.
With P=Σ−1 (so ∣P∣−1/2=∣Σ∣1/2) and a shift by μ, this is exactly the normaliser in the density.
2. Five linear-algebra moves
Most “Gaussian algebra” is linear algebra in disguise, and most of the difficulty beginners meet is choosing which way to write a matrix expression. Five moves cover nearly every derivation in probabilistic machine learning. Beginners expand and compute; experts rewrite with one of these first.
Move 1: a scalar is its own trace
a⊤Mb=tr(a⊤Mb)=tr(Mba⊤), because a 1×1 matrix equals its trace and tr(UV)=tr(VU). It turns a quadratic form into a linear function of an outer product, which can then be averaged or summed.
Note (Why experts reach for it: sufficient statistics appear by themselves)
Step 1. The data-dependent part of a Gaussian log-likelihood is −21∑n=1N(xn−μ)⊤Σ−1(xn−μ).
Step 2. Each term is tr(Σ−1(xn−μ)(xn−μ)⊤) by Move 1; the trace is linear, so the sum is tr(Σ−1Sμ) with Sμ=∑n(xn−μ)(xn−μ)⊤.
Step 3. The data now enter only through one D×D matrix. Expanding Sμ shows that it depends on the data only through ∑nxn and ∑nxnxn⊤: those two sums are all a Gaussian model ever needs to remember, however large N is.
Move 2: never invert; factor and whiten
Lemma 1 (Whitening with a Cholesky factor)
Let Σ=LL⊤ with L lower triangular (Cholesky). Then
x=μ+Lz with z∼N(0,I) has x∼N(μ,Σ);
(x−μ)⊤Σ−1(x−μ)=∥w∥2, where w solves the triangular system Lw=x−μ;
log∣Σ∣=2∑ilogLii.
Proof
Step 1. Sampling. By GP Lemma 2, μ+Lz is Gaussian with mean μ and covariance LIL⊤=Σ.
Step 2. The inverse factorises.Σ−1=(LL⊤)−1=L−⊤L−1.
Step 3. Mahalanobis distance. With w=L−1(x−μ), the quadratic form is (x−μ)⊤L−⊤L−1(x−μ)=w⊤w.
Step 4. Determinant.∣Σ∣=∣L∣∣L⊤∣=∣L∣2, and the determinant of a triangular matrix is the product of its diagonal. Take logs.
Every Gaussian is a standard normal seen through a linear map. Expert practice is to move to z-space, where every coordinate is independent with unit variance, do the work there, and map back at the end. Numerically, a triangular solve costs O(D2) and is stable, while forming Σ−1 costs O(D3) and amplifies rounding error by the condition number. In code, inv(S) is almost always a bug.
Move 3: update, don’t recompute
Lemma 2 (Sherman–Morrison and the matrix determinant lemma)
For invertible A and vectors u,v with 1+v⊤A−1u=0:
Step 2. Simplify. The fraction is u(1+γ)v⊤A−1/(1+γ)=uv⊤A−1, which cancels the middle term, leaving I.
Step 3. Determinant: factor out A.∣A+uv⊤∣=∣A∣∣I+bv⊤∣ with b=A−1u.
Step 4. Eigenvalues of I+bv⊤. The rank-one matrix bv⊤ maps every vector to a multiple of b; it has eigenvalue v⊤b (eigenvector b) and eigenvalue 0 on the (D−1)-dimensional subspace orthogonal to v. Adding I adds 1 to each, so the determinant is 1+v⊤b.
Note (Why experts reach for it: one new data point costs O(D²), not O(D³))
In Bayesian linear regression the posterior precision gains one rank-one term per observation, A←A+σn−2ϕϕ⊤ (GP Section 2). Sherman–Morrison updates A−1, and the determinant lemma updates log∣A∣, in O(M2) per point. This is recursive least squares, the Kalman filter’s update step, and the reason a GP can absorb one new observation by extending its Cholesky factor by one row in O(N2). The general rank-k version is the Woodbury identity (GP Lemma 6).
Move 4: blocks, Schur complements, and the chain rule
Lemma 3 (Block factorisation and determinant)
For M=[ACBD] with A invertible, and the Schur complement S=D−CA−1B,
M=[ICA−10I][A00S][I0A−1BI],∣M∣=∣A∣∣S∣.
Proof
Step 1. Multiply the last two factors.[A00S][I0A−1BI]=[A0BS].
Step 2. Multiply by the first factor. The top block row is unchanged; the bottom block row becomes [CA−1A,CA−1B+S]=[C,D]. That is M.
Step 3. Determinants. The outer factors are block triangular with identity diagonal blocks, so their determinants are 1. The middle factor is block diagonal, with determinant ∣A∣∣S∣.
Note (Why experts reach for it: the determinant obeys the chain rule of probability)
For a Gaussian joint covariance, A=Σaa and S=Σbb−ΣbaΣaa−1Σab is the conditional covariance of b given a (GP Lemma 5). So log∣Σ∣=log∣Σaa∣+log∣Σb∣a∣: the log-determinant splits exactly as logp(a,b)=logp(a)+logp(b∣a). Applied one variable at a time, it is why a GP’s marginal likelihood is a sum of one-step-ahead predictive terms (GP Section 7), and why a Cholesky factor’s diagonal entries are conditional standard deviations.
Move 5: think in eigenvalues
A function of a symmetric matrix acts on its eigenvalues and leaves its eigenvectors alone: if K=UΛU⊤, then (K+σ2I)−1=U(Λ+σ2I)−1U⊤. Many formulas that look opaque become one-line statements about numbers.
Note (Why experts reach for it: a GP is a spectral filter)
Step 1. The GP posterior mean at the training inputs is K(K+σn2I)−1y (GP Proposition 5).
Step 2. In the eigenbasis this is UΛ(Λ+σn2I)−1U⊤y, that is,
i∑λi+σn2λi(ui⊤y)ui.
Step 3. Each direction of the data is multiplied by λi/(λi+σn2)∈(0,1): kept where the prior’s signal variance λi dominates the noise, suppressed where it does not. Smooth kernels have rapidly decaying λi, so the GP keeps a few smooth directions and filters the rest. The sum ∑iλi/(λi+σn2) is the model’s effective number of parameters.
3. Moments
Proposition 2 (First and second moments, and quadratic forms)
For x∼N(μ,Σ) and any matrix A:
E[xx⊤]=Σ+μμ⊤,E[x⊤Ax]=tr(AΣ)+μ⊤Aμ.
(These hold for any distribution with mean μ and covariance Σ.)
Proof
Step 1. Second moment. Expand the definition of covariance: Σ=E[(x−μ)(x−μ)⊤]=E[xx⊤]−μμ⊤ (the two cross terms each equal −μμ⊤, and +μμ⊤ remains). Rearrange.
Step 2. The trace trick. A scalar is its own trace, and tr(UV)=tr(VU): x⊤Ax=tr(x⊤Ax)=tr(Axx⊤).
Step 3. Expectation passes through the trace (both are linear): E[x⊤Ax]=tr(AE[xx⊤])=tr(AΣ)+tr(Aμμ⊤) by Step 1, and tr(Aμμ⊤)=μ⊤Aμ by Step 2 read backwards.
Fourth moments are where the Gaussian is special: they are fixed entirely by the covariance.
Proposition 3 (Isserlis (Wick) theorem)
For x∼N(0,Σ), E[xixjxkxl]=ΣijΣkl+ΣikΣjl+ΣilΣjk: a sum over the three ways to pair four indices.
Proof
Step 1. The moment generating function.M(t)=E[et⊤x]=exp(q) with q=21t⊤Σt (complete the square in the integral, as in GP Lemma 1, then use Proposition 1). Moments are derivatives at zero: E[xixjxkxl]=∂i∂j∂k∂lMt=0.
Step 2. Derivatives of q. Write si=∂iq=(Σt)i. Then ∂jsi=Σij, all higher derivatives of q vanish, and si=0 at t=0.
Step 3. Differentiate four times, using ∂iM=siM and the product rule:
Step 4. Differentiate once more and set t=0. Every term still containing an s vanishes. What survives is each s in Step 3 differentiated by ∂l, with M(0)=1: ΣijΣkl+ΣikΣjl+ΣjkΣil.
Example 1 (Where Isserlis is used: the Hutchinson trace estimator)
Expensive GP computations need tr(A) for a matrix A we can only multiply by (for example A=Ky−1∂Ky in the gradient of the marginal likelihood, GP Proposition 8). Draw z∼N(0,I).
Step 1. Unbiased. By Proposition 2 with Σ=I, μ=0: E[z⊤Az]=trA.
Step 2. Second moment by Isserlis (symmetric A, Σij=δij):
Step 3. Variance. Subtract the squared mean: Var[z⊤Az]=2tr(A2)=2∥A∥F2. Averaging S independent probes divides it by S.
4. The closure toolkit
Operation
Result
Proof
Linear map Cx+d
N(Cμ+d,CΣC⊤)
GP Lemma 2
Sum of independent Gaussians (convolution)
means add, covariances add
GP Lemma 3
Product of densities in the same variable
precisions add; normaliser N(μ1∣μ2,Σ1+Σ2)
GP Lemma 4
Conditioning, moment form
μb+ΣbaΣaa−1(a−μa), Schur complement
GP Lemma 5
Likelihood N(y∣Cx+d,S) times prior on x
evidence times posterior, two forms
GP Lemma 8
Push-through and Woodbury
A−1=Σw−ΣwΦ⊤G−1ΦΣw
GP Lemma 6
Sampling a conditional by correcting a prior sample
Matheron’s rule
GP Proposition 6
Mixture of Gaussians
not Gaussian
GP Note on Lemma 4
5. Conditioning and marginalising, in both coordinates
The moment form makes marginalising trivial (read off a block) and conditioning costly (a Schur complement). The information form swaps the roles. Here is the information-form half, which the GP post only sketched.
Proposition 4 (Information form: slice and shadow)
Let [ab] be Gaussian with mean [μaμb] and precision P=[PaaPbaPabPbb]. Then
Step 1. Expand the joint exponent in blocks. Using Pab⊤=Pba,
−21[αβ]⊤P[αβ]=−21α⊤Paaα−β⊤Pbaα−21β⊤Pbbβ.
Step 2. Slice: fix a. As a function of β this is −21β⊤Pbbβ+β⊤h+const with h=−Pbaα. GP Lemma 1 gives β∣a∼N(Pbb−1h,Pbb−1). Add back μb.
Step 3. Shadow: complete the square in β. By GP Lemma 1, the two β terms equal −21(β−Pbb−1h)⊤Pbb(β−Pbb−1h)+21h⊤Pbb−1h.
Step 4. Integrate b out. By Proposition 1 the integral of the first term over β is (2π)dimb/2∣Pbb∣−1/2, which does not depend on a. What remains in α is
using h⊤Pbb−1h=α⊤PabPbb−1Pbaα. Read off the precision.
Remark (A free corollary: the block inverse)
The marginal of a also has covariance Σaa (moment form). Comparing with the shadow, Σaa=(Paa−PabPbb−1Pba)−1. Comparing the slice with GP Lemma 5, Pbb−1=Σbb−ΣbaΣaa−1Σab. The block-inverse formulas fall out of probability with no matrix algebra. In the figure, with unit variances, P22=1/(1−ρ2): the slice’s variance 1−ρ2 is 1/P22, while the shadow’s is Σ22=1.
Step 2. By Proposition 2 applied to x−μ (mean 0), the expectation is tr(Σ−1Σ)=D.
Step 3.2Dlog2π+2D+21log∣Σ∣=21log((2πe)D∣Σ∣).
Entropy depends only on ∣Σ∣, the volume of the uncertainty ellipsoid. Among all distributions with a given covariance, the Gaussian has the largest entropy, which is one reason it is the default “least committed” choice.
Step 1. Definition.KL(p0∥p1)=E0[logp0(x)]−E0[logp1(x)], expectations under p0.
Step 2. The first term is minus the entropy of p0: −2Dlog2π−21log∣Σ0∣−2D (Proposition 5, Steps 1–2).
Step 3. The second term.E0[logp1]=−2Dlog2π−21log∣Σ1∣−21E0[(x−μ1)⊤Σ1−1(x−μ1)]. Under p0, x−μ1 has mean μ0−μ1 and covariance Σ0, so by Proposition 2 the expectation is tr(Σ1−1Σ0)+(μ0−μ1)⊤Σ1−1(μ0−μ1).
Step 4. Subtract. The log2π terms cancel; collecting the rest gives the formula.
Note (Where the KL appears)
It is the regulariser in every variational autoencoder (with p1=N(0,I) it becomes 21∑i(σi2+μi2−1−logσi2) for a diagonal p0), and the term that keeps inducing-point posteriors close to the prior in sparse and deep GPs. Its three parts read cleanly: a shape mismatch (trace), a location mismatch (Mahalanobis distance of the means), and a volume mismatch (log-determinants).
7. Stein, Bonnet and Price: differentiating through a Gaussian
Variational inference and reinforcement learning need gradients of Ex∼N(μ,Σ)[f(x)] with respect to μ and Σ. Three identities turn them into expectations of derivatives of f.
Lemma 4 (Stein’s lemma)
For x∼N(μ,Σ) and differentiable g with E∣∇g∣<∞: E[g(x)(x−μ)]=ΣE[∇g(x)].
Proof
Step 1. One dimension, the key fact. For φ(z)=N(z∣0,1), differentiating gives φ′(z)=−zφ(z).
Step 2. Integrate by parts. For a scalar function h of z∼N(0,1),
Step 4. Move the derivative onto f.∂vE[f]=∫f∂vpvdx=21∫f∂x2pvdx=21∫f′′pvdx, integrating by parts twice (boundary terms vanish).
Remark (Two different gradient estimators)
Bonnet’s identity is the reparameterisation gradient behind VAEs and Gaussian variational inference: low variance, but it needs ∇f. The score-function identity ∇μE[f]=E[f(x)Σ−1(x−μ)] needs only values of f (it is Stein’s lemma read in reverse, combined with Bonnet), which is why it powers policy gradients in reinforcement learning, at the price of higher variance. Price’s Step 3 is the same heat equation that the operator post learns: adding Gaussian noise is running heat flow.
8. The matrix normal
A random matrix X∈Rn×p whose rows are correlated by one covariance and whose columns are correlated by another appears whenever data have two axes: inputs and outputs in a multi-output GP, space and time in a weather field.
Definition 1 (Matrix normal distribution)
X∼MNn×p(M,Ω,Σ), with mean M∈Rn×p, row covariance Ω∈Rn×n and column covariance Σ∈Rp×p (both positive definite), if
vec(X)∼N(vec(M),Σ⊗Ω),
where vec stacks the columns. Entrywise, Cov[Xij,Xkl]=ΩikΣjl.
Conventions differ between books (some stack rows, which swaps the order of the Kronecker factors); the entrywise covariance is the unambiguous statement.
Lemma 5 (Two vec identities)
vec(AXB)=(B⊤⊗A)vec(X).
vec(A)⊤vec(B)=tr(A⊤B).
Proof
Step 1. One column of the product. Column j of AXB is AXbj=∑kBkjAxk, where xk is column k of X.
Step 2. Stack the columns. Block j of vec(AXB) is ∑k(BkjA)xk, which is block row j of the matrix with blocks BkjA=(B⊤)jkA applied to vec(X). That matrix is B⊤⊗A.
Step 3. Inner product of vecs.vec(A)⊤vec(B)=∑ijAijBij=∑j(A⊤B)jj=tr(A⊤B).
Proposition 8 (Matrix normal density and characteristic function)
Step 1. Start from the vector density of vec(X) in Rnp, with covariance Σ⊗Ω.
Step 2. The determinant. By the mixed-product property, the eigenvalues of Σ⊗Ω are all products σiωj of eigenvalues of Σ (p of them) and Ω (n of them). So ∣Σ⊗Ω∣=∏i,jσiωj=(∏iσi)n(∏jωj)p=∣Σ∣n∣Ω∣p.
Step 3. The quadratic form.(Σ⊗Ω)−1=Σ−1⊗Ω−1, and by Lemma 5, part 1 (with B=Σ−1, which is symmetric),
the last step by part 2. Cycle the trace to tr(Σ−1E⊤Ω−1E).
Step 4. The characteristic function.tr(Z⊤X)=vec(Z)⊤vec(X) (part 2), so this is the Gaussian characteristic function (GP Lemma 2, Step 4) at t=vec(Z). Its quadratic term is vec(Z)⊤(Σ⊗Ω)vec(Z)=tr(Z⊤ΩZΣ), by the same two identities.
Remark (A multi-output GP is a matrix normal)
For a separable kernel k(x,x′)B, the N×p matrix F of function values (rows: inputs, columns: outputs) has Cov[Fia,Fjb]=k(xi,xj)Bab. That is F∼MN(0,K,B): the row covariance is the Gram matrix and the column covariance is the output covariance. The density’s determinant ∣B∣N∣K∣p and its trace form are why the marginal likelihood of such models costs O(N3+p3) rather than O(N3p3), the same saving as the Kronecker trick in the operator post.
9. Derivatives of the log-density
Proposition 9 (Gradients, and the maximum-likelihood estimates)
For ℓ(μ,Σ)=logN(x∣μ,Σ) and r=x−μ (treating the entries of Σ as free),
∇μℓ=Σ−1r,∇Σℓ=21(Σ−1rr⊤Σ−1−Σ−1).
Summing over data x1,…,xN and setting both to zero gives the sample mean and the (biased) sample covariance.
Proof
Step 1. Write the log-density.ℓ=−2Dlog2π−21log∣Σ∣−21r⊤Σ−1r.
Step 2. Gradient in μ.∇μ(−21r⊤Σ−1r)=Σ−1r, since ∇r(r⊤Ar)=2Ar for symmetric A and ∂r/∂μ=−I.
Step 3. Gradient in Σ, entry by entry. Let Eij be the matrix with a single 1 in position (i,j). By GP Lemma 7, ∂log∣Σ∣/∂Σij=tr(Σ−1Eij)=(Σ−1)ji and
∂Σij∂r⊤Σ−1r=−r⊤Σ−1EijΣ−1r=−(Σ−1r)i(Σ−1r)j.
Collecting entries (and Σ−1 symmetric) gives the stated matrix.
Step 4. Maximum likelihood. Summing Step 2 over data, Σ−1∑n(xn−μ)=0 gives μ^=N1∑nxn. Summing Step 3 and multiplying by Σ on both sides, ∑nrnrn⊤=NΣ, so Σ^=N1∑n(xn−μ^)(xn−μ^)⊤.
10. Probabilistic moves
Splitting uncertainty: the law of total variance
Proposition 10 (Law of total covariance)
For random vectors x and y with m(y)=E[x∣y],
Cov[x]=average spreadE[Cov[x∣y]]+spread of the averagesCov[m(y)].
Proof
Step 1. Second moment by the tower rule.E[xx⊤]=E[E[xx⊤∣y]]=E[Cov[x∣y]+m(y)m(y)⊤], using Proposition 2, Step 1 conditionally on y.
Step 2. Mean by the tower rule.E[x]=E[m(y)].
Step 3. Subtract.Cov[x]=E[xx⊤]−E[x]E[x]⊤=E[Cov[x∣y]]+(E[mm⊤]−E[m]E[m]⊤), and the bracket is Cov[m(y)].
Proposition 11 (Moment matching is the best Gaussian fit in KL(p ‖ q))
For any distribution p with mean μp and covariance Σp, the Gaussian q=N(m,S) minimising KL(p∥q) has m=μp and S=Σp.
Proof
Step 1. Drop what does not depend on q.KL(p∥q)=Ep[logp]−Ep[logq], so minimise −Ep[logq]=21log∣S∣+21Ep[(x−m)⊤S−1(x−m)]+const.
Step 2. Expectation of the quadratic form (Proposition 2): tr(S−1Σp)+(μp−m)⊤S−1(μp−m).
Step 3. The mean. Only the second term involves m; it is non-negative and zero at m=μp.
Step 4. The covariance. With m=μp, the objective is 21log∣S∣+21tr(S−1Σp). Its gradient in S (Proposition 9, Step 3) is 21S−1−21S−1ΣpS−1, which vanishes at S=Σp.
Example 2 (Ensembles: aleatoric plus epistemic)
A deep ensemble of M networks predicts N(μj,σj2), j=1,…,M, each with weight 1/M.
Step 1. Let J be a uniformly random member. By Proposition 10 with y=J: Var[y]=M1∑jσj2+M1∑j(μj−μˉ)2, with μˉ=M1∑jμj.
Step 2. The first term is the noise each member believes is in the data (aleatoric). The second is the members’ disagreement (epistemic): it shrinks where data constrain the model and grows away from them.
Step 3. By Proposition 11, N(μˉ,Var[y]) is the best single Gaussian summary of the ensemble in KL(p∥q). Moment matching is also the core step of expectation propagation, assumed-density filtering, and PILCO’s uncertainty propagation.
Note (The other direction of KL behaves differently)
Minimising KL(q∥p) instead, as variational inference does, penalises q for putting mass where p has none. Fitted to a two-mode p, it locks onto one mode and underestimates the spread, while KL(p∥q) (Proposition 11) covers both modes and overestimates it. Knowing which direction an algorithm minimises predicts how its uncertainty will be wrong.
The evidence lower bound in three lines
Proposition 12 (ELBO)
For any density q(z), logp(y)=ELBO(q)Eq[logp(y,z)−logq(z)]+KL(q(z)∥p(z∣y))≥ELBO(q).
Proof
Step 1.logp(y) does not depend on z, so it equals its own average under q: logp(y)=Eq[logp(y)].
Step 2. Bayes’ rule, p(y)=p(y,z)/p(z∣y), and multiplying and dividing by q(z): logp(y)=Eq[logq(z)p(y,z)+logp(z∣y)q(z)].
Step 3. The second expectation is a KL divergence, which is non-negative.
So maximising the ELBO over q is the same as minimising the KL to the true posterior, without ever computing that posterior. With Gaussian q, the KL to a Gaussian prior is Proposition 6 in closed form and the expected log-likelihood has Bonnet and Price gradients (Proposition 7): this is how VAEs, sparse GPs and Bayesian neural networks are trained.
Note (log-sum-exp: never exponentiate first)
Mixtures, softmaxes and importance weights need log∑ieai with ai of size ±1000, where eai overflows or underflows. With m=maxiai, log∑ieai=m+log∑ieai−m: every exponent is now at most 0 and the largest term is exactly 1. Work with log-densities throughout and exponentiate only at the very end, if at all.
Fisher information: the geometry inside the KL
Proposition 13 (For Gaussians, the KL is exactly the Fisher metric)
For fixed Σ: KL(N(μ+δ,Σ)∥N(μ,Σ))=21δ⊤Σ−1δ, and the Fisher information of the mean is F=E[∇μlogp∇μlogp⊤]=Σ−1.
Proof
Step 1. KL. In Proposition 6 with Σ0=Σ1=Σ: the trace is tr(I)=D, cancelling −D, and the log-determinant ratio is log1=0. Only the Mahalanobis term remains.
Step 2. Fisher. By Proposition 9, ∇μlogp=Σ−1r with r=x−μ, so F=Σ−1E[rr⊤]Σ−1=Σ−1ΣΣ−1=Σ−1.
In general the KL between nearby distributions is 21δ⊤Fδ to second order; for a Gaussian mean it is exact. The natural gradientF−1∇ (Amari, 1998) here is Σ∇: it measures steps in units of the distribution’s own spread, so it does not care how the parameters happen to be scaled.
11. Gaussians in reinforcement learning
Continuous-control policies are almost always Gaussian, πθ(a∣s)=N(a∣μθ(s),Σ), and the standard algorithms are the identities above wearing different names. When an RL derivation gets messy, it is usually one of the following.
Proposition 14 (The score of a Gaussian policy, and why baselines are free)
Hence subtracting any baseline b(s) from the return leaves the policy gradient E[∇logπ(Q(s,a)−b(s))] unchanged.
Proof
Step 1. Log-density.logπ=−21(a−μ)⊤Σ−1(a−μ)+(terms without θ).
Step 2. Chain rule. By Proposition 9, ∇μlogπ=Σ−1(a−μ), and ∇θ=J⊤∇μ.
Step 3. Zero mean. Under π, E[a−μ]=0, and J⊤Σ−1 does not depend on a.
Step 4. The baseline term vanishes.Ea[∇logπb(s)]=b(s)Ea[∇logπ]=0 by Step 3.
Remark (Why REINFORCE gets noisier as the policy converges, and the fix)
Step 1. With Σ=σ2I write a=μ+σε, ε∼N(0,I). The score of Proposition 14 is J⊤ε/σ: its size grows like 1/σ, its variance like 1/σ2.
Step 2. As training shrinks the exploration noise σ, the score-function gradient estimate becomes ever noisier.
Step 3. Reparameterise instead (Bonnet, Proposition 7): ∇θE[Q(s,μθ(s)+σε)]=E[J⊤∇aQ(s,a)]. No 1/σ appears, and at σ→0 it becomes the deterministic policy gradient (Silver et al., 2014). This is why DDPG, TD3 and SAC differentiate through a learned Q.
Proposition 15 (Trust regions for Gaussian policies are Mahalanobis balls)
For πold=N(μ0,Σ) and πnew=N(μ1,Σ), KL(πold∥πnew)=21(μ1−μ0)⊤Σ−1(μ1−μ0); for diagonal Σ, ∑i(Δμi)2/(2σi2).
Proof
Step 1. This is Proposition 13 with δ=μ1−μ0.
Step 2. For diagonal Σ, Σ−1=diag(1/σi2) and the quadratic form is a sum over action dimensions.
A TRPO or PPO constraint KL≤δ therefore lets the mean of action dimension i move by about σi2δ: dimensions the policy is still exploring may change a lot, settled ones only a little. Natural policy gradients are Proposition 13 applied to the whole policy.
Note (Entropy bonuses act only on the covariance; and the tanh correction)
Step 1. By Proposition 5, H[π(⋅∣s)]=21log((2πe)D∣Σ∣) does not involve the mean: a maximum-entropy bonus (SAC) pushes only on Σ.
Step 2. SAC bounds actions by squashing, a=tanh(u) elementwise with u∼N(μ,diagσ2). The change-of-variables formula for an invertible map gives pa(a)=pu(u)∣det∂a/∂u∣−1.
Step 3. The Jacobian is diagonal with entries 1−tanh2(ui), so logπ(a)=logN(u∣μ,diagσ2)−∑ilog(1−tanh2(ui)). Forgetting the second term is a classic bug: the entropy of the squashed policy is then wrong, increasingly so as actions saturate.
Proposition 16 (Linear-quadratic control: noise does not change the best action)
For dynamics x′=Ax+Bu+w with w∼N(0,W) independent of x,u, and a quadratic cost-to-go V(x′)=x′⊤Px′,
E[V(x′)]=(Ax+Bu)⊤P(Ax+Bu)+tr(PW),
so the action minimising u⊤Ru+E[V(x′)] is the same as for W=0.
Proof
Step 1. Given x and u, x′ has mean Ax+Bu and covariance W.
Step 2. Proposition 2 with A→P gives the formula.
Step 3. The noise enters only through tr(PW), which does not depend on u; its gradient in u is zero, so the minimiser is unchanged. This is certainty equivalence: plan as if there were no noise, and pay a constant for it.
Note (The Kalman filter is two identities)
Predict.xt+1=Axt+w: an affine map plus independent noise (GP Lemmas 2 and 3), so N(μ,Σ)↦N(Aμ,AΣA⊤+W). Covariances add: uncertainty grows.
Update. Observe y=Cx+v: the linear-Gaussian model, GP Lemma 8. Its moment form is the Kalman gain ΣC⊤(CΣC⊤+V)−1; its information form is the information filter, where precisions add and uncertainty shrinks. For a scalar observation, Sherman–Morrison (Lemma 2) makes the update O(D2).
Questions
Question 1
In the figure, why is the slice never wider than the shadow?
Answer
The slice’s variance is 1/P22=Σ22−Σ21Σ11−1Σ12 (Remark after Proposition 4), which is Σ22 minus a non-negative quantity. Observing x1 can only remove uncertainty about x2; for Gaussians it never adds any, whatever value a is observed.
Question 2
KL(p0∥p1)=KL(p1∥p0). Which term of Proposition 6 makes the asymmetry obvious?
Answer
The Mahalanobis term measures the distance between the means in units of Σ1. Swapping the arguments measures it in units of Σ0, which differs whenever the covariances do.
Question 3
How many Hutchinson probes give a trace estimate with relative standard deviation 1% for A=I1000, and for a rank-one A=vv⊤?
Answer
With S probes the variance is 2∥A∥F2/S. For I1000: tr=1000, ∥A∥F2=1000, so the relative s.d. is 2/(1000S), and S=20 suffices. For vv⊤: tr=∥v∥2 and ∥A∥F2=∥v∥4, so the relative s.d. is 2/S and S=20000. Hutchinson is good for “spread out” spectra and poor for low-rank ones.
Question 4
Your Gaussian-policy gradient estimates get noisier as training converges. Why, and what are two fixes?
Answer
The score is J⊤ε/σ (Remark after Proposition 14), so its variance grows like 1/σ2 as exploration shrinks. Fixes: use the reparameterised gradient through a learned Q (Bonnet), subtract a baseline or use advantages (Proposition 14), and keep σ from collapsing (an entropy bonus).
Question 5
You add one data point to a GP with N=10000 observations. What does it cost to update the posterior, and why?
Answer
O(N2), not O(N3). The new Gram matrix is the old one bordered by one row and column, so its Cholesky factor gains one row, computed by a triangular solve (Lemma 3 with a 1×1 block D: the new diagonal entry is the square root of the Schur complement, the predictive variance of the new point).
K. B. Petersen, M. S. Pedersen. The Matrix Cookbook. 2012.
C. M. Bishop. Pattern Recognition and Machine Learning. Springer, 2006. Section 2.3.
A. K. Gupta, D. K. Nagar. Matrix Variate Distributions. Chapman & Hall/CRC, 1999.
L. Isserlis. On a formula for the product-moment coefficient of any order of a normal frequency distribution in any number of variables. Biometrika, 1918.
C. M. Stein. Estimation of the mean of a multivariate normal distribution. Annals of Statistics, 1981.
M. Opper, C. Archambeau. The variational Gaussian approximation revisited. Neural Computation, 2009. (Bonnet’s and Price’s theorems.)
M. F. Hutchinson. A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines. Communications in Statistics, 1989.
G. H. Golub, C. F. Van Loan. Matrix Computations. Johns Hopkins University Press, 4th ed., 2013.
S. Amari. Natural gradient works efficiently in learning. Neural Computation, 1998.
B. Lakshminarayanan, A. Pritzel, C. Blundell. Simple and scalable predictive uncertainty estimation using deep ensembles. NeurIPS 2017.
R. J. Williams. Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine Learning, 1992.
D. Silver, G. Lever, N. Heess, T. Degris, D. Wierstra, M. Riedmiller. Deterministic policy gradient algorithms. ICML 2014.
J. Schulman, S. Levine, P. Abbeel, M. Jordan, P. Moritz. Trust region policy optimization. ICML 2015.
T. Haarnoja, A. Zhou, P. Abbeel, S. Levine. Soft actor-critic: off-policy maximum entropy deep reinforcement learning with a stochastic actor. ICML 2018.
R. E. Kalman. A new approach to linear filtering and prediction problems. Journal of Basic Engineering, 1960.