The chapters of this book reuse a small number of identities. Each was
introduced where it was first needed, usually with a derivation shaped by
that chapter's example. This appendix collects them in one place, in their
general form, each with a proof short enough to check and a note on where
the book relies on it.
The five sections build on one another. Block inversion is the root: the
Woodbury identity is block inversion read in two ways, Gaussian conditioning
is block inversion applied to a covariance matrix, and the product of two
Gaussian densities is conditioning in disguise. The last section, on the
expected maximum of two Gaussian values, is independent of the others and
serves the acquisition functions of Chapter 12 and Chapter 19.
Throughout, vectors are columns, I is an identity matrix of whatever size
fits, and every matrix that is inverted is assumed to be invertible.
A matrix whose rows and columns fall into two groups can be inverted group
by group. Write it in blocks,
M=[ACBD],
(B.1)
with A of size p×p and D of size q×q. The
matrix need not be symmetric. The Schur complement of A in
M is
S=D−CA−1B,
(B.2)
what remains of D after the first group has been eliminated, in
the same way that elimination on two equations leaves d−cb/a in the
corner of a 2×2 matrix.
Eliminate the off-diagonal blocks with two triangular matrices,
E=[I−CA−10I],F=[I0−A−1BI].
Multiplying by E on the left subtracts CA−1
times the first block row from the second. The bottom-left block becomes
C−CA−1A=0 and the bottom-right
block becomes D−CA−1B=S.
Multiplying the result by F on the right subtracts the first
block column times A−1B from the second, which clears the
top-right block and leaves the rest unchanged. So
EMF=[A00S].
E and F are invertible: each is undone by the same
matrix with the sign of its off-diagonal block flipped. Inverting both
sides of step 2 gives
F−1M−1E−1=diag(A−1,S−1),
the block-diagonal matrix with those two blocks, and so
M−1=Fdiag(A−1,S−1)E.
Multiply out. Fdiag(A−1,S−1) has
top row (A−1,−A−1BS−1) and bottom row
(0,S−1), and multiplying by E on the
right adds −CA−1 times the second column to the first,
which gives the four blocks of Equation (B.3).
E and F are triangular with ones on the diagonal, so
their determinants are 1, and the determinant of a product is the product
of the determinants (Section 3.6). Step 2 then gives
detM=detA⋅detS.
Nothing singled out the first group. Eliminating the second group instead,
with the Schur complement of D,
T=A−BD−1C, the same argument
gives a second expression for the same inverse:
Where the book uses it.Section 3.7.2 derives the symmetric case,
C=B⊤, step by step, and shows that a symmetric
M is positive definite exactly when A and S are.
The bottom-right block of Equation (B.3), S−1, is why the
covariance of a conditioned Gaussian is a Schur complement
(Section B.3). Taking the second group to be a single coordinate
gives the leave-one-out formulas Equation (9.6), and adding one row and column
to a factored matrix gives the Cholesky update of
Section 3.7.3.
The two expressions for M−1 must agree block by block.
Comparing their top-left blocks produces the most useful identity in this
appendix. It says how the inverse of a matrix changes when a low-rank matrix
is added to it.
Theorem B.2Woodbury identity
Let Z be n×n, W be m×m, and U and
V be n×m. Then
(Z+UWV⊤)−1=Z−1−Z−1UN−1V⊤Z−1,where N=W−1+V⊤Z−1U.
(B.5)
Proof
Apply Section B.1 to the block matrix with A=Z,
B=−U, C=V⊤, and
D=W−1.
The Schur complement of A is
S=W−1+V⊤Z−1U=N,
and by Equation (B.3) the top-left block of the inverse is
P=Z−1−Z−1UN−1V⊤Z−1.
The Schur complement of D is
T=Z+UWV⊤, and by
Equation (B.4) the top-left block of the inverse is
T−1.
A matrix has one inverse, so the two blocks are equal.
The identity is also called the matrix inversion lemma
(Rasmussen and Williams, 2006, app. A.3). Its value is in the sizes. The left side
inverts an n×n matrix. The right side, given Z−1,
inverts only the m×m matrix N. When Z is easy
to invert, a diagonal matrix for example, and m is much smaller than n,
the cost falls from O(n3) to O(nm2).
Three companions follow from the same block matrix.
Rank one. With m=1, W=1, and vectors u,v
in place of U,V, the middle inverse is a number. This is
the Sherman-Morrison formula:
(Z+uv⊤)−1=Z−1−1+v⊤Z−1uZ−1uv⊤Z−1.
(B.6)
Determinants. Equating the two determinant formulas of Section B.1
for the same block matrix gives the matrix determinant lemma
(Rasmussen and Williams, 2006, app. A.3):
det(Z+UWV⊤)=detZdetWdetN.
(B.7)
Pushing through. For any X of size n×m and
Y of size m×n,
(I+XY)−1X=X(I+YX)−1,
(B.8)
because X(I+YX)=(I+XY)X,
and multiplying by the two inverses, one on each side, moves them across.
Example B.1Weight space and function space agree
Section 5.4.2 found the posterior of a linear model with M
features in weight space: covariance Aw−1 with
Aw=Σp−1+σn−2Φ⊤Φ, an
M×M matrix, and mean
wˉ=σn−2Aw−1Φ⊤y.
Section 8.3 predicts in function space with the n×n matrix
Ky=ΦΣpΦ⊤+σn2I. The
two must give the same predictions, and the identities show that they do.
Covariance. Apply Equation (B.5) with Z=Σp−1,
U=V=Φ⊤, and W=σn−2I:
Aw−1=Σp−ΣpΦ⊤Ky−1ΦΣp.
Multiply by the features ϕ∗ of a new input on both sides.
The left side is the weight-space predictive variance
ϕ∗⊤Aw−1ϕ∗. The right side is
k(x∗,x∗)−k∗⊤Ky−1k∗, with the kernel
k(x,x′)=ϕ(x)⊤Σpϕ(x′) of
Equation (7.3) and k∗=ΦΣpϕ∗.
That is Equation (8.6).
Mean. From the definitions,
AwΣpΦ⊤=Φ⊤+σn−2Φ⊤ΦΣpΦ⊤=σn−2Φ⊤Ky.
Multiplying by Aw−1 on the left and Ky−1 on the right gives
σn−2Aw−1Φ⊤=ΣpΦ⊤Ky−1,
a push-through identity. So
ϕ∗⊤wˉ=k∗⊤Ky−1y, again Equation (8.6).
Weight space inverts an M×M matrix and function space an
n×n one (Rasmussen and Williams, 2006, sec. 2.1.2). With a few features
and many observations, weight space is cheaper. With infinitely many
features, only function space is possible (Section 7.2).
In terms of the precision matrix Λ=Σ−1, partitioned
the same way, the conditional has precision Λbb and mean
μb−Λbb−1Λab⊤(a−μa).
Proof
The marginal is the linear map that keeps a and drops
b, and linear maps of Gaussians are Gaussian with the mapped mean
and covariance (Equation (4.9)).
For the conditional, the density of b given a is
proportional, as a function of b, to the joint density, whose
logarithm is −21(x−μ)⊤Λ(x−μ) plus a
constant. Collecting the terms in b leaves a quadratic with
precision Λbb and the mean stated in precision form. By
Theorem B.1 applied to Σ, with the Schur complement
S=Σbb−Σab⊤Σaa−1Σab, the
blocks of the precision are Λbb=S−1 and
Λab⊤=−S−1Σab⊤Σaa−1.
Substituting gives covariance S and mean offset
Σab⊤Σaa−1(a−μa).
Section 4.5.2 carries out each step, and gives a second
proof that avoids the precision matrix.
Three features of Equation (B.9) recur throughout the book. The
conditional mean is linear in the observed block. The conditional covariance
does not depend on the observed values at all. And the conditional
covariance is the prior covariance minus a positive semidefinite matrix, so
observing can only reduce uncertainty.
Most models in this book are not given as a joint Gaussian. They are given
as a Gaussian prior and an observation that is a linear function of the
unknown plus Gaussian noise. The next result converts one form into the
other.
Theorem B.4The linear-Gaussian pair
Let a∼N(μ,Σ) and
b∣a∼N(Ha+c,R).
Then a and b are jointly Gaussian with
Write b=Ha+c+e with
e∼N(0,R) independent of a. The
pair (a,e) is jointly Gaussian because its parts are
independent Gaussians, and (a,b) is a linear map of it,
so it is jointly Gaussian too. Its moments follow by linearity:
Cov[a,b]=Cov[a,Ha]=ΣH⊤,
and Cov[b]=HΣH⊤+R because
the two independent parts of b add their covariances. The
posterior is Equation (B.9) with the roles of the two blocks exchanged.
Where the book uses it. With H=I on the observed inputs
and R=σn2I, Equation (B.10) is the joint distribution
behind Gaussian process regression with noise (Section 8.3), and its
middle formula is the covariance Ky of the marginal likelihood
(Section 9.3). With H=Φ it is
Bayesian linear regression (Section 5.4), in the function-space form of
Example B.1. The matrix G is called the gain: it converts the
surprise in the observation into a correction of the prior mean.
Multiplying two Gaussian densities over the same variable gives a Gaussian
shape again, scaled by a constant. Write N(x;μ,Σ) for the
Gaussian density with mean μ and covariance Σ, evaluated at
x.
Theorem B.5Product of two Gaussian densities
N(x;μ1,Σ1)N(x;μ2,Σ2)=ZN(x;μ,Σ),
(B.12)
with
Σ=(Σ1−1+Σ2−1)−1,
μ=Σ(Σ1−1μ1+Σ2−1μ2), and
Z=N(μ1;μ2,Σ1+Σ2).
Proof
Read the product as a model. Let x∼N(μ1,Σ1) and
y∣x∼N(x,Σ2).
The joint density is
p(x)p(y∣x)=N(x;μ1,Σ1)N(y;x,Σ2).
A Gaussian density depends on its argument and its mean only through
their difference, so N(y;x,Σ2)=N(x;y,Σ2).
At y=μ2 the joint density is the left side of Equation (B.12).
The same joint density factors the other way, as
p(y)p(x∣y). By Theorem B.4 with
H=I, c=0, and R=Σ2:
p(y)=N(y;μ1,Σ1+Σ2), and p(x∣y)
is Gaussian with covariance
Σ1−Σ1(Σ1+Σ2)−1Σ1 and mean
μ1+Σ1(Σ1+Σ2)−1(y−μ1).
At y=μ2, the first factor is the constant Z.
By Equation (B.5) with Z=Σ1−1,
U=V=I, and W=Σ2−1, the covariance
in step 2 equals (Σ1−1+Σ2−1)−1=Σ.
From step 4,
ΣΣ1−1=I−Σ1(Σ1+Σ2)−1, and
since Σ(Σ1−1+Σ2−1)=I,
ΣΣ2−1=Σ1(Σ1+Σ2)−1. So the mean in
step 2 at y=μ2 is
ΣΣ1−1μ1+ΣΣ2−1μ2=μ.
The proof explains the three parts of the result. Precisions add because two
independent pieces of evidence about the same quantity are being combined.
The mean is the precision-weighted average of the two means. And the
constant Z is the probability density that the first Gaussian, blurred by
the second, assigns to the second's center: it is large when the two
densities overlap and tiny when they do not. Section 4.6.2 derives the
one-dimensional case by completing the square and shows it in a figure.
Example B.2Two bumps in one variable
Section 7.2.1 needed the integral over c of a product of two
unnormalized bumps, e−(x−c)2/2s2e−(x′−c)2/2s2. As functions
of c, each bump is 2πs2 times a Gaussian density with variance
s2, centered at x and at x′. By Equation (B.12) the product is
2πs2⋅N(x;x′,2s2)⋅N(c;2x+x′,2s2).
The last factor integrates to 1 over c, so the integral is
2πs2N(x;x′,2s2)=sπe−(x−x′)2/4s2, the value
found there by completing the square. The RBF kernel is the constant Z of
a product of two bumps.
Where the book uses it. Bayes' rule with a Gaussian prior and a Gaussian
likelihood is Equation (B.12), with Z the model evidence (Section 5.6).
Expectation propagation (Section 17.3) multiplies and divides Gaussian factors
with the same rule, one factor at a time.
Several acquisition functions ask for the expected value of the larger of
two uncertain quantities. Expected improvement compares an uncertain value
with a known one (Section 12.3). The expected utility of the best option compares
two uncertain values of a utility (Section 19.4). When the two quantities are
jointly Gaussian, the expectation has a closed form.
Theorem B.6Expected maximum of two Gaussians
Let A and B be jointly Gaussian with means μA,μB, variances
vA,vB, and covariance c. Write δ=μA−μB and
s2=vA+vB−2c, the variance of A−B. If s>0,
E[max{A,B}]=μAΦ(α)+μBΦ(−α)+sϕ(α),α=δ/s,
(B.13)
where ϕ and Φ are the standard normal density and distribution
function. If s=0, the expectation is max{μA,μB}.
Proof
For any two numbers, max{A,B}=B+max{A−B,0}.
D=A−B is a linear map of a Gaussian vector, so it is Gaussian
(Equation (4.9)), with mean δ and variance
Var[A]+Var[B]−2Cov[A,B]=s2.
If s>0, write D=δ+sZ with Z standard normal. Then
max{D,0} vanishes unless Z>−δ/s, and
E[max{D,0}]=∫−δ/s∞(δ+sz)ϕ(z)dz.
The first part is δ(1−Φ(−δ/s))=δΦ(δ/s).
For the second, ϕ′(z)=−zϕ(z), so zϕ(z) has antiderivative
−ϕ(z) and the integral of zϕ(z) from −δ/s to infinity is
ϕ(−δ/s)=ϕ(δ/s). So
E[max{D,0}]=δΦ(δ/s)+sϕ(δ/s).
By linearity of expectation and step 1,
E[max{A,B}]=μB+δΦ(δ/s)+sϕ(δ/s).
Since μB+δΦ(δ/s)=μAΦ(δ/s)+μB(1−Φ(δ/s))
and 1−Φ(t)=Φ(−t), this is Equation (B.13).
If s=0, D equals the constant δ, and
max{A,B}=B+max{δ,0} has expectation
max{μA,μB}.
The formula is due to Clark (1961), whose paper gives exact results
for two jointly normal variables with any correlation and approximations,
by repeated application, for more than two. Step 3 is the computation behind
expected improvement, which Section 12.3 carries out step by step
(Equation (12.4)).
The formula can be read term by term. Φ(δ/s) is the probability
that A exceeds B, so the first two terms average the means, each
weighted by the probability that its variable is the larger. The third term
is a bonus for not knowing which is larger, and it depends on the
uncertainty only through s. Four consequences are used in the book.
Never below the better mean.max{D,0}≥D and
max{D,0}≥0, so E[max{D,0}]≥max{δ,0} and
E[max{A,B}]≥max{μA,μB}.
Increasing in s. Differentiating step 3 with respect to s, the
terms from Φ and from ϕ′ cancel and leave exactly
ϕ(δ/s)>0. More uncertainty about the difference is always worth
more.
Correlation matters only through s. Positive correlation between A
and B lowers s and with it the expected maximum; negative correlation
raises it. Two options that rise and fall together offer little choice.
Equal means. With δ=0 the formula reduces to
μ+s/2π: the bonus is about 0.4s.
The figure shows the whole distribution of the maximum, of which
Equation (B.13) is the mean.
Figure B.1 The maximum of two jointly Gaussian values. Thin curves: the densities of A and B. Shaded: the exact density of max{A,B}. The solid vertical line is its mean, Equation (B.13); the dashed line is the better of the two means. The readout checks the formula against a numerical integral of the shaded density and reports the bonus over the better mean.
Press Equal means. The bonus is s/2π: with standard
deviations 1 and 0.5 and no correlation, s=1.12 and the bonus is 0.446.
Raise the correlation toward 0.95. The bonus shrinks, because s does.
With both standard deviations equal and the correlation near 1, the two
values move together, their difference is almost constant, and the maximum
is worth almost exactly the better mean.
Lower the correlation toward −0.95. Now one value is high when the
other is low, the maximum is almost always well above both means, and the
bonus is at its largest.
Press One certain option. With B nearly constant, the shaded density
is the density of A with everything below B swept up to B. Its mean
is μB plus the expected improvement of A over μB. Expected
improvement is the special case of Equation (B.13) in which one of the two
values is known.
Where the book uses it.Equation (B.13) is the closed form of EUBO for a
pair of options, Equation (19.3), with A and B the posterior utilities of
the two options. It is also the knowledge gradient when only two inputs are
in play (Section 12.6). There the two values are linear functions
of one standard normal variable, so they are perfectly correlated, and the
theorem applies with s equal to the difference of their slopes in absolute
value.
Sources cited in Section B.5 1
Clark (1961) The Greatest of a Finite Set of Random Variables
Let 1 be the vector of n ones. Use Equation (B.6) to
compute (σ2I+11⊤)−11, and from it
the posterior variance at x0 after n noisy observations at x0 under a
unit-amplitude kernel, as in Exercise 8.2.
Solution
With Z=σ2I and u=v=1,
Z−11=1/σ2 and
1⊤Z−11=n/σ2. So
All kernel values are 1, so K=11⊤ and
k(x0)=1, and the posterior variance of Equation (8.6) is
1−1⊤1/(σ2+n)=σ2/(σ2+n).
Exercise B.2
Use Equation (B.7) to compute the determinant of
σ2I+11⊤ for n observations, and with it the
complexity term −21log∣Ky∣ of Equation (9.4) for a
unit-amplitude kernel with an infinitely long lengthscale. Compare with a
very short lengthscale, where Ky=(1+σ2)I.
Solution
With Z=σ2I, U=V=1, and
W=1:
det(σ2I+11⊤)=σ2n(1+n/σ2)=σ2(n−1)(σ2+n).
The complexity term is
−21[(n−1)logσ2+log(σ2+n)]. For small
noise this is large and positive: with n=7 and σ=0.1 it is
−21[6×(−4.61)+1.95]=12.8. At a very short
lengthscale the determinant is (1+σ2)n and the term is
−2nlog(1+σ2)=−0.03. The long lengthscale is charged
far less for complexity, because it expects all observations to be nearly
equal, a thin sliver of the space of data sets. It pays in the data-fit
term unless the observations really are nearly equal.
Exercise B.3
Let A and B be independent standard normal variables. (a) Use
Equation (B.13) to find E[max{A,B}]. (b) Show that
E[max{A,B}2]=1 without integrating, and find the variance of the
maximum. (c) Check both numbers in Figure B.1.
Solution
(a) δ=0 and s2=2, so the expectation is
sϕ(0)=2/2π=1/π≈0.564.
(b) max{A,B}2+min{A,B}2=A2+B2, whose expectation is 2.
The pair (−A,−B) has the same distribution as (A,B), and
min{A,B}=−max{−A,−B}, so min{A,B}2 and max{A,B}2
have the same expectation, which must be 1. The variance is
1−1/π≈0.682: the maximum of two draws is less variable than
either draw. (c) Set both means to 0, both standard deviations to 1, and the
correlation to 0. The readout gives 0.564, and the shaded density is
visibly narrower than the two thin curves.
Rasmussen and Williams (2006), appendix A, lists the Gaussian and matrix
identities used in Gaussian process regression, in the same notation as
the rest of that book.
Bishop (2006), section 2.3, derives the marginal, the conditional,
and the linear-Gaussian pair at textbook length.
Golub and Van Loan (2013) is the standard reference on computing with matrices,
including why factorizations are preferred to explicit inverses.
Clark (1961) is the original paper on the maximum of jointly normal
variables.