Bayesian Optimization
中文

Matrix and Gaussian Identities

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\mI is an identity matrix of whatever size fits, and every matrix that is inverted is assumed to be invertible.

B.1 Block inversion and the Schur complement #

A matrix whose rows and columns fall into two groups can be inverted group by group. Write it in blocks,

M=[ABCD],\mathbf{M} = \begin{bmatrix} \mA & \mathbf{B} \\ \mathbf{C} & \mathbf{D} \end{bmatrix},
(B.1)

with A\mA of size p×pp \times p and D\mathbf{D} of size q×qq \times q. The matrix need not be symmetric. The Schur complement of A\mA in M\mathbf{M} is

S=D−CA−1B,\mathbf{S} = \mathbf{D} - \mathbf{C}\mA^{-1}\mathbf{B},
(B.2)

what remains of D\mathbf{D} after the first group has been eliminated, in the same way that elimination on two equations leaves d−cb/ad - cb/a in the corner of a 2×22 \times 2 matrix.

Theorem B.1 Block inversion

If A\mA and S\mathbf{S} are invertible, then

M−1=[PQRS−1],P=A−1+A−1B S−1CA−1,Q=−A−1B S−1,R=−S−1CA−1,\begin{aligned} \mathbf{M}^{-1} &= \begin{bmatrix} \mathbf{P} & \mathbf{Q} \\ \mathbf{R} & \mathbf{S}^{-1} \end{bmatrix}, \\ \mathbf{P} &= \mA^{-1} + \mA^{-1}\mathbf{B}\,\mathbf{S}^{-1}\mathbf{C}\mA^{-1}, \\ \mathbf{Q} &= -\mA^{-1}\mathbf{B}\,\mathbf{S}^{-1}, \\ \mathbf{R} &= -\mathbf{S}^{-1}\mathbf{C}\mA^{-1}, \end{aligned}
(B.3)

and det⁡M=det⁡A⋅det⁡S\det\mathbf{M} = \det\mA \cdot \det\mathbf{S}.

Proof

Eliminate the off-diagonal blocks with two triangular matrices,

