Linear Algebra for Machine Learning
Inner products, orthogonal projection, the spectral theorem, the SVD and the matrix norms that every later bound is written in.
Everything later in this laboratory is written in the language of this page. A concentration inequality for random matrices is a statement about ; a convergence rate for gradient descent is a statement about and ; the kernel trick is a statement about Gram matrices; attention is a statement about the geometry of inner products. This page fixes notation and proves the five or six facts that get used without comment from here on.
Inner products, norms and orthogonality
We work in with the standard inner product and the Euclidean norm .
For the norm is , and . Each satisfies
- , with only for (positivity),
- (homogeneity),
- (triangle inequality).
Only comes from an inner product, which is why the Euclidean norm is the one with a geometry — angles, projections, orthogonality — attached to it.
For all ,
with equality if and only if and are linearly dependent.
The Cauchy–Schwarz inequality is what lets us define the angle between non-zero vectors through . Two vectors are orthogonal when . A set is orthonormal when .
Orthogonal projection
Let be a subspace with orthonormal basis , and let . Then for every :
- and ;
- the decomposition into a -component and a -component is unique;
- , and ;
- , and unless .
Key idea
Least squares is orthogonal projection. The normal equations of linear regression say exactly that the residual is orthogonal to the column space of the design matrix; the geometry of this theorem is the whole derivation.
The spectral theorem
Write for the set of real symmetric matrices.
Let . Then there exist real numbers and an orthonormal basis of with . Equivalently with orthogonal and , equivalently .
For and define the Rayleigh quotient . Then
and more generally (the Courant–Fischer min–max characterisation).
Positive semidefinite matrices and quadratic forms
is positive semidefinite (PSD), written , if for all , and positive definite (PD), written , if for all . We write for ; this is the Loewner order, a partial order — not every pair of symmetric matrices is comparable.
For the following are equivalent:
- for all ;
- every eigenvalue of is non-negative;
- for some matrix ;
- for some , and orthonormal .
Statement (3) is why PSD matrices are unavoidable in learning theory: every Gram matrix is of the form and therefore PSD, and conversely every PSD matrix is a Gram matrix of some feature map. That equivalence is Mercer's condition in miniature.
For with spectral decomposition , the matrix is the unique PSD matrix with . If it also has a unique factorisation with lower triangular and positive diagonal (the Cholesky factor), computable in flops — which is how every "solve " in this laboratory is actually executed.
The singular value decomposition
Every can be written
where , and are orthogonal, and is zero off the diagonal with .
Matrix norms
The first is the spectral (operator) norm, the second the Frobenius norm, the third the nuclear norm. All three are functions of the singular values alone, hence invariant under for orthogonal .
The inequalities
follow at once from and Cauchy–Schwarz on the vector of singular values. They matter because the statistically natural norm is often while the analytically tractable one is , and the conversion costs a — a factor that is harmless for low-rank objects and fatal for full-rank ones in high dimension.
Let be the rank- truncation of the SVD. Then for every matrix of rank at most ,
This theorem is the reason principal component analysis is what it is: PCA is the Frobenius-optimal low-rank approximation of the centred data matrix, and nothing more.
Matrix calculus in one line each
The derivative conventions used throughout the optimisation pages are collected on the matrix calculus page. The three identities used most often are
Problems
Equality in Cauchy–SchwarzProof · Beginner · 15 min Characterising orthogonal projectorsProof · Intermediate · 30 min Schur complement and block positive semidefinitenessProof · Advanced · 30 min Bounding the spectral norm by row and column sumsProof · Intermediate · 30 min Implement power iteration and verify the convergence rateCoding · Intermediate · 1 hourReferences
- BookRoger A. Horn and Charles R. Johnson (2012). Matrix AnalysisThe standard reference for everything on this page, in far greater generality.
- BookLloyd N. Trefethen and David Bau III (1997). Numerical Linear AlgebraExcellent on the SVD and on conditioning.
- BookStephen Boyd and Lieven Vandenberghe (2004). Convex OptimizationAppendix A collects the linear algebra used throughout optimisation.
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- TheoremCauchy–Schwarz inequalityproof includedThe inner product of two vectors is bounded by the product of their norms, with equality exactly for parallel vectors.
- TheoremOrthogonal projection onto a subspaceproof includedEvery vector decomposes uniquely into a component in a subspace and a component orthogonal to it, and the subspace component is the nearest point.
- TheoremSpectral theorem for real symmetric matricesproof includedA real symmetric matrix has an orthonormal eigenbasis and real eigenvalues.
- PropositionRayleigh quotient characterisation of eigenvaluesproof includedThe extreme eigenvalues of a symmetric matrix are the extreme values of the Rayleigh quotient.
- TheoremSingular value decompositionproof includedEvery real matrix factors as a rotation, a non-negative scaling and another rotation.
- TheoremEckart–Young–Mirsky theoremTruncating the SVD gives the best low-rank approximation in both the spectral and the Frobenius norm.
- PropositionCharacterisations of positive semidefinitenessproof includedFour equivalent descriptions of a PSD matrix, each of which is the convenient one somewhere later.
Problems (5)
All problems- Equality in Cauchy–SchwarzProofBeginner⏱ 15 min
- Implement power iteration and verify the convergence rateCodingIntermediate⏱ 1 hour
- Characterising orthogonal projectorsProofIntermediate⏱ 30 min
- Schur complement and block positive semidefinitenessProofAdvanced⏱ 30 min
- Bounding the spectral norm by row and column sumsProofIntermediate⏱ 30 min