The Linear Algebra of Uncertainty
Section 2.6.3 introduced a table: the covariances between every pair of uncertain quantities, the covariance matrix. A Bayesian optimizer keeps such a table for the objective's values at every input it has evaluated and every input it is considering, so after 50 evaluations the table has 50 rows at the least. Each update of its belief, each prediction, and each fit of the model's own settings is a computation with that table. This chapter is about those computations.
Linear algebra is a large subject, and this chapter takes only the part that the rest of the book uses. It treats a matrix as a map that moves the points of space, because that picture explains the properties that matter: which tables can be covariance matrices, what shape a covariance gives a cloud of uncertainty, how to solve the equations of a Gaussian process without ever inverting a matrix, and what a determinant measures. Two-dimensional pictures carry most of the intuition, but a few facts appear only from three dimensions on, so the chapter also turns a three-dimensional covariance in your hands.
The payoff comes in the next chapter, Chapter 4, where every result here becomes a statement about the Gaussian distribution, and in Chapter 8, where those statements become an algorithm.
3.1 Vectors #
A vector is an ordered list of numbers. Bold lowercase letters name vectors, and by convention a vector is a column:
The symbol is the set of all such lists of real numbers, and is the vector's dimension. Writing , read " transpose", turns the column into a row.
Vectors appear in this book in two roles, and keeping them apart prevents a common confusion. In the first role a vector is a point in the space being searched: a configuration of hyperparameters, the settings of an exoskeleton, the parameters of a photo filter. Snoek et al. (2012), for instance, tuned nine settings of an image classifier's training procedure at once, so each configuration they tried was a vector in (Section 9.2 returns to what they found). In the second role a vector holds the values of the objective at a list of inputs, . Its dimension is the number of inputs, not the number of hyperparameters, and it grows with every evaluation. The covariance matrices of a Gaussian process live in this second space.
Vectors add entry by entry, and multiplying a vector by a number multiplies every entry. Geometrically, places the arrow of at the tip of the arrow of , and is the same arrow twice as long.
3.1.1 Inner products, lengths, and angles #
The inner product, or dot product, of two vectors of the same dimension multiplies them entry by entry and adds the results:
The notation reads as a row times a column, which is the rule for multiplying matrices introduced in Section 3.2. From the inner product come length and distance. The norm of a vector, its length, is , Pythagoras's theorem in dimensions, and the distance between two points is the norm of their difference, .
The inner product also measures angle. For any two vectors,
where is the angle between them. Two vectors are orthogonal, perpendicular, when their inner product is zero. Dividing by the two lengths gives , which is 1 for vectors pointing the same way, 0 for perpendicular ones, and for opposite ones. The correlation of Section 2.6.3 is this cosine, computed for centered random variables instead of lists of numbers.
Distance matters to Bayesian optimization because the most common kernels, the functions that decide how strongly the objective's values at two inputs are correlated (Chapter 9), depend on the inputs only through the distance between them. The RBF kernel, , says that nearby inputs have similar values and distant ones are unrelated, with the lengthscale setting what "nearby" means.
3.1.2 Distances in many dimensions #
Our intuition about distance comes from two and three dimensions, and it misleads in more. Scatter points uniformly at random in the unit cube . Each coordinate contributes on average to the squared distance between two points, so the typical distance grows like : about 0.58 in two dimensions, 1.0 in six, and 2.9 in fifty. The spread of the distances does not grow with it. In a simulation with 200 random points, the standard deviation of the pairwise distances stayed near 0.24 from two dimensions to a hundred. As a result, the ratio of each point's nearest neighbor distance to its farthest neighbor distance, which was 0.04 for a typical point in two dimensions, rose to 0.22 in six dimensions, 0.65 in fifty, and 0.74 in a hundred.
In many dimensions, then, every point is far from every other, and all of them are about equally far. A kernel with a lengthscale suited to a two-dimensional problem would declare every pair of points in a fifty-dimensional one unrelated, and the model would learn nothing from one evaluation about any other. This is one root of the difficulty of Bayesian optimization in many dimensions, and the remedies, such as lengthscales that grow with the dimension and a lengthscale for each input (Section 9.2), start from it (Chapter 30).
Sources cited in Section 3.1 1
- Snoek et al. (2012) Practical Bayesian Optimization of Machine Learning Algorithms
3.2 Matrices as transformations #
A matrix is a rectangular table of numbers, written with a bold capital. An matrix has rows and columns, and is the entry in row and column . The table is the matrix's storage format. Its meaning is the map it defines.
3.2.1 The product of a matrix and a vector #
Multiplying an matrix by a vector of dimension gives a vector of dimension , whose -th entry is the inner product of row with the vector:
The same product has a second reading, which is the one to picture. Write the columns of as . Then
The vector picks out the first column: . So the columns of a matrix record where it sends the coordinate directions, and Equation (3.2) says that every other vector goes where its coordinates say: as much of as had of , and so on.
A map of this kind is linear: it sends sums to sums and multiples to multiples, and . In the plane, a linear map sends straight lines to straight lines, keeps the origin in place, and turns a square grid into a grid of parallelograms. The unit circle, the set of vectors of length one, becomes an ellipse.
Some things to try:
- Drag the tip of . Only the first column changes, and the whole grid follows: every point moves by its first coordinate times the change.
- Choose the Rotation, Shear, and Stretch presets. A rotation turns the circle without changing its shape; a stretch scales the two axes by different amounts; a shear slides one axis along the other and turns the square into a slanted parallelogram of the same area.
- Choose Singular. The two columns point the same way, the ellipse collapses to a line segment, and the whole plane is flattened onto a line. Every point on that line came from infinitely many points, so the map cannot be undone.
3.2.2 Composition, identity, and inverse #
Applying and then is again a linear map, and its matrix is the product , whose columns are applied to the columns of . Entry by entry, , the inner product of row of with column of . Order matters: stretching and then rotating is not the same as rotating and then stretching, so in general . Multiplying two matrices this way takes multiplications, one for each combination of , , and .
The identity matrix , with ones on the diagonal and zeros elsewhere, leaves every vector where it is. A square matrix is invertible when another matrix undoes it, . A matrix is invertible exactly when it does not flatten space: when no nonzero vector is sent to zero, so no two points land on the same image. The Singular preset of Figure 3.1 is the opposite case. Inverting a product reverses the order, , since the last map applied must be the first one undone.
3.2.3 Transpose #
The transpose flips a matrix across its diagonal, so that and an matrix becomes . A column vector is an matrix, its transpose a row, and the inner product is the product of a row with a column. The reverse product , a column times a row, is an matrix called the outer product. Transposing a product also reverses the order, .
The shapes in Chapter 8 follow these rules. With observed inputs and inputs to predict at, the kernel matrix among observed inputs is , the matrix between observed and new inputs is , and the posterior mean multiplies an matrix, an matrix, and an -vector to give one prediction for each of the new inputs.
3.3 Symmetric and positive definite matrices #
Not every square table of numbers can be a covariance matrix. This section finds the condition, which turns out to be geometric: a covariance matrix must not let any direction have negative variance.
3.3.1 Quadratic forms #
A matrix is symmetric when it equals its transpose, . A covariance matrix is symmetric because , and so is a kernel matrix, because .
For a symmetric matrix , the expression is a single number for each vector , called a quadratic form. In two dimensions, with ,
a quadratic polynomial in the entries of . Quadratic forms appear whenever a covariance matrix meets a weighted sum, because of the following identity.
Let be a random vector with mean and covariance matrix , and let be a fixed vector of weights.
- The weighted sum is , with mean by linearity of expectation (Equation (2.10)).
- By the definition of variance (Equation (2.11)), .
- Expanding the square of the sum gives every pairwise product: .
- By linearity of expectation, this is , by the definition of covariance.
- The double sum is the quadratic form, so .
3.3.2 Every direction has nonnegative variance #
A variance cannot be negative. By the derivation, a covariance matrix must therefore satisfy for every . This property has a name.
A symmetric matrix is positive semidefinite if for every vector , and positive definite if for every nonzero .
Read with , positive definiteness says that every direction in the space has positive variance: no weighted combination of the variables is known exactly. A covariance matrix that is only semidefinite has some combination with zero variance, a combination that is fixed. That happens in a Gaussian process when two observed inputs coincide: the values and are then the same random variable, and is exactly zero. Every result below assumes the strict version, which is why implementations add a little noise or "jitter" to the diagonal (Section 8.4).
In two dimensions the condition is easy to check. A covariance matrix with standard deviations and correlation is positive definite exactly when and , and every correlation in that range is possible. From three dimensions on, this is no longer enough.
3.3.3 Three correlations that cannot coexist #
Suppose three quantities each have variance 1, the first is correlated with the second and with the third, and the second and third are uncorrelated:
Each correlation is between and , and each pair on its own is a valid two-dimensional covariance. Yet the weights give
a negative variance for the quantity . No three random variables have these correlations. Intuitively, if moves closely with and closely with , then and must move together to some extent; they cannot be unrelated. Exercise 3.2 finds how strongly they must be correlated.
This is not a curiosity. In finance, tables of correlations between many assets can fail to be positive semidefinite, and the problem of repairing such a table into the nearest valid correlation matrix has a literature of its own (Higham, 2002). For a Gaussian process it is the reason a kernel cannot be an arbitrary similarity score. A natural-looking rule such as "two inputs are fully correlated if they are closer than 1 and uncorrelated otherwise" fails on the inputs , , and : the first two are fully correlated, the last two are fully correlated, and the first and last are uncorrelated, an impossible triple of the same kind. The kernels of Chapter 9 are built so that this can never happen: a valid kernel is one whose matrices are positive semidefinite for every choice of inputs, and no other function is (Section 7.2).
Figure 3.2 in the next section lets you try to build such a matrix and see what goes wrong.
Sources cited in Section 3.3 1
- Higham (2002) Computing the Nearest Correlation Matrix: A Problem from Finance
3.4 Eigenvectors: the axes a matrix stretches #
The entries of a matrix say little at a glance about what it does. In Figure 3.1, most vectors are both turned and stretched by . Some directions, though, are only stretched: the image points along itself. If we could find those directions, we could describe the map as a set of independent stretches.
A nonzero vector is an eigenvector of a square matrix , with eigenvalue , if .
An eigenvector is a direction the matrix does not turn; its eigenvalue is the factor by which the direction is stretched, and a negative eigenvalue reverses it. In Figure 3.1, drag around the circle until and line up, and the readout reports the eigenvalue. For the default matrix this happens near , with eigenvalue 1.4, and near , with eigenvalue 0.6. Turn on Show eigenvectors to see both directions. The Rotation preset has no real eigenvectors at all, because it turns every direction.
3.4.1 Symmetric matrices #
For a general matrix the eigenvectors need not be perpendicular, as the default matrix shows. Symmetric matrices, the only kind a covariance can be, are much better behaved.
A symmetric matrix has real eigenvalues and an orthonormal set of eigenvectors : unit vectors that are pairwise perpendicular. Collecting the eigenvectors as the columns of a matrix and the eigenvalues on the diagonal of a matrix ,
The proof that the eigenvalues are real takes more space than it deserves here (Strang, 2016), but the perpendicularity is short.
Let and with .
- Multiply the first equation on the left by : .
- Transpose the left side, a single number, which leaves it unchanged: , using .
- By the second equation, .
- So , and since , .
- Because , .
The decomposition reads from right to left as a recipe. turns space so that the eigenvectors line up with the coordinate axes, stretches each axis by its eigenvalue, and turns space back. A symmetric matrix is a set of perpendicular stretches, nothing more. Choose the Symmetric preset in Figure 3.1 and turn on the eigenvectors: they are perpendicular, and they are the axes of the ellipse.
3.4.2 Eigenvalues and positive definiteness #
The spectral theorem turns the definition of positive definiteness into a condition on the eigenvalues.
Let be symmetric, and let be any vector.
- Substitute the decomposition: .
- Write , the coordinates of along the eigenvectors, . Then .
- If every , the sum is positive whenever some , which holds for every nonzero because is invertible.
- Conversely, choosing gives and every other , so , which must be positive.
For a covariance matrix the derivation says more. Take of length one, a direction. Its coordinates along the eigenvectors then satisfy , so the variance in direction is a weighted average of the eigenvalues, with weights . The eigenvalues are the variances along the eigenvectors, and every other direction's variance lies between the smallest and the largest. The eigenvector with the largest eigenvalue is the direction in which the uncertainty is widest. The shape of the uncertainty is an ellipsoid whose axes point along the eigenvectors, with half-lengths (the standard deviations along the axes), which Section 4.2.1 derives for the Gaussian.
3.4.3 A covariance in three dimensions #
In two dimensions the ellipse summarizes everything. In three, two things appear that the plane cannot show. Figure 3.2 draws the ellipsoid of a three-dimensional covariance, , the set of points one standard deviation from the center in the sense that Section 4.2.1 makes precise, together with its three axes and its shadows on the walls of the cube. Beside it are the three pairwise views, the ellipses of the blocks of that involve two of the three coordinates.
Some things to try:
- Turn the cube. The ellipsoid has three perpendicular axes, the eigenvectors, and from most angles none of them is aligned with a coordinate axis. The readout lists the eigenvalues; their square roots are the axes' half-lengths.
- Compare the shadows with the pairwise views. They are the same ellipses. The shadow of a covariance's ellipsoid on the plane of two coordinates is the ellipse of the corresponding block, which is why ignoring a variable of a Gaussian amounts to deleting its row and column (Section 4.4).
- Press An impossible triple. The pairwise views show three valid ellipses, with correlations 0.8, 0.8, and 0. The ellipsoid vanishes, and the red dashed line marks the direction whose variance would be negative, the eigenvector of the eigenvalue . Now raise slowly: the ellipsoid reappears once passes 0.28 (at 0.29 on the slider), as a flat disk that thickens as grows.
- Press A chain. Here is linked to , and to , with correlation 0.8 each, and is the product of the two. The ellipsoid becomes a cigar along the diagonal, with one eigenvalue much larger than the others: most of the uncertainty lies along a single direction.
The first lesson is that pairwise checks do not certify a covariance matrix; its validity is a property of the whole table. The second is that a covariance can be nearly flat in a direction that no single variable reveals: none of the pairwise views of a nearly singular matrix need look degenerate.
3.4.4 The eigenvalues of a kernel matrix #
That second lesson is the everyday situation of a Gaussian process. The kernel matrix of 100 inputs spaced evenly in , under an RBF kernel with lengthscale 0.1, is a positive definite matrix in exact arithmetic. Its largest eigenvalues are 23.9, 21.2, and 17.5, but they decay so quickly that only 28 of the 100 exceed . In double-precision arithmetic the smallest ones are lost in rounding error; in our run with NumPy the smallest computed eigenvalue even came out slightly negative, . The function values at nearby inputs are so strongly correlated that most directions in the 100-dimensional space have almost no variance. In the same run, NumPy's Cholesky factorization of this matrix failed; adding to the diagonal, the jitter of Section 8.4, makes it succeed. A smooth prior over functions has, in effect, far fewer than 100 independent directions of uncertainty, which is part of why a Gaussian process can learn a smooth function from a few evaluations.
The ratio of the largest to the smallest eigenvalue, the condition number, measures how close to singular a matrix is. Double-precision numbers carry about 16 significant decimal digits, and solving a system with a matrix of condition number can lose about of them (Golub and Van Loan, 2013). Kernel matrices of smooth kernels on closely spaced inputs routinely reach condition numbers near , where no digits remain, so jitter or observation noise is a numerical necessity, not a modeling choice.
Eigenvalues of exactly zero carry information too. In Section 18.5, the eigenvalues of a matrix built from a set of pairwise comparisons count the directions in which the comparisons say nothing at all about a person's preferences.
Sources cited in Section 3.4 2
- Strang (2016) Introduction to Linear Algebra
- Golub and Van Loan (2013) Matrix Computations
3.5 Solving systems without inverting #
The formulas of Gaussian process regression are full of inverse matrices: the posterior mean and the variance of Equation (8.3). Read literally, they say: invert , then multiply. Numerical practice says never to do that. This section explains why, and what to do instead.
3.5.1 Why not invert #
A formula containing never needs itself. It needs the vector that solves the linear system . Two reasons favor solving over inverting. Forming the inverse costs more, several times as much as the factorization used below. And the computed inverse is less accurate: multiplying by a rounded inverse loses more digits than solving directly with a factorization (Golub and Van Loan, 2013). When the matrix is badly conditioned, as kernel matrices often are, the difference decides whether the answer is usable.
3.5.2 Triangular systems #
Some systems are easy. A matrix is lower triangular when every entry above the diagonal is zero. The system with such a matrix can be solved one entry at a time, top to bottom: the first equation involves only , the second only and , and so on.
This forward substitution costs about operations, against for general methods. An upper triangular system, with zeros below the diagonal, is solved the same way from the bottom up, by back substitution. The whole strategy for symmetric positive definite systems is to reduce them to two triangular ones.
3.5.3 The Cholesky factorization #
Every symmetric positive definite matrix can be written uniquely as
where is lower triangular with positive diagonal entries. is the Cholesky factor of .
The factor is a square root of the matrix. For a matrix it is , which exists exactly when . The case shows how the general algorithm works and why it needs positive definiteness.
Let and look for .
- Multiplying out, .
- Match the top-left entry: , so , which needs .
- Match the off-diagonal entry: , so .
- Match the bottom-right entry: , so , which needs .
- Both conditions hold exactly when is positive definite: is the variance in direction , and is the determinant, the product of the two eigenvalues (Section 3.6).
The quantity in step 4 is a first glimpse of the Schur complement of Section 3.7. For a covariance matrix with , , and , it equals : the variance of the second variable that remains once the first is known, as Section 4.5 will show.
The general algorithm fills in one column at a time, in the same way.
Input: a symmetric matrix .
- For each column :
- Compute . If , stop: is not positive definite.
- Set .
- For each row , set .
Step 2 makes the algorithm a test as well as a factorization: it succeeds exactly when the matrix is positive definite, and it is the cheapest such test in practice. In Figure 3.2, the impossible triple fails at the third column, where comes out negative. The algorithm costs about floating-point operations (Golub and Van Loan, 2013).
3.5.4 Solving with the factor #
With , the system splits into two triangular systems. First solve by forward substitution, then by back substitution. Then , as required. Once is known, each new right-hand side costs only . This is Algorithm 8.1: one factorization of the kernel matrix, then triangular solves for the weights and for each predictive variance.
import numpy as np
from scipy.linalg import cho_factor, cho_solve, solve_triangular
A = np.array([[4.0, 2.0], [2.0, 3.0]])
b = np.array([2.0, 4.0])
L = np.linalg.cholesky(A) # lower triangular, L @ L.T == A
z = solve_triangular(L, b, lower=True) # forward substitution
x = solve_triangular(L.T, z, lower=False) # back substitution
print(x) # [-0.25 1.5 ]
c = cho_factor(A) # the same, packaged
print(cho_solve(c, b)) # [-0.25 1.5 ]
3.5.5 The cost, in practice #
The cubic cost decides how many observations an exact Gaussian process can handle. Table 3.1 gives timings measured with NumPy in double precision on the laptop used to prepare this chapter (an Apple M5 Pro); other machines will differ, but the growth rate will not.
| Cholesky | Inverse | Memory | |
|---|---|---|---|
| 500 | 0.4 ms | 2.3 ms | 2 MB |
| 1,000 | 2.0 ms | 10 ms | 8 MB |
| 2,000 | 14 ms | 82 ms | 32 MB |
| 4,000 | 132 ms | 625 ms | 128 MB |
Doubling multiplies the time by roughly eight, as predicts, and the inverse costs about five times the factorization. A Bayesian optimization run rarely has more than a few hundred observations, so a single factorization is cheap. Fitting the kernel's own settings, such as its lengthscale, is what multiplies the cost, because every step of that fit refactorizes the matrix (Section 9.3). For larger data sets, the library GPyTorch replaces the factorization by conjugate gradients, an iterative method that needs only products of the kernel matrix with vectors, and runs them on graphics processors; its authors report that this reduces the asymptotic cost of exact inference from to (Gardner et al., 2018).
3.5.6 The square root that makes samples #
The Cholesky factor is also a recipe for building correlated randomness out of independent randomness. If has independent coordinates with variance 1, then has covariance , a consequence of the rule that Section 4.3 derives. Turn on Show samples in Figure 3.2 to see 160 such points: each is for a draw of three independent random numbers with mean 0 and variance 1 (standard normal numbers, the bell curve of Section 4.1.1), and together they fill the ellipsoid's shape. Because is lower triangular, the first coordinate uses only , the second and , and the third all three, so each new coordinate is built from the randomness of the earlier ones plus a fresh part of its own. This is how the posterior samples of Section 8.5 are drawn.
Sources cited in Section 3.5 2
- Golub and Van Loan (2013) Matrix Computations
- Gardner et al. (2018) GPyTorch: Blackbox Matrix-Matrix Gaussian Process Inference with GPU Acceleration
3.6 Determinants as volume #
The density of a multivariate Gaussian (Section 4.2) and the marginal likelihood used to fit kernels (Section 9.3) both contain a determinant. Its meaning is geometric.
The determinant of a square matrix, or , is the factor by which the map multiplies areas in two dimensions, volumes in three, and -dimensional volumes in general. Its sign records whether the map flips orientation, as a mirror does. For a matrix,
the signed area of the parallelogram spanned by the two columns. This is the yellow parallelogram in Figure 3.1, the image of the unit square; the Singular preset flattens it to zero area, and the Reflection preset turns the determinant negative.
Three properties follow from the picture. Applying two maps multiplies their volume factors, so , and in particular . A matrix is invertible exactly when its determinant is nonzero, when it does not flatten space. And for a symmetric matrix , the rotations and preserve volume while stretches axis by , so
For a covariance matrix the determinant is therefore a single number for the overall size of the uncertainty, sometimes called the generalized variance. The ellipsoid of Figure 3.2 has half-axes and so volume . Correlation shrinks it: for three variables with unit variance and correlations ,
which falls from 1 for independent variables toward 0 as the ellipsoid flattens, and becomes negative for the impossible triple (). In Section 6.5, a determinant of this kind measures how much a set of evaluations can teach about the objective, and the evaluations that make it largest are the most informative.
3.6.1 The log-determinant from the Cholesky factor #
The determinant of a triangular matrix is the product of its diagonal entries. (In the formula, with is . In general, a triangular matrix stretches coordinate axis by its -th diagonal entry and then shears, and a shear moves points parallel to the other axes without changing any volume, as the Shear preset of Figure 3.1 shows.) With , the product rule for determinants gives
The logarithm is not decoration. A kernel matrix with many tiny eigenvalues has a determinant far below the smallest positive double-precision number, about . For the 100-input example of Section 3.4.4, with the jitter that makes it factorizable, the product of the computed eigenvalues underflows to zero, while Equation (3.6) gives , a moderate number that costs nothing once the factor is known. Every implementation of the Gaussian log density and of the log marginal likelihood computes the determinant this way (Section 4.7).
3.7 Block matrices and the Schur complement #
A Gaussian process works with two groups of variables at once: the function values already observed and those to be predicted. Its matrices are therefore naturally split into blocks, as in Equation (8.1). This section develops the algebra of such blocks and ends with the one formula Section 4.5 needs.
3.7.1 Partitioned matrices #
A symmetric matrix partitioned into blocks looks like
where is , is , and is . Blocks multiply like numbers, with the rule that the order of each product is kept, since matrices do not commute. For a covariance, and are the covariances within each group and holds the covariances across groups.
3.7.2 Elimination by blocks #
Solving two equations in two unknowns by hand, we use the first equation to eliminate the first unknown from the second. The same step with blocks produces the central object of this section.
For the partitioned matrix Equation (3.7) with invertible, the Schur complement of is
For a matrix with entries , the Schur complement of is the number from the Cholesky derivation. In general it is what remains of after the part explained by the first group is removed.
- Subtract times the first block row from the second. As a matrix product, with , , because the bottom-right block becomes .
- Do the same to the columns: multiplying on the right by clears the top-right block, and since is symmetric, .
- is invertible: its inverse is the same matrix with the sign of the off-diagonal block flipped. So .
Three consequences follow, each used later in the book.
Determinants. is block triangular with identity blocks on the diagonal, so its determinant is 1 and .
Positive definiteness. For any vector , set ; then , where and are the two parts of . So is positive definite exactly when both and its Schur complement are. This is the precise version of the impossible triple: once is accounted for, what is left of and must still be a valid covariance (Exercise 3.2).
The inverse. Inverting step 3 block by block, using , gives , and multiplying out,
The bottom-right block of the inverse is the inverse of the Schur complement. Section 4.5 uses this, with the covariance of the observed values and that of the unobserved ones, to show that the covariance after conditioning is the Schur complement: , the prior covariance minus the part the observations explain. Section 8.1 is the same formula with kernel matrices in the blocks, and Section B.1 and Section B.2 collect it with related identities (Petersen and Pedersen, 2012).
3.7.3 Adding one observation #
The block view also says how to update a Cholesky factor cheaply, which a Bayesian optimizer needs after every evaluation. Suppose for the inputs observed so far, and a new input arrives with covariances to the old inputs and variance . The new kernel matrix and its factor have the block forms
Matching blocks, , one forward substitution costing , and . Since , the new diagonal entry squared is , the Schur complement of , which is also the Gaussian process's posterior variance at the new input (Equation (8.3)). Growing the factor by one row costs instead of the of starting over, as long as the kernel's settings stay fixed. And if the new input repeats an old one without observation noise, is zero and the factorization breaks: the matrix has become singular, for the reason given in Section 3.3.2.
Sources cited in Section 3.7 1
- Petersen and Pedersen (2012) The Matrix Cookbook
3.8 Exercises #
Let . (a) Compute its Cholesky factor by hand. (b) Use it to find and check with . (c) Solve by forward and back substitution.
Solution
(a) By the derivation, , , and , so .
(b) , and .
(c) Forward: and . Back, with : and . Check: and . These are the numbers the code sketch in Section 3.5.4 prints.
Three variables have unit variances, and . Using the Schur complement of the first variable, find every value of for which the covariance matrix is positive definite. Interpret the Schur complement.
Solution
Partition with , , and . Then
Since is positive definite, the whole matrix is positive definite exactly when is, which for a matrix with positive diagonal means , so and . This is where the ellipsoid of Figure 3.2 reappears. is the covariance of and after the part explained by is removed (Section 4.5): each keeps variance , and their remaining covariance must be a valid one, at most 0.36 in absolute value.
Two inputs have kernel value , so their kernel matrix is . Find its eigenvalues and eigenvectors, and its condition number. How many decimal digits can solving with lose when , as for two inputs very close together under a smooth kernel?
Solution
and , so the eigenvalues are with eigenvectors (the average of the two values) and (their difference). The condition number is , which for is , so about four of the sixteen digits can be lost. The small eigenvalue is the prior variance of the difference between the two function values: two close inputs leave almost no room for their values to differ, and that is the direction in which the matrix is nearly singular.
In Section 3.7.3, suppose the observations are noisy, so the matrix to factor is . What is the new diagonal entry now? Show that it can no longer be zero, even when the new input repeats an old one.
Solution
The new matrix has in the corner and in the old block, so . The quantity is the noisy posterior variance of at the new input, of Equation (8.6), so , the variance of a new noisy measurement there. Because , : observation noise keeps the matrix positive definite, which is why noisy models rarely need jitter.
Further reading #
- Strang (2016) is a patient introduction to matrices as maps, eigenvalues, and positive definite matrices, with the geometric emphasis of this chapter.
- Golub and Van Loan (2013) is the standard reference for how these computations are done in floating point: triangular systems, the Cholesky factorization, operation counts, and conditioning.
- Rasmussen and Williams (2006), appendix A, collects the matrix identities and the Cholesky-based computations that Gaussian process regression uses.
- Petersen and Pedersen (2012) is a compact catalog of identities, including the block inverse and determinant formulas, useful for checking a derivation.
- Sanderson (2016) is an animated video series that shows matrices acting on the plane and in space, the picture behind Figure 3.1.
- Higham (2002) treats the problem of repairing an invalid correlation matrix, the practical side of Section 3.3.3.
References
- (2018). GPyTorch: Blackbox Matrix-Matrix Gaussian Process Inference with GPU Acceleration. Advances in Neural Information Processing Systems 31 (NeurIPS 2018). Cited in §3.5
- (2013). Matrix Computations. Johns Hopkins University Press. Cited in §3.4 §3.5
- (2002). Computing the Nearest Correlation Matrix: A Problem from Finance. IMA Journal of Numerical Analysis. Cited in §3.3
- (2012). The Matrix Cookbook. Technical University of Denmark. non-peer-reviewed Cited in §3.7
- (2006). Gaussian Processes for Machine Learning. MIT Press.
- (2016). Essence of Linear Algebra. Video series, 3Blue1Brown. non-peer-reviewed
- (2012). Practical Bayesian Optimization of Machine Learning Algorithms. Advances in Neural Information Processing Systems 25 (NeurIPS 2012). Cited in §3.1
- (2016). Introduction to Linear Algebra. Wellesley-Cambridge Press. Cited in §3.4