E=[I0−CA−1I],F=[I−A−1B0I].\mathbf{E} = \begin{bmatrix} \mI & \mathbf{0} \\ -\mathbf{C}\mA^{-1} & \mI \end{bmatrix}, \qquad \mathbf{F} = \begin{bmatrix} \mI & -\mA^{-1}\mathbf{B} \\ \mathbf{0} & \mI \end{bmatrix}.
  1. Multiplying by E\mathbf{E} on the left subtracts CA−1\mathbf{C}\mA^{-1} times the first block row from the second. The bottom-left block becomes C−CA−1A=0\mathbf{C} - \mathbf{C}\mA^{-1}\mA = \mathbf{0} and the bottom-right block becomes D−CA−1B=S\mathbf{D} - \mathbf{C}\mA^{-1}\mathbf{B} = \mathbf{S}.
  2. Multiplying the result by F\mathbf{F} on the right subtracts the first block column times A−1B\mA^{-1}\mathbf{B} from the second, which clears the top-right block and leaves the rest unchanged. So
    E M F=[A00S].\mathbf{E}\,\mathbf{M}\,\mathbf{F} = \begin{bmatrix} \mA & \mathbf{0} \\ \mathbf{0} & \mathbf{S} \end{bmatrix}.
  3. E\mathbf{E} and F\mathbf{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)\mathbf{F}^{-1}\mathbf{M}^{-1}\mathbf{E}^{-1} = \operatorname{diag}(\mA^{-1}, \mathbf{S}^{-1}), the block-diagonal matrix with those two blocks, and so M−1=Fdiag⁡(A−1,S−1) E\mathbf{M}^{-1} = \mathbf{F}\operatorname{diag}(\mA^{-1}, \mathbf{S}^{-1})\,\mathbf{E}.
  4. Multiply out. Fdiag⁡(A−1,S−1)\mathbf{F}\operatorname{diag}(\mA^{-1}, \mathbf{S}^{-1}) has top row (A−1, −A−1BS−1)(\mA^{-1},\, -\mA^{-1}\mathbf{B}\mathbf{S}^{-1}) and bottom row (0, S−1)(\mathbf{0},\, \mathbf{S}^{-1}), and multiplying by E\mathbf{E} on the right adds −CA−1-\mathbf{C}\mA^{-1} times the second column to the first, which gives the four blocks of Equation (B.3).
  5. E\mathbf{E} and F\mathbf{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 det⁡M=det⁡A⋅det⁡S\det\mathbf{M} = \det\mA\cdot\det\mathbf{S}.

Nothing singled out the first group. Eliminating the second group instead, with the Schur complement of D\mathbf{D}, T=A−BD−1C\mathbf{T} = \mA - \mathbf{B}\mathbf{D}^{-1}\mathbf{C}, the same argument gives a second expression for the same inverse:

M−1=[T−1Q′R′P′],P′=D−1+D−1C T−1BD−1,Q′=−T−1BD−1,R′=−D−1C T−1,\begin{aligned} \mathbf{M}^{-1} &= \begin{bmatrix} \mathbf{T}^{-1} & \mathbf{Q}' \\ \mathbf{R}' & \mathbf{P}' \end{bmatrix}, \\ \mathbf{P}' &= \mathbf{D}^{-1} + \mathbf{D}^{-1}\mathbf{C}\,\mathbf{T}^{-1}\mathbf{B}\mathbf{D}^{-1}, \\ \mathbf{Q}' &= -\mathbf{T}^{-1}\mathbf{B}\mathbf{D}^{-1}, \\ \mathbf{R}' &= -\mathbf{D}^{-1}\mathbf{C}\,\mathbf{T}^{-1}, \end{aligned}
(B.4)

with det⁡M=det⁡D⋅det⁡T\det\mathbf{M} = \det\mathbf{D}\cdot\det\mathbf{T}.

Where the book uses it. Section 3.7.2 derives the symmetric case, C=B⊤\mathbf{C} = \mathbf{B}^\T, step by step, and shows that a symmetric M\mathbf{M} is positive definite exactly when A\mA and S\mathbf{S} are. The bottom-right block of Equation (B.3), S−1\mathbf{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.

B.2 The Woodbury identity #

The two expressions for M−1\mathbf{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.2 Woodbury identity

Let Z\mathbf{Z} be n×nn \times n, W\mW be m×mm \times m, and U\mathbf{U} and V\mathbf{V} be n×mn \times m. Then

(Z+UWV⊤)−1=Z−1−Z−1U N−1V⊤Z−1,where N=W−1+V⊤Z−1U.\begin{aligned} &\left(\mathbf{Z} + \mathbf{U}\mW\mathbf{V}^\T\right)^{-1} = \mathbf{Z}^{-1} - \mathbf{Z}^{-1}\mathbf{U}\,\mathbf{N}^{-1}\mathbf{V}^\T\mathbf{Z}^{-1}, \\ &\text{where } \mathbf{N} = \mW^{-1} + \mathbf{V}^\T\mathbf{Z}^{-1}\mathbf{U}. \end{aligned}
(B.5)
Proof

Apply Section B.1 to the block matrix with A=Z\mA = \mathbf{Z}, B=−U\mathbf{B} = -\mathbf{U}, C=V⊤\mathbf{C} = \mathbf{V}^\T, and D=W−1\mathbf{D} = \mW^{-1}.

  1. The Schur complement of A\mA is S=W−1+V⊤Z−1U=N\mathbf{S} = \mW^{-1} + \mathbf{V}^\T\mathbf{Z}^{-1}\mathbf{U} = \mathbf{N}, and by Equation (B.3) the top-left block of the inverse is P=Z−1−Z−1U N−1V⊤Z−1\mathbf{P} = \mathbf{Z}^{-1} - \mathbf{Z}^{-1}\mathbf{U}\,\mathbf{N}^{-1}\mathbf{V}^\T\mathbf{Z}^{-1}.
  2. The Schur complement of D\mathbf{D} is T=Z+UWV⊤\mathbf{T} = \mathbf{Z} + \mathbf{U}\mW\mathbf{V}^\T, and by Equation (B.4) the top-left block of the inverse is T−1\mathbf{T}^{-1}.
  3. 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×nn \times n matrix. The right side, given Z−1\mathbf{Z}^{-1}, inverts only the m×mm \times m matrix N\mathbf{N}. When Z\mathbf{Z} is easy to invert, a diagonal matrix for example, and mm is much smaller than nn, the cost falls from O(n3)O(n^3) to O(nm2)O(nm^2).

Three companions follow from the same block matrix.

Rank one. With m=1m = 1, W=1\mW = 1, and vectors u,v\mathbf{u}, \mathbf{v} in place of U,V\mathbf{U}, \mathbf{V}, the middle inverse is a number. This is the Sherman-Morrison formula:

(Z+uv⊤)−1=Z−1−Z−1u v⊤Z−11+v⊤Z−1u.\left(\mathbf{Z} + \mathbf{u}\mathbf{v}^\T\right)^{-1} = \mathbf{Z}^{-1} - \frac{\mathbf{Z}^{-1}\mathbf{u}\,\mathbf{v}^\T\mathbf{Z}^{-1}}{1 + \mathbf{v}^\T\mathbf{Z}^{-1}\mathbf{u}}.
(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⊤)=det⁡Z det⁡W det⁡N.\det(\mathbf{Z} + \mathbf{U}\mW\mathbf{V}^\T) = \det\mathbf{Z}\,\det\mW\,\det\mathbf{N}.
(B.7)

Pushing through. For any X\mathbf{X} of size n×mn \times m and Y\mathbf{Y} of size m×nm \times n,

(I+XY)−1X=X(I+YX)−1,\left(\mI + \mathbf{X}\mathbf{Y}\right)^{-1}\mathbf{X} = \mathbf{X}\left(\mI + \mathbf{Y}\mathbf{X}\right)^{-1},
(B.8)

because X(I+YX)=(I+XY)X\mathbf{X}(\mI + \mathbf{Y}\mathbf{X}) = (\mI + \mathbf{X}\mathbf{Y})\mathbf{X}, and multiplying by the two inverses, one on each side, moves them across.

Example B.1 Weight space and function space agree

Section 5.4.2 found the posterior of a linear model with MM features in weight space: covariance Aw−1\mA_w^{-1} with Aw=Σp−1+σn−2Φ⊤Φ\mA_w = \mSigma_p^{-1} + \sigma_n^{-2}\boldsymbol{\Phi}^\T\boldsymbol{\Phi}, an M×MM \times M matrix, and mean wˉ=σn−2Aw−1Φ⊤y\bar{\vw} = \sigma_n^{-2}\mA_w^{-1}\boldsymbol{\Phi}^\T\vy. Section 8.3 predicts in function space with the n×nn \times n matrix Ky=ΦΣpΦ⊤+σn2I\mK_y = \boldsymbol{\Phi}\mSigma_p\boldsymbol{\Phi}^\T + \sigma_n^2\mI. The two must give the same predictions, and the identities show that they do.

Covariance. Apply Equation (B.5) with Z=Σp−1\mathbf{Z} = \mSigma_p^{-1}, U=V=Φ⊤\mathbf{U} = \mathbf{V} = \boldsymbol{\Phi}^\T, and W=σn−2I\mW = \sigma_n^{-2}\mI:

Aw−1=Σp−ΣpΦ⊤Ky−1ΦΣp.\mA_w^{-1} = \mSigma_p - \mSigma_p\boldsymbol{\Phi}^\T\mK_y^{-1}\boldsymbol{\Phi}\mSigma_p.

Multiply by the features ϕ∗\boldsymbol{\phi}_* of a new input on both sides. The left side is the weight-space predictive variance ϕ∗⊤Aw−1ϕ∗\boldsymbol{\phi}_*^\T\mA_w^{-1}\boldsymbol{\phi}_*. The right side is k(x∗,x∗)−k∗⊤Ky−1k∗k(\vx_*, \vx_*) - \vk_*^\T\mK_y^{-1}\vk_*, with the kernel k(x,x′)=ϕ(x)⊤Σpϕ(x′)k(\vx, \vx') = \boldsymbol{\phi}(\vx)^\T\mSigma_p\boldsymbol{\phi}(\vx') of Equation (7.3) and k∗=ΦΣpϕ∗\vk_* = \boldsymbol{\Phi}\mSigma_p\boldsymbol{\phi}_*. That is Equation (8.6).

Mean. From the definitions, AwΣpΦ⊤=Φ⊤+σn−2Φ⊤ΦΣpΦ⊤=σn−2Φ⊤Ky\mA_w\mSigma_p\boldsymbol{\Phi}^\T = \boldsymbol{\Phi}^\T + \sigma_n^{-2}\boldsymbol{\Phi}^\T\boldsymbol{\Phi}\mSigma_p\boldsymbol{\Phi}^\T = \sigma_n^{-2}\boldsymbol{\Phi}^\T\mK_y. Multiplying by Aw−1\mA_w^{-1} on the left and Ky−1\mK_y^{-1} on the right gives σn−2Aw−1Φ⊤=ΣpΦ⊤Ky−1\sigma_n^{-2}\mA_w^{-1}\boldsymbol{\Phi}^\T = \mSigma_p\boldsymbol{\Phi}^\T\mK_y^{-1}, a push-through identity. So ϕ∗⊤wˉ=k∗⊤Ky−1y\boldsymbol{\phi}_*^\T\bar{\vw} = \vk_*^\T\mK_y^{-1}\vy, again Equation (8.6).

Weight space inverts an M×MM \times M matrix and function space an n×nn \times 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).

Where the book uses it. Besides the example, Equation (B.6) gives a second solution of Exercise 8.2 (Exercise B.1), and the low-rank approximations that make Gaussian processes affordable for large data sets (Section 8.4) apply Equation (B.5) and Equation (B.7) with mm inducing points in place of nn observations (Quiñonero-Candela and Rasmussen, 2005).

Sources cited in Section B.2 2
  1. Rasmussen and Williams (2006) Gaussian Processes for Machine Learning
  2. Quiñonero-Candela and Rasmussen (2005) A Unifying View of Sparse Approximate Gaussian Process Regression

B.3 Conditioning a Gaussian #

Let a Gaussian vector be split into two blocks, with the notation of Equation (4.12):

[ab]∼N ⁣([μaμb],  [ΣaaΣabΣab⊤Σbb]).\begin{bmatrix} \mathbf{a} \\ \mathbf{b} \end{bmatrix} \sim \N\!\left( \begin{bmatrix} \vmu_a \\ \vmu_b \end{bmatrix},\; \begin{bmatrix} \mSigma_{aa} & \mSigma_{ab} \\ \mSigma_{ab}^\T & \mSigma_{bb} \end{bmatrix} \right).

Two operations reduce it to a statement about one block, and both return a Gaussian.

Theorem B.3 Marginal and conditional of a Gaussian

The marginal distribution of a\mathbf{a} is N(μa,Σaa)\N(\vmu_a, \mSigma_{aa}). The conditional distribution of b\mathbf{b} given a\mathbf{a} is Gaussian,

b ∣ a∼N ⁣(μb∣a, Σb∣a),μb∣a=μb+Σab⊤Σaa−1(a−μa),Σb∣a=Σbb−Σab⊤Σaa−1Σab.\begin{aligned} \mathbf{b} \given \mathbf{a} &\sim \N\!\left(\vmu_{b \mid a},\, \mSigma_{b \mid a}\right), \\ \vmu_{b \mid a} &= \vmu_b + \mSigma_{ab}^\T\mSigma_{aa}^{-1}(\mathbf{a} - \vmu_a), \\ \mSigma_{b \mid a} &= \mSigma_{bb} - \mSigma_{ab}^\T\mSigma_{aa}^{-1}\mSigma_{ab}. \end{aligned}
(B.9)

In terms of the precision matrix Λ=Σ−1\bm{\Lambda} = \mSigma^{-1}, partitioned the same way, the conditional has precision Λbb\bm{\Lambda}_{bb} and mean μb−Λbb−1Λab⊤(a−μa)\vmu_b - \bm{\Lambda}_{bb}^{-1}\bm{\Lambda}_{ab}^\T(\mathbf{a} - \vmu_a).

Proof

The marginal is the linear map that keeps a\mathbf{a} and drops b\mathbf{b}, and linear maps of Gaussians are Gaussian with the mapped mean and covariance (Equation (4.9)).

For the conditional, the density of b\mathbf{b} given a\mathbf{a} is proportional, as a function of b\mathbf{b}, to the joint density, whose logarithm is −12(x−μ)⊤Λ(x−μ)-\tfrac12(\vx - \vmu)^\T\bm{\Lambda}(\vx - \vmu) plus a constant. Collecting the terms in b\mathbf{b} leaves a quadratic with precision Λbb\bm{\Lambda}_{bb} and the mean stated in precision form. By Theorem B.1 applied to Σ\mSigma, with the Schur complement S=Σbb−Σab⊤Σaa−1Σab\mathbf{S} = \mSigma_{bb} - \mSigma_{ab}^\T\mSigma_{aa}^{-1}\mSigma_{ab}, the blocks of the precision are Λbb=S−1\bm{\Lambda}_{bb} = \mathbf{S}^{-1} and Λab⊤=−S−1Σab⊤Σaa−1\bm{\Lambda}_{ab}^\T = -\mathbf{S}^{-1}\mSigma_{ab}^\T\mSigma_{aa}^{-1}. Substituting gives covariance S\mathbf{S} and mean offset Σab⊤Σaa−1(a−μa)\mSigma_{ab}^\T\mSigma_{aa}^{-1}(\mathbf{a} - \vmu_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.4 The linear-Gaussian pair

Let a∼N(μ,Σ)\mathbf{a} \sim \N(\vmu, \mSigma) and b ∣ a∼N(Ha+c, R)\mathbf{b} \given \mathbf{a} \sim \N(\mathbf{H}\mathbf{a} + \mathbf{c},\, \mathbf{R}). Then a\mathbf{a} and b\mathbf{b} are jointly Gaussian with

E[b]=Hμ+c,Cov⁡[b]=HΣH⊤+R,Cov⁡[a,b]=ΣH⊤,\begin{aligned} \E[\mathbf{b}] &= \mathbf{H}\vmu + \mathbf{c}, \\ \Cov[\mathbf{b}] &= \mathbf{H}\mSigma\mathbf{H}^\T + \mathbf{R}, \\ \Cov[\mathbf{a}, \mathbf{b}] &= \mSigma\mathbf{H}^\T, \end{aligned}
(B.10)

and the posterior of a\mathbf{a} given b\mathbf{b} is Gaussian with

E[a ∣ b]=μ+G (b−Hμ−c),Cov⁡[a ∣ b]=Σ−G HΣ,G=ΣH⊤(HΣH⊤+R)−1.\begin{aligned} \E[\mathbf{a} \given \mathbf{b}] &= \vmu + \mathbf{G}\,(\mathbf{b} - \mathbf{H}\vmu - \mathbf{c}), \\ \Cov[\mathbf{a} \given \mathbf{b}] &= \mSigma - \mathbf{G}\,\mathbf{H}\mSigma, \\ \mathbf{G} &= \mSigma\mathbf{H}^\T\left(\mathbf{H}\mSigma\mathbf{H}^\T + \mathbf{R}\right)^{-1}. \end{aligned}
(B.11)
Proof

Write b=Ha+c+e\mathbf{b} = \mathbf{H}\mathbf{a} + \mathbf{c} + \mathbf{e} with e∼N(0,R)\mathbf{e} \sim \N(\mathbf{0}, \mathbf{R}) independent of a\mathbf{a}. The pair (a,e)(\mathbf{a}, \mathbf{e}) is jointly Gaussian because its parts are independent Gaussians, and (a,b)(\mathbf{a}, \mathbf{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⊤\Cov[\mathbf{a}, \mathbf{b}] = \Cov[\mathbf{a}, \mathbf{H}\mathbf{a}] = \mSigma\mathbf{H}^\T, and Cov⁡[b]=HΣH⊤+R\Cov[\mathbf{b}] = \mathbf{H}\mSigma\mathbf{H}^\T + \mathbf{R} because the two independent parts of b\mathbf{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\mathbf{H} = \mI on the observed inputs and R=σn2I\mathbf{R} = \sigma_n^2\mI, Equation (B.10) is the joint distribution behind Gaussian process regression with noise (Section 8.3), and its middle formula is the covariance Ky\mK_y of the marginal likelihood (Section 9.3). With H=Φ\mathbf{H} = \boldsymbol{\Phi} it is Bayesian linear regression (Section 5.4), in the function-space form of Example B.1. The matrix G\mathbf{G} is called the gain: it converts the surprise in the observation into a correction of the prior mean.

B.4 Products of Gaussian densities #

Multiplying two Gaussian densities over the same variable gives a Gaussian shape again, scaled by a constant. Write N(x; μ,Σ)\N(\vx;\, \vmu, \mSigma) for the Gaussian density with mean μ\vmu and covariance Σ\mSigma, evaluated at x\vx.

Theorem B.5 Product of two Gaussian densities
N(x; μ1,Σ1)  N(x; μ2,Σ2)=Z  N(x; μ,Σ),\N(\vx;\, \vmu_1, \mSigma_1)\;\N(\vx;\, \vmu_2, \mSigma_2) = Z\;\N(\vx;\, \vmu, \mSigma),
(B.12)

with Σ=(Σ1−1+Σ2−1)−1\mSigma = \left(\mSigma_1^{-1} + \mSigma_2^{-1}\right)^{-1}, μ=Σ(Σ1−1μ1+Σ2−1μ2)\vmu = \mSigma\left(\mSigma_1^{-1}\vmu_1 + \mSigma_2^{-1}\vmu_2\right), and Z=N(μ1; μ2, Σ1+Σ2)Z = \N(\vmu_1;\, \vmu_2,\, \mSigma_1 + \mSigma_2).

Proof

Read the product as a model. Let x∼N(μ1,Σ1)\vx \sim \N(\vmu_1, \mSigma_1) and y ∣ x∼N(x,Σ2)\vy \given \vx \sim \N(\vx, \mSigma_2).

  1. The joint density is p(x) p(y ∣ x)=N(x; μ1,Σ1) N(y; x,Σ2)p(\vx)\,p(\vy \given \vx) = \N(\vx;\, \vmu_1, \mSigma_1)\,\N(\vy;\, \vx, \mSigma_2). A Gaussian density depends on its argument and its mean only through their difference, so N(y; x,Σ2)=N(x; y,Σ2)\N(\vy;\, \vx, \mSigma_2) = \N(\vx;\, \vy, \mSigma_2). At y=μ2\vy = \vmu_2 the joint density is the left side of Equation (B.12).
  2. The same joint density factors the other way, as p(y) p(x ∣ y)p(\vy)\,p(\vx \given \vy). By Theorem B.4 with H=I\mathbf{H} = \mI, c=0\mathbf{c} = \mathbf{0}, and R=Σ2\mathbf{R} = \mSigma_2: p(y)=N(y; μ1,Σ1+Σ2)p(\vy) = \N(\vy;\, \vmu_1, \mSigma_1 + \mSigma_2), and p(x ∣ y)p(\vx \given \vy) is Gaussian with covariance Σ1−Σ1(Σ1+Σ2)−1Σ1\mSigma_1 - \mSigma_1(\mSigma_1 + \mSigma_2)^{-1}\mSigma_1 and mean μ1+Σ1(Σ1+Σ2)−1(y−μ1)\vmu_1 + \mSigma_1(\mSigma_1 + \mSigma_2)^{-1}(\vy - \vmu_1).
  3. At y=μ2\vy = \vmu_2, the first factor is the constant ZZ.
  4. By Equation (B.5) with Z=Σ1−1\mathbf{Z} = \mSigma_1^{-1}, U=V=I\mathbf{U} = \mathbf{V} = \mI, and W=Σ2−1\mW = \mSigma_2^{-1}, the covariance in step 2 equals (Σ1−1+Σ2−1)−1=Σ(\mSigma_1^{-1} + \mSigma_2^{-1})^{-1} = \mSigma.
  5. From step 4, ΣΣ1−1=I−Σ1(Σ1+Σ2)−1\mSigma\mSigma_1^{-1} = \mI - \mSigma_1(\mSigma_1 + \mSigma_2)^{-1}, and since Σ(Σ1−1+Σ2−1)=I\mSigma(\mSigma_1^{-1} + \mSigma_2^{-1}) = \mI, ΣΣ2−1=Σ1(Σ1+Σ2)−1\mSigma\mSigma_2^{-1} = \mSigma_1(\mSigma_1 + \mSigma_2)^{-1}. So the mean in step 2 at y=μ2\vy = \vmu_2 is ΣΣ1−1μ1+ΣΣ2−1μ2=μ\mSigma\mSigma_1^{-1}\vmu_1 + \mSigma\mSigma_2^{-1}\vmu_2 = \vmu.

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 ZZ 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.2 Two bumps in one variable

Section 7.2.1 needed the integral over cc of a product of two unnormalized bumps, e−(x−c)2/2s2 e−(x′−c)2/2s2e^{-(x - c)^2/2s^2}\,e^{-(x' - c)^2/2s^2}. As functions of cc, each bump is 2πs2\sqrt{2\pi s^2} times a Gaussian density with variance s2s^2, centered at xx and at x′x'. By Equation (B.12) the product is

2πs2⋅N(x; x′, 2s2)⋅N ⁣(c; x+x′2, s22).2\pi s^2 \cdot \N(x;\, x',\, 2s^2) \cdot \N\!\left(c;\, \tfrac{x + x'}{2},\, \tfrac{s^2}{2}\right).

The last factor integrates to 1 over cc, so the integral is 2πs2 N(x; x′,2s2)=sπ  e−(x−x′)2/4s22\pi s^2\,\N(x;\, x', 2s^2) = s\sqrt{\pi}\; e^{-(x - x')^2/4s^2}, the value found there by completing the square. The RBF kernel is the constant ZZ 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 ZZ 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.

B.5 The expected maximum of two Gaussians #

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.6 Expected maximum of two Gaussians

Let AA and BB be jointly Gaussian with means μA,μB\mu_A, \mu_B, variances vA,vBv_A, v_B, and covariance cc. Write δ=μA−μB\delta = \mu_A - \mu_B and s2=vA+vB−2cs^2 = v_A + v_B - 2c, the variance of A−BA - B. If s>0s > 0,

E[max⁡{A,B}]=μA Φ(α)+μB Φ(−α)+s ϕ(α),α=δ/s,\begin{aligned} \E[\max\{A, B\}] ={}& \mu_A\,\Phi(\alpha) + \mu_B\,\Phi(-\alpha) \\ &+ s\,\phi(\alpha), \qquad \alpha = \delta / s, \end{aligned}
(B.13)

where ϕ\phi and Φ\Phi are the standard normal density and distribution function. If s=0s = 0, the expectation is max⁡{μA,μB}\max\{\mu_A, \mu_B\}.

Proof
  1. For any two numbers, max⁡{A,B}=B+max⁡{A−B,0}\max\{A, B\} = B + \max\{A - B, 0\}.
  2. D=A−BD = A - B is a linear map of a Gaussian vector, so it is Gaussian (Equation (4.9)), with mean δ\delta and variance Var⁡[A]+Var⁡[B]−2Cov⁡[A,B]=s2\Var[A] + \Var[B] - 2\Cov[A, B] = s^2.
  3. If s>0s > 0, write D=δ+sZD = \delta + sZ with ZZ standard normal. Then max⁡{D,0}\max\{D, 0\} vanishes unless Z>−δ/sZ > -\delta/s, and E[max⁡{D,0}]=∫−δ/s∞(δ+sz) ϕ(z) dz\E[\max\{D, 0\}] = \int_{-\delta/s}^{\infty}(\delta + sz)\,\phi(z)\,\dd z. The first part is δ (1−Φ(−δ/s))=δ Φ(δ/s)\delta\,(1 - \Phi(-\delta/s)) = \delta\,\Phi(\delta/s). For the second, ϕ′(z)=−z ϕ(z)\phi'(z) = -z\,\phi(z), so z ϕ(z)z\,\phi(z) has antiderivative −ϕ(z)-\phi(z) and the integral of z ϕ(z)z\,\phi(z) from −δ/s-\delta/s to infinity is ϕ(−δ/s)=ϕ(δ/s)\phi(-\delta/s) = \phi(\delta/s). So E[max⁡{D,0}]=δ Φ(δ/s)+s ϕ(δ/s)\E[\max\{D, 0\}] = \delta\,\Phi(\delta/s) + s\,\phi(\delta/s).
  4. By linearity of expectation and step 1, E[max⁡{A,B}]=μB+δ Φ(δ/s)+s ϕ(δ/s)\E[\max\{A, B\}] = \mu_B + \delta\,\Phi(\delta/s) + s\,\phi(\delta/s). Since μB+δ Φ(δ/s)=μAΦ(δ/s)+μB(1−Φ(δ/s))\mu_B + \delta\,\Phi(\delta/s) = \mu_A\Phi(\delta/s) + \mu_B(1 - \Phi(\delta/s)) and 1−Φ(t)=Φ(−t)1 - \Phi(t) = \Phi(-t), this is Equation (B.13).
  5. If s=0s = 0, DD equals the constant δ\delta, and max⁡{A,B}=B+max⁡{δ,0}\max\{A, B\} = B + \max\{\delta, 0\} has expectation max⁡{μA,μB}\max\{\mu_A, \mu_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)\Phi(\delta/s) is the probability that AA exceeds BB, 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 ss. Four consequences are used in the book.

  • Never below the better mean. max⁡{D,0}≥D\max\{D, 0\} \ge D and max⁡{D,0}≥0\max\{D, 0\} \ge 0, so E[max⁡{D,0}]≥max⁡{δ,0}\E[\max\{D, 0\}] \ge \max\{\delta, 0\} and E[max⁡{A,B}]≥max⁡{μA,μB}\E[\max\{A, B\}] \ge \max\{\mu_A, \mu_B\}.
  • Increasing in ss. Differentiating step 3 with respect to ss, the terms from Φ\Phi and from ϕ′\phi' cancel and leave exactly ϕ(δ/s)>0\phi(\delta/s) > 0. More uncertainty about the difference is always worth more.
  • Correlation matters only through ss. Positive correlation between AA and BB lowers ss and with it the expected maximum; negative correlation raises it. Two options that rise and fall together offer little choice.
  • Equal means. With δ=0\delta = 0 the formula reduces to μ+s/2π\mu + s/\sqrt{2\pi}: the bonus is about 0.4 s0.4\,s.

The figure shows the whole distribution of the maximum, of which Equation (B.13) is the mean.

density of Adensity of Bdensity of max(A, B)0.00.20.40.60.8density−4−2024valuebetter meanE[max]E[max(A, B)] = 0.674 by Clark's formula, 0.674 by integrating the density · better mean 0.40 · bonus 0.274 · s = 1.12
density of Adensity of Bdensity of max(A, B)0.00.20.40.60.8density−4−2024valuebetter meanE[max]E[max(A, B)] = 0.674 (formula), 0.674 (integral)better mean 0.40 · bonus 0.274 · s = 1.12
Figure B.1 The maximum of two jointly Gaussian values. Thin curves: the densities of AA and BB. Shaded: the exact density of max⁡{A,B}\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πs/\sqrt{2\pi}: with standard deviations 1 and 0.5 and no correlation, s=1.12s = 1.12 and the bonus is 0.446.

Raise the correlation toward 0.95. The bonus shrinks, because ss 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-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 BB nearly constant, the shaded density is the density of AA with everything below BB swept up to BB. Its mean is μB\mu_B plus the expected improvement of AA over μB\mu_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 AA and BB 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 ss equal to the difference of their slopes in absolute value.

Sources cited in Section B.5 1
  1. Clark (1961) The Greatest of a Finite Set of Random Variables

B.6 Exercises #

Exercise B.1

Let 1\mathbf{1} be the vector of nn ones. Use Equation (B.6) to compute (σ2I+11⊤)−11(\sigma^2\mI + \mathbf{1}\mathbf{1}^\T)^{-1}\mathbf{1}, and from it the posterior variance at x0x_0 after nn noisy observations at x0x_0 under a unit-amplitude kernel, as in Exercise 8.2.

Solution

With Z=σ2I\mathbf{Z} = \sigma^2\mI and u=v=1\mathbf{u} = \mathbf{v} = \mathbf{1}, Z−11=1/σ2\mathbf{Z}^{-1}\mathbf{1} = \mathbf{1}/\sigma^2 and 1⊤Z−11=n/σ2\mathbf{1}^\T\mathbf{Z}^{-1}\mathbf{1} = n/\sigma^2. So

(σ2I+11⊤)−11=1σ2−1 (n/σ2)σ2 (1+n/σ2)=1σ2⋅11+n/σ2=1σ2+n.\begin{aligned} (\sigma^2\mI + \mathbf{1}\mathbf{1}^\T)^{-1}\mathbf{1} &= \frac{\mathbf{1}}{\sigma^2} - \frac{\mathbf{1}\,(n/\sigma^2)}{\sigma^2\,(1 + n/\sigma^2)} \\ &= \frac{\mathbf{1}}{\sigma^2}\cdot\frac{1}{1 + n/\sigma^2} = \frac{\mathbf{1}}{\sigma^2 + n}. \end{aligned}

All kernel values are 1, so K=11⊤\mK = \mathbf{1}\mathbf{1}^\T and k(x0)=1\vk(x_0) = \mathbf{1}, and the posterior variance of Equation (8.6) is 1−1⊤1/(σ2+n)=σ2/(σ2+n)1 - \mathbf{1}^\T\mathbf{1}/(\sigma^2 + n) = \sigma^2/(\sigma^2 + n).

Exercise B.2

Use Equation (B.7) to compute the determinant of σ2I+11⊤\sigma^2\mI + \mathbf{1}\mathbf{1}^\T for nn observations, and with it the complexity term −12log⁡∣Ky∣-\tfrac12\log\lvert\mK_y\rvert 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\mK_y = (1 + \sigma^2)\mI.

Solution

With Z=σ2I\mathbf{Z} = \sigma^2\mI, U=V=1\mathbf{U} = \mathbf{V} = \mathbf{1}, and W=1\mW = 1: det⁡(σ2I+11⊤)=σ2n (1+n/σ2)=σ2(n−1)(σ2+n)\det(\sigma^2\mI + \mathbf{1}\mathbf{1}^\T) = \sigma^{2n}\,(1 + n/\sigma^2) = \sigma^{2(n-1)}(\sigma^2 + n). The complexity term is −12[(n−1)log⁡σ2+log⁡(σ2+n)]-\tfrac12\left[(n - 1)\log\sigma^2 + \log(\sigma^2 + n)\right]. For small noise this is large and positive: with n=7n = 7 and σ=0.1\sigma = 0.1 it is −12[6×(−4.61)+1.95]=12.8-\tfrac12\left[6 \times (-4.61) + 1.95\right] = 12.8. At a very short lengthscale the determinant is (1+σ2)n(1 + \sigma^2)^n and the term is −n2log⁡(1+σ2)=−0.03-\tfrac{n}{2}\log(1 + \sigma^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 AA and BB be independent standard normal variables. (a) Use Equation (B.13) to find E[max⁡{A,B}]\E[\max\{A, B\}]. (b) Show that E[max⁡{A,B}2]=1\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\delta = 0 and s2=2s^2 = 2, so the expectation is s ϕ(0)=2/2π=1/π≈0.564s\,\phi(0) = \sqrt{2}/\sqrt{2\pi} = 1/\sqrt{\pi} \approx 0.564. (b) max⁡{A,B}2+min⁡{A,B}2=A2+B2\max\{A, B\}^2 + \min\{A, B\}^2 = A^2 + B^2, whose expectation is 2. The pair (−A,−B)(-A, -B) has the same distribution as (A,B)(A, B), and min⁡{A,B}=−max⁡{−A,−B}\min\{A, B\} = -\max\{-A, -B\}, so min⁡{A,B}2\min\{A, B\}^2 and max⁡{A,B}2\max\{A, B\}^2 have the same expectation, which must be 1. The variance is 1−1/π≈0.6821 - 1/\pi \approx 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.

Further reading #

  • Petersen and Pedersen (2012) is a free reference of matrix identities, including every one in this appendix and the derivative rules used in Section 9.4.1.
  • 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.

References

  1. Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer.
  2. Clark, C. E. (1961). The Greatest of a Finite Set of Random Variables. Operations Research. Cited in §B.5
  3. Golub, G. H., and Van Loan, C. F. (2013). Matrix Computations. Johns Hopkins University Press.
  4. Petersen, K. B., and Pedersen, M. S. (2012). The Matrix Cookbook. Technical University of Denmark. non-peer-reviewed
  5. Quiñonero-Candela, J., and Rasmussen, C. E. (2005). A Unifying View of Sparse Approximate Gaussian Process Regression. Journal of Machine Learning Research. Cited in §B.2
  6. Rasmussen, C. E., and Williams, C. K. I. (2006). Gaussian Processes for Machine Learning. MIT Press. Cited in §B.2