Contents / Linear Algebra / The Singular Value Decomposition
Chapter 12
The Singular Value Decomposition
Singular values, the SVD, the pseudoinverse, low-rank approximation, and principal component analysis.
Introduction
Diagonalisation is a beautiful theory with an awkward restriction: it only applies to square matrices, and even then only to those with enough eigenvectors. A matrix has no eigenvalues at all, because cannot even be written down when input and output live in different spaces. Yet rectangular matrices are the ones that carry data — rows are patients, customers or pixels, columns are measurements — and we would like to know their structure too.
The singular value decomposition supplies it. Every real matrix, of every shape and every rank, factors as
with and orthogonal and diagonal and nonnegative. There is no hypothesis to check. The price is that we give up on one basis doing both jobs: instead of , we get , an orthonormal basis in the domain sent to an orthonormal basis in the codomain, with a stretch factor attached to each pair.
That single factorisation answers an implausible number of questions. It reads off the rank, bases for all four fundamental subspaces, the two most used matrix norms, the sensitivity of to error, the best low-rank approximation of , the inverse of a matrix that has no inverse, and the principal components of a dataset. This chapter proves each of these from the same factorisation, which is the point: the SVD is not a collection of tricks but one structural fact with many consequences.
We assume the Spectral Theorem for real symmetric matrices — every symmetric has an orthonormal basis of eigenvectors with real eigenvalues, — from the chapter on symmetric matrices. Everything else is built here.
12.1Singular values and the geometry of a matrix
An eigenvalue asks which vectors a matrix leaves pointing where they were. A singular value asks a blunter question: how much can this matrix stretch a vector? That question makes sense for any shape, and it has a clean answer.
The device that makes it work is the matrix . If is then is , square no matter what looked like, and it is symmetric. Better still, it is positive semidefinite, so its eigenvalues are real and nonnegative and their square roots are honest real numbers.
Proposition 12.1 (The Gram matrix is symmetric positive semidefinite). For any real matrix , the matrix is symmetric, and for every . Consequently every eigenvalue of is real and nonnegative.
Proof. Symmetry: .
Semidefiniteness: for any ,
Now let be an eigenvalue with unit eigenvector . Because is real symmetric, the Spectral Theorem gives . Multiplying on the left by gives
so .∎
The last line of that proof is worth isolating, because it is the whole reason is the right object: the eigenvalue of at a unit eigenvector is exactly the squared length of . The eigenvalues of are not an algebraic accident; they are the squared stretch factors of itself, already sorted into perpendicular directions by the Spectral Theorem.
Definition 12.2 (Singular values). Let be a real matrix and let be the eigenvalues of , listed with multiplicity in decreasing order. The singular values of are
so that . A unit eigenvector of for is a right singular vector.
By the identity above, : the -th singular value is the length of the image of the -th right singular vector. So an matrix has singular values, one for each input direction, and they are the lengths produces along a well-chosen orthonormal frame in the domain.
Example 12.3 (Singular values of a diagonal matrix). Find the singular values of .
Solution. Compute .
Its eigenvalues are and , so and .
Note that the eigenvalues of are and , and the singular values are and : the absolute values, reordered. Sanity check: stretches the -axis by and flips it, and a singular value records only the amount of stretching, never the direction.□
Example 12.4 (Singular values of a matrix). Find the singular values of .
Solution. Here , , so is and there are two singular values.
Trace and determinant give the characteristic polynomial , so , and
Sanity check: , which is also the sum of the squares of all six entries of . That identity is proved later as the Frobenius norm formula, and it is the cheapest arithmetic check available on any set of singular values.□
Why should rather than be the object of study? It is a matter of which side you stand on. is and lives in the domain; is and lives in the codomain. They have the same nonzero eigenvalues, so either one produces the singular values, and in practice you diagonalise whichever is smaller.
Proposition 12.5 ( and share their nonzero eigenvalues). If is an eigenvalue of with eigenvector , then is an eigenvalue of with eigenvector , and conversely. The nonzero eigenvalues of and of agree, with multiplicity.
Proof. Suppose with and . Then , because . Multiply on the left by :
so is an eigenvector of for . Exchanging the roles of and gives the converse. The map is injective on each -eigenspace of (again because ), and its inverse is , so the eigenspaces have equal dimension.∎
Now the geometric fact the whole chapter rests on. A linear map cannot bend anything, so the image of a sphere ought to be some kind of stretched sphere. The singular values say exactly how stretched.
Theorem 12.6 (A matrix maps the unit sphere to an ellipsoid). Let be with singular values and orthonormal right singular vectors . If every , then the image of the unit sphere under is an ellipsoid in whose semi-axes have lengths and point along the mutually orthogonal directions . If some , the image is a flat (degenerate) ellipsoid inside the subspace spanned by the directions with .
Proof. The vectors form an orthonormal basis of , so any with can be written with .
Set for each with . These are orthonormal:
Then
Write for the coordinates of in the orthonormal frame . The constraint becomes
which is precisely the equation of an ellipsoid with semi-axes along the axes . Conversely every point satisfying that equation is for the unit vector , so the image is the whole ellipsoid. If some then identically and the ellipsoid is flattened to zero thickness in that direction.∎
Intuition. Take a circular pizza dough of radius and roll it once with a rolling pin. It becomes an ellipse. It does not become a square, a crescent or a figure eight — a linear map has no way to produce those. The longest radius of the resulting ellipse is , the shortest is , and the directions you had to push in the dough to produce them are and , which were perpendicular before you started and whose images are perpendicular after. Everything the SVD says is bookkeeping about that picture: turns the dough so the pushing directions line up with the axes, rolls along the axes, turns the result to where it belongs.
Example 12.7 (The ellipse of a matrix). Describe the image of the unit circle under .
Solution.
Trace , determinant , so and , . Hence and .
For : forces , giving . For : , giving .
So the unit circle maps to an ellipse with semi-axes and . The long axis lies along and the short axis along .
Sanity check: the area of the image ellipse is , and the area of the unit circle scaled by is also . For a square matrix, always, because .□
Example 12.8 (A matrix that flattens the circle). What does do to the unit circle?
Solution.
Trace , determinant , so the eigenvalues are and : , .
The image is therefore a degenerate ellipse — a line segment. The eigenvector for is found from , i.e. : . Its image is , of length as promised. The unit circle collapses onto the segment of the line running from to .
Sanity check: , and agrees.□
Pitfall. Singular values are not the absolute values of the eigenvalues, except when is symmetric. For the eigenvalues are , but has eigenvalues , giving and . A matrix with both eigenvalues equal to can still stretch some directions by a factor of five: eigenvalues see only the invariant directions, singular values see all of them.
Proposition 12.9 (Singular values of a symmetric matrix). If is real symmetric with eigenvalues , then the singular values of are , sorted downward.
Proof. Write with orthogonal and . Then
so the eigenvalues of are and the singular values are .∎
12.2The singular value decomposition
Everything needed for the factorisation is already in hand. The proof of the ellipsoid theorem manufactured orthonormal vectors out of thin air; collecting the identities into matrix form is the theorem.
Theorem 12.10 (Singular value decomposition). Let be any real matrix of rank . Then there exist an orthogonal matrix , an orthogonal matrix , and an matrix whose only nonzero entries are for , with
such that
The numbers are the nonzero singular values of , and .
Proof. Because is real symmetric, the Spectral Theorem provides an orthonormal basis of with and (nonnegative by the Gram matrix proposition). Let be the number of strictly positive and put .
Step 1: the tail is the null space. For we have , so .
Step 2: build . For set . As computed in the ellipsoid theorem,
so is orthonormal in .
Step 3: complete the basis. An orthonormal set in extends to an orthonormal basis of — take any basis of the orthogonal complement of and run Gram–Schmidt on it. (When there is nothing to do.) Let and ; both are orthogonal because their columns are orthonormal.
Step 4: verify the factorisation. Two matrices are equal when they agree on a basis, so it suffices to check for each . Since and (interpreted as when ),
and for both sides are by Step 1. Hence .
Step 5: is the rank. and are invertible, so , and visibly has nonzero rows.∎
Three details of that proof carry all the practical weight, and they are the three places students go wrong.
First, the are computed from the , not diagonalised separately. It is true that the columns of are orthonormal eigenvectors of — apply the shared-eigenvalue proposition — but if you diagonalise on its own you get vectors determined only up to sign, and a wrong sign destroys the identity . The formula pins the signs together.
Second, the completion in Step 3 is where a rank-deficient or tall matrix is handled. If you must produce further orthonormal columns, and they are exactly a basis of ; if the last columns of are a basis of . Nothing about the theorem requires to have full rank.
Third, has the shape of , not of or . If is then is : a diagonal block on top and a row of zeros beneath.
Notation. We write for the matrix and, when only the top block matters, for the invertible diagonal matrix of nonzero singular values. Columns are (left singular vectors) and (right singular vectors); and denote the matrices of the first of each.
Theorem 12.11 (Uniqueness of the SVD). The singular values of are uniquely determined by . If all the nonzero singular values are distinct, then each pair with is determined up to a simultaneous sign change . If a singular value is repeated with multiplicity , the corresponding 's are determined only up to an arbitrary orthogonal change of basis inside that -dimensional eigenspace.
Proof. Given any factorisation with orthogonal, compute
This is an orthogonal diagonalisation of , so the diagonal entries of — namely — are the eigenvalues of , which depend only on . Since , the themselves are determined, and the ordering convention fixes their arrangement.
The columns of are then forced to be an orthonormal eigenbasis of . If is a simple eigenvalue its eigenspace is a line, so is determined up to sign; and then flips sign with it. If has multiplicity , any orthonormal basis of its -dimensional eigenspace will serve.∎
Remark. Non-uniqueness is not a defect. It is the same freedom you have when choosing an orthonormal basis for a plane: no canonical choice exists, and none is needed, because every quantity we extract from the SVD in this chapter — rank, norms, condition number, the pseudoinverse, the best rank- approximation — is independent of which admissible choice you make. Only the individual vectors wobble, and question banks therefore pin them with a sign convention.
Definition 12.12 (Full and reduced SVD). The full SVD of an matrix of rank is with of size , of size and of size .
The reduced (thin) SVD keeps only the columns that do anything:
where is with orthonormal columns, is diagonal and invertible, and is with orthonormal columns. Equivalently,
the outer product form: is a sum of rank-one matrices with decreasing weights.
The outer product form is the one to remember. Each term is a rank-one matrix of "size" , and the decomposition sorts the content of from most important to least. Low-rank approximation, image compression and PCA are all statements about truncating that sum.
Note the storage difference. A full SVD of a matrix stores a matrix — a million numbers, of whose columns are multiplied by zero. The reduced SVD stores . Software returns the reduced form by default for exactly this reason.
Method 12.13 (Computing an SVD by hand). Given of size :
- Choose the smaller Gram matrix. If work with (); if work with () and swap the roles of and throughout.
- Find the eigenvalues of and an orthonormal eigenbasis . Normalise each eigenvector; orthogonalise within a repeated eigenvalue if necessary.
- Set and let be the number that are nonzero.
- For set . Never compute these by diagonalising separately.
- If , extend to an orthonormal basis of by solving and applying Gram–Schmidt to a basis of that null space.
- Assemble , (the shape of ) and , and check on at least one entry.
Example 12.14 (A square SVD in full). Find the full SVD of .
Solution. From the ellipse example we already have , , , hence , , and
Left singular vectors:
Assemble:
Check: and
Note , not . Had we diagonalised and picked , the product would have come out as , which is not .□
Example 12.15 (A tall non-square SVD). Find the full SVD of .
Solution. This is , so is , is , is .
From the earlier example, with , , so , and .
For : gives , so . For : , so .
Left singular vectors:
Since we need one more column. It must span : solving
gives and , so . Confirm orthogonality: and . ✓
The full SVD is
The reduced SVD drops the third column of and the last row of :
Sanity check on the entry: . ✓□
Example 12.16 (A wide non-square SVD). Find the full SVD of .
Solution. Here , so the recipe says diagonalise the smaller Gram matrix :
Trace , determinant , so : , , giving and . Both nonzero, so and has full row rank.
Eigenvectors of (these are the 's): for , gives ; for , gives .
Now run the recipe in reverse to get the 's, using :
Check : . ✓
must be , so we need spanning . Solve and . Adding gives , so ; substituting into the first gives , so . Taking : , normalised .
Hence
Sanity check: , and the sum of squares of the entries of is . ✓□
Example 12.17 (A rank-deficient non-square SVD). Find the full SVD of .
Solution.
with trace and determinant , so , . Thus , and : the matrix is rank one, as its identical columns advertise.
Eigenvectors: for , gives ; for , gives , which indeed satisfies .
Only comes from the formula:
We need two more columns of , from , a plane. Pick and — already orthogonal to each other and to — and normalise:
Then
In outer product form the whole matrix is a single term:
Note that were not forced on us: any orthonormal basis of that plane works, which is the multiplicity clause of the uniqueness theorem in action ( here has multiplicity two on the side).□
Pitfall. When you cannot compute — you would be dividing by zero, and indeed carries no directional information. The remaining columns of must come from the null space of , not from the formula. Similarly, if is wide (), the last columns of come from .
12.3The four fundamental subspaces
A matrix has four subspaces attached to it: the column space , the null space , the row space , and the left null space . Row reduction produces bases for all four, but the bases it produces are not orthonormal and the two pairs are related only by a theorem. The SVD produces orthonormal bases for all four at once, and the orthogonality relations become visible rather than proved.
Theorem 12.18 (Orthonormal bases from the SVD). Let be a full SVD of an matrix of rank . Then
and in each case the listed vectors form an orthonormal basis.
Proof. Null space. For , , so . Conversely write any ; then , and since the are independent, forces , hence for . So lies in the stated span. The vectors are orthonormal as columns of an orthogonal matrix, and there are of them, matching the Rank–Nullity Theorem.
Column space. shows every output is a combination of , and taking realises , so each () is attained. Hence is exactly that span.
The other two. Transposing the SVD gives , which is a full SVD of with the roles of and exchanged and the same nonzero singular values. Applying the two results already proved to yields and .∎
Corollary 12.19 (The orthogonality of the fundamental subspaces). and are orthogonal complements in , and and are orthogonal complements in .
Proof. is an orthonormal basis of , split by the theorem into a basis of (the first ) and a basis of (the rest). A splitting of an orthonormal basis into two blocks makes the two spans orthogonal complements. The same argument in with the 's gives the second statement.∎
This is why the SVD is sometimes called the "complete picture" of a matrix. Read from right to left, says: express the input in the basis, throw away the components in , scale the survivors by , and read the result off in the basis. The matrix is an isomorphism from to — both of dimension — plus a projection that kills everything else.
Intuition. Think of as a sorting office. Mail arriving in is first separated into two piles: the row space pile, which gets delivered, and the null space pile, which is incinerated. The delivered pile arrives in the column space of , scaled up or down. The left null space is the set of addresses in that no mail can ever reach. The SVD hands you orthonormal street maps for all four.
Example 12.20 (Reading the subspaces off an SVD). Using the full SVD of computed above, give orthonormal bases for all four fundamental subspaces and state their dimensions.
Solution. There , , , with
- , dimension .
- , the zero subspace, dimension (there are no columns of past the second).
- , dimension .
- , dimension .
Sanity check: . ✓ And , as Rank–Nullity requires.□
Example 12.21 (Subspaces of a rank-one matrix). For , use the SVD computed earlier to give orthonormal bases for the four subspaces.
Solution. There , , .
- , dimension — the line through , which is indeed where both columns of live.
- , dimension : the plane .
- , dimension .
- , dimension .
Sanity check: and . ✓□
12.4Rank, numerical rank, and matrix norms
The rank fell out of the existence proof: it is the number of nonzero singular values. That is more than a restatement, because it is the only practical way to compute a rank from measured data.
Proposition 12.22 (Rank from singular values). equals the number of singular values of that are nonzero.
Proof. Multiplying by an invertible matrix does not change rank, so , and the rank of a diagonal-shaped matrix is its number of nonzero diagonal entries.∎
Row reduction also computes a rank, and on exact integer data it is faster. On floating-point data it is worthless. Consider
Row reduction reports rank , because the second pivot is rather than exactly . The singular values are approximately and , which reports the truth: the matrix is a rank-one matrix that has been perturbed. The useful notion is therefore not rank but numerical rank.
Definition 12.23 (Numerical rank). Fix a tolerance . The numerical rank of at tolerance is the number of singular values with . A standard default is , which scales the tolerance with the size of the matrix and of its largest singular value.
The justification for this definition is supplied by the Eckart–Young theorem later in the chapter: if then there is a matrix of rank within distance of , so at resolution the matrix is indistinguishable from one of rank .
Definition 12.24 (Spectral norm and Frobenius norm). For an matrix , the spectral norm (or operator -norm) is
and the Frobenius norm is
The two measure different things. The spectral norm asks how far the matrix can stretch a single vector — it is a worst-case amplification factor. The Frobenius norm treats the matrix as a list of numbers and takes their Euclidean length. Both have clean expressions in singular values.
Theorem 12.25 (Norms in terms of singular values). For any real matrix of rank ,
Proof. Spectral norm. By homogeneity it suffices to maximise over unit . Expanding with , the computation in the ellipsoid theorem gives
with equality when (so and the rest vanish). Hence the maximum is , attained.
Frobenius norm. First note , since the entry of is the squared length of the -th column of . The trace of a matrix is the sum of its eigenvalues, and the eigenvalues of are (zeros included). Therefore
Corollary 12.26 (Both norms are orthogonally invariant). If and are orthogonal of the right sizes, then and .
Proof. , which is similar to (as ) and hence has the same eigenvalues. So has the same singular values as , and both norms are functions of the singular values alone.∎
That corollary is the reason the SVD interacts so well with these norms: rotating the input or the output of a linear map changes neither how much it can stretch nor its total energy.
Example 12.27 (Both norms of a matrix). Compute and for .
Solution. The singular values were found to be and .
Sanity check on the Frobenius norm directly from the entries: . ✓ And note , which always holds since .□
Example 12.28 (When the two norms coincide). For which matrices is ?
Solution. , which vanishes exactly when , i.e. when .
So the two norms agree precisely for matrices of rank at most one (including the zero matrix). For instance has and . ✓□
Example 12.29 (Numerical rank in practice). A measurement matrix has singular values , , , . What is its numerical rank, and what does that tell you?
Solution. Take the standard tolerance with : . By that strict tolerance all four singular values exceed and the numerical rank is .
But the data were measured, and measurement noise is far larger than . If the entries are accurate to about , the honest tolerance is , and then only two singular values survive: the numerical rank is .
The conclusion is that the four measured variables really carry two independent pieces of information, with the remaining two directions accounted for by noise. The gap between and — four orders of magnitude — is what makes the conclusion safe; had the values been there would be no defensible cut.□
Pitfall. There is no single "the norm" of a matrix. and differ, sometimes a lot: the identity has but . Always say which norm you are using, and never assume a statement proved in one holds in the other — the Eckart–Young theorem is remarkable precisely because it happens to hold in both.
12.5The condition number
Solving on a computer means solving it with a that is slightly wrong, because measurements and floating-point arithmetic are both inexact. How wrong is the answer? The singular values give a sharp answer.
Definition 12.30 (Condition number). For an invertible matrix with singular values , the condition number (in the -norm) is
A singular matrix is assigned . A matrix with small is called well-conditioned; one with large is ill-conditioned. For a rectangular or rank-deficient matrix one uses .
The second expression needs a line of justification: if then , which is an SVD of once the diagonal entries are reordered. So the largest singular value of is and .
Theorem 12.31 (Error amplification). Let be invertible, with , and let . Then
and the bound is attained for suitable and .
Proof. Subtracting the two equations gives , so and
Also , i.e. . Multiplying the two inequalities,
For attainment take , so and the second inequality is an equality, and take , so and the first is an equality too.∎
The rule of thumb that follows is worth memorising: if , then solving can lose about decimal digits of accuracy. Double precision carries roughly digits, so a condition number near means the computed solution may have no correct digits at all.
Intuition. Condition number is a lever ratio. A matrix that stretches one direction by and another by has . Ask it to undo itself and it must shrink the first direction by and leave the second alone — so an error you introduce along the weakly-stretched direction gets magnified by on the way back. The trouble is not that is nearly singular in absolute terms; it is that is nearly singular relative to its own scale. Multiplying a matrix by changes neither its condition number nor its difficulty.
Example 12.32 (A well-conditioned and an ill-conditioned matrix). Compute the condition numbers of and .
Solution. Both are diagonal with positive entries, so the singular values are the diagonal entries.
is as well-conditioned as a non-scalar matrix gets. will lose roughly four decimal digits: a relative error of in can become a relative error of in .
Sanity check on the claim of attainment: with and we get and , exactly times the relative perturbation. ✓□
Example 12.33 (Conditioning of a non-diagonal matrix). Find for and interpret it.
Solution.
Trace and . From ,
Numerically , so and . Hence , , and
Interpretation: the two rows of are nearly parallel, so the two lines and meet at a very shallow angle and their intersection point moves a long way when a line is nudged. A relative error of in can produce a relative error of several hundred percent in .
Sanity check: . ✓□
Example 12.34 (Scaling does not help). Show that for any nonzero scalar , and explain why "the determinant is tiny" is not the same as "the matrix is ill-conditioned".
Solution. If then after absorbing the sign of into , so every singular value is multiplied by and the ratio is unchanged.
Now take . Its determinant is , apparently alarming, but its singular values are both and : it is perfectly conditioned. The matrix has the same determinant and .
The determinant is the product of the singular values and so confuses overall scale with the spread between directions. The condition number, a ratio, is immune to scale — which is exactly the property a measure of difficulty should have.□
Pitfall. always, since . A computed condition number below is an arithmetic slip, usually the ratio taken upside down.
12.6Low-rank approximation
The outer product form orders the content of by importance. Truncating it after terms should give the best possible rank- summary of , and remarkably it does — in both of our norms, which is not something one has any right to expect.
Definition 12.35 (Truncated SVD). For the rank- truncation of is
where and hold the first columns of and and . It has rank exactly (assuming ).
Lemma 12.36 (The truncation error).
with the convention for .
Proof. , which is a decomposition of exactly the same form: orthonormal 's, orthonormal 's, nonnegative decreasing weights. So its singular values are , and the norm formulas apply, giving the largest of them for the spectral norm and the root sum of squares for the Frobenius norm.∎
Theorem 12.37 (Eckart–Young). Let be of rank and let . For every matrix of rank at most ,
with equality for . The same minimisation is solved by in the Frobenius norm, where the minimum value is .
Proof. We prove the spectral norm statement in full. Let have rank at most . Then by Rank–Nullity. The subspace has dimension , and
so the two subspaces intersect in more than the zero vector. Pick a unit vector and write with . Then , so
using that for . Hence , and the truncation lemma shows attains it.
For the Frobenius norm the same conclusion holds; the standard argument writes using Weyl's inequality , which with and gives for every ; summing the squares over yields the bound. We take Weyl's inequality on trust here, as its proof is a variational argument belonging to a numerical analysis course.∎
Intuition. A photograph stored as a matrix of grey levels is not independent numbers. Sky is nearly constant, walls are nearly constant, edges repeat. In singular value terms, might be , might be , and might be . Keeping the first terms keeps everything a human eye registers and throws away of the storage. Eckart–Young says you cannot do better with any other -dimensional description: the truncated SVD is not a good heuristic, it is the optimum.
Example 12.38 (Best rank-one approximation, by hand). Find the best rank-one approximation to and the error in both norms.
Solution. From the earlier SVD, , , , and .
The error is , and
Sanity check directly: the error matrix has entries , so its Frobenius norm is . ✓ (The two norms coincide because the error has rank one.)□
Example 12.39 (How much of the matrix does rank capture?). A matrix has singular values . What fraction of is captured by the best rank- approximation, and what is the rank- error in each norm?
Solution. . The rank- truncation captures , a fraction
about .
Errors: and .
Sanity check: . ✓ The Pythagorean split always holds, because the two pieces are built from disjoint sets of orthonormal outer products.□
Example 12.40 (Image compression: counting the storage). A greyscale image is a matrix. It is approximated by its rank- truncation. How many numbers must be stored, and what is the compression ratio?
Solution. Storing outright costs numbers.
The rank- truncation is stored as (), the singular values, and ():
In general the cost is . The compression ratio is
so about of the original storage, an saving.
Sanity check on when this is worth doing: the truncation saves space only when , i.e. here. Taking would store more numbers than the original image while still losing information.□
Example 12.41 (Choosing from an energy target). The singular values of a data matrix are . Choose the smallest for which the rank- truncation retains at least of .
Solution. Squares: ; total .
Cumulative: (), (), (), (), , .
The first cumulative fraction to reach is at , with .
So . Sanity check: at the fraction is , so is genuinely the smallest. ✓□
Pitfall. The best rank- approximation is not obtained by zeroing the small entries of , nor by deleting its least important rows or columns. It is obtained by zeroing the small singular values, which mixes every entry of . Zeroing entries below a threshold in changes nothing, yet the matrix is within of a rank-one matrix.
12.7The Moore–Penrose pseudoinverse
A matrix that is not square, or is square but singular, has no inverse. It does, however, have a best available substitute, and the SVD writes it down in one line: invert what can be inverted and leave the rest alone.
Definition 12.42 (Moore–Penrose pseudoinverse). Let be a full SVD of an matrix of rank . Let be the matrix with for and zeros elsewhere. The pseudoinverse of is the matrix
Note carefully what is and is not inverted: the nonzero are replaced by their reciprocals, and the zero ones are left as zero. Reciprocating a zero is what an inverse would have to do and cannot; the pseudoinverse simply declines.
The definition appears to depend on the choice of SVD, which is not unique. It does not, and the reason is the Penrose characterisation.
Theorem 12.43 (The four Penrose conditions). is the unique matrix satisfying
Proof. Existence. Write , . Then is the diagonal matrix with ones followed by zeros; call it , and note and . Similarly , the diagonal matrix with ones, with and . Now
which is (i); (ii) is the same computation with the roles exchanged. For (iii), , which is symmetric since is; (iv) is , likewise symmetric.
Uniqueness. Suppose and both satisfy all four. Then
Because the four conditions mention only , the matrix they determine cannot depend on which SVD produced it.
Proposition 12.44 (Special cases).
- If is invertible then .
- If has full column rank () then .
- If has full row rank () then .
- is the orthogonal projection onto , and is the orthogonal projection onto .
Proof. (1) If is invertible, satisfies all four Penrose conditions trivially, so by uniqueness .
(2) With , is invertible, so is invertible and
because is the matrix with diagonal .
(3) Apply (2) to and use , immediate from the definition.
(4) From the proof above, , which is symmetric and idempotent with column space — the defining description of the orthogonal projection onto . Similarly projects onto .∎
Part (4) is what connects the pseudoinverse to least squares, the subject that motivated it.
Theorem 12.45 (Least squares and minimum norm). For any and any , the vector minimises over all ; and among all minimisers it is the one of smallest norm.
Proof. Least squares. ranges over as ranges over , so is minimised exactly when is the orthogonal projection of onto , namely by part (4). Taking gives , so is a minimiser.
Minimum norm. If is any other minimiser then , so . But is a combination of and hence lies in , which is orthogonal to . Pythagoras gives
with equality only when .∎
Intuition. Least squares with a full-rank has one answer. When is rank-deficient — two of your predictors are the same measurement in different units, say — there is a whole flat of equally good answers, and any of them fits the data identically well. The pseudoinverse picks the one closest to the origin: the fit that does not put large, cancelling coefficients on the duplicated predictors. That is both the most stable and the most interpretable choice, and it is what every numerical library returns.
Example 12.46 (Pseudoinverse of a full-column-rank matrix). Compute for .
Solution. The columns are independent, so and formula (2) applies.
Then
Sanity check with Penrose condition (i): . ✓ (For full column rank always, since the projection onto is the identity.) Note : it is the projection onto a plane in .□
Example 12.47 (Pseudoinverse of a rank-deficient matrix). Compute for , and verify the four Penrose conditions.
Solution. has eigenvalues and , so , , and does not exist — formula (2) is unavailable and we must use the SVD.
and .
Verification: , which is symmetric (iii) — it is the projection onto the line through . By symmetry is the same matrix, giving (iv). Then (i), and (ii). ✓
Sanity check on the nonsense alternative: does not exist, and no matrix has , since is only a line.□
Example 12.48 (Minimum-norm least squares). Solve in the least-squares, minimum-norm sense for and .
Solution. Using from the previous example,
Check it is a least-squares solution: , and the residual is orthogonal to , as required. ✓
Check minimum norm: every vector of the form satisfies too, and its squared norm is , minimised at . ✓
Example 12.49 (Pseudoinverse of a wide matrix). Compute for and use it to find the minimum-norm solution of .
Solution. is of rank , so it has full row rank and formula (3) applies: , so
The minimum-norm solution of is
Sanity check: ✓, and geometrically the closest point of a plane to the origin is along the normal direction, which for is . Its norm is , matching the distance formula . ✓□
Pitfall. in general — the pseudoinverse does not reverse products the way the inverse does. It is also discontinuous in : for we have , which blows up as , while . This is the practical reason numerical libraries truncate small singular values before pseudo-inverting.
12.8Principal component analysis
Given a table of measurements — observations of variables — which directions in variable space carry the variation, and how many of them are really needed? Principal component analysis answers both questions, and the answer is the SVD of the centred data matrix.
Definition 12.50 (Centred data matrix and sample covariance). Let the rows of be observations of variables. Subtract from each column its mean to obtain the centred data matrix , so that every column of sums to zero. The sample covariance matrix is
an matrix whose entry is the sample covariance of variables and , and whose entry is the sample variance of variable .
Centring is not cosmetic. Variance measures spread about the mean, so the formula computes variance only if the mean has already been removed. Skip the centring and the largest "principal component" typically points at the mean vector, describing where the data sits rather than how it varies.
By the Gram matrix proposition, is symmetric positive semidefinite, so the Spectral Theorem applies and has an orthonormal eigenbasis with nonnegative eigenvalues. Those eigenvectors are the principal components, and the SVD of produces them directly.
Definition 12.51 (Principal components). Let be an SVD of the centred data matrix. The -th principal component is the right singular vector , a unit vector in variable space. The variance explained by it is
and the scores of the observations on it are the entries of .
Proposition 12.52 (The principal components diagonalise the covariance). With ,
so the columns of are orthonormal eigenvectors of with eigenvalues . In particular the variance explained by is exactly the -th eigenvalue of , and the total variance is
Proof. , and dividing by gives the display. Since is orthogonal and is diagonal, this is an orthogonal diagonalisation of with the stated eigenvalues. The trace of equals the sum of its eigenvalues, and also the sum of the sample variances of the individual variables, so "total variance" is unambiguous.∎
Theorem 12.53 (The first principal component maximises variance). Among all unit vectors , the sample variance of the projected data is largest when , and its value is then . More generally, among unit vectors orthogonal to , the maximum is attained at with value .
Proof. Because is centred, the projected values have mean zero, so their sample variance is
Write with . Then , with equality at , i.e. . Restricting to forces , and the same estimate gives the bound , attained at .∎
Definition 12.54 (Explained variance fraction). The fraction of total variance explained by the first principal components is
the 's cancelling. One usually chooses the smallest meeting a target such as or , or reads off the "elbow" of a scree plot of against .
Notice that this is Eckart–Young wearing different clothes. Projecting the data onto the span of produces the matrix , which is the rank- truncation of ; the residual sum of squared distances from the data points to that -dimensional subspace is , minimised by that choice of subspace. PCA finds the -dimensional plane closest to the data in the least-squares sense.
Intuition. A cloud of points shaped like a cigar has one long direction and two short ones. PCA hands you the axis of the cigar first, then the two cross-sectional directions, sorted. If the cigar is very thin you may describe each point by a single number — its position along the axis — and lose almost nothing. The explained variance fraction tells you exactly how much "almost nothing" is.
Example 12.55 (PCA on three points). The observations are , , . Find the principal components and the explained variance fractions.
Solution. Mean: , so the data is already centred and is the matrix of the three points as rows.
Covariance with : , , , so
Trace , determinant : gives , so , .
For : forces , so ; then .
Explained variance: . Projecting onto the single line through retains of the spread.
Sanity check: ✓ — the trace is unchanged by the orthogonal change of basis PCA performs, which is why "total variance" does not depend on the coordinate system.□
Example 12.56 (PCA with centring, and the singular values). The observations are , , , . Centre the data, find the first principal component with the convention that its first entry is positive, and report the fraction of variance it explains.
Solution. Means: , . Centred rows:
Then , , , so with ,
Eigenvalues of : trace , determinant , so , giving and . Hence the singular values of are and , and the covariance eigenvalues are and .
The eigenvector for satisfies , so : with the stated sign convention,
Explained variance fraction: .
Sanity check: total variance , and ✓ — the cancels, as claimed.□
Example 12.57 (Choosing on a real-sized problem). A dataset of observations of variables has with singular values . How many components are needed for of the variance, and what is the variance explained by the first component?
Solution. Squares: , totalling .
Cumulative fractions: ; ; .
So components are needed — two fall just short of the target at .
The variance explained by the first component in absolute units is .
Sanity check: the total variance is , and , matching the fraction computed from squares alone. ✓□
Pitfall. PCA is not scale-invariant. If one variable is measured in millimetres and another in kilometres, the first will dominate the covariance matrix purely because of its units, and the first principal component will point along it. When variables have different units, standardise each column to unit variance first — equivalently, run PCA on the correlation matrix rather than the covariance matrix.
Remark. Two conventions clash in the literature. We put observations in rows, so the principal components are the right singular vectors and . Some texts put variables in rows, in which case the principal components are the left singular vectors. Always check which way the data matrix is oriented before quoting a formula.
12.9The polar decomposition
A nonzero complex number factors as : a rotation times a stretch. Square matrices do the same, and the SVD proves it in one line.
Theorem 12.58 (Polar decomposition). Every real matrix factors as
where is orthogonal and is symmetric positive semidefinite. If is invertible the factorisation is unique, with and . There is also a left-handed version with .
Proof. Take an SVD and insert :
where is orthogonal (a product of orthogonal matrices) and is symmetric with nonnegative eigenvalues , hence positive semidefinite.
For uniqueness when is invertible, note that forces
and a positive definite matrix has exactly one positive definite square root (diagonalise: the square root must act as on each eigenspace). So is determined, and then is too.∎
Intuition. In continuum mechanics this is the statement that any deformation of a body is a pure stretch along three perpendicular axes followed by a rigid rotation. is the stretch tensor, the rotation. Engineers care because material response depends on alone — rotating a steel beam does not stress it.
Example 12.59 (Polar decomposition of a matrix). Find the polar decomposition of .
Solution. From the SVD computed earlier, , , .
a rotation by .
Check: the entry of is ✓, and the entry is ✓.
Sanity check on : its eigenvalues should be the singular values of . Trace and determinant ; the eigenvalues of are and . ✓□
Example 12.60 (The nearest orthogonal matrix). Show that the in the polar decomposition is the orthogonal matrix closest to in the Frobenius norm, and find it for .
Solution. For any orthogonal , orthogonal invariance of the Frobenius norm gives
and ranges over all orthogonal matrices as does. Expanding,
since . So we must maximise . Every entry of an orthogonal matrix satisfies , so the sum is at most , attained at , i.e. .
For , which is already symmetric positive definite, the SVD is and , so and . The nearest orthogonal matrix to is the identity, at distance .□
12.10Applications
The three sections above are the theory; this one is a short tour of what practitioners actually do with it. Each application is the same theorem — truncate the outer product sum — applied to a different kind of matrix.
Latent semantic analysis. Build a term–document matrix whose entry counts occurrences of word in document . It is enormous and almost entirely zero, and a keyword search on it fails whenever a query says "car" and a document says "automobile". Truncate to rank . The columns of are "topics" — weighted word combinations — and each document becomes a short vector of topic scores. Two documents about cars now have similar scores even with no word in common, because both words load on the same singular direction. The truncation is doing the synonymy handling, and Eckart–Young is the guarantee that no other -dimensional summary retains more of the original counts.
Recommender systems. Let be a users items matrix of ratings. A rank- model says each user is a point in a -dimensional taste space and each item a point in the same space, with the predicted rating being an inner product. Fitting to a matrix of a million users and twenty thousand films replaces unknown ratings with parameters. (The honest version of this problem has most entries missing, so one minimises the error over the observed entries only; the truncated SVD is the special case where everything is observed, and it is where the idea comes from.)
Noise filtering. Suppose a true signal matrix has rank and you observe with small random noise. The singular values of then look like large ones, inherited from , followed by a shelf of small ones contributed by the noise. Truncating to rank removes most of while disturbing by at most , since
using (because has rank , so is at most the distance from to the rank- set, which is at most ). The same argument underlies background subtraction in video and denoising in seismic imaging.
Least squares and regularisation. Fitting a model with nearly collinear predictors gives an ill-conditioned , and the least-squares coefficients become wild. Truncated SVD regularisation discards the singular directions with below a threshold before pseudo-inverting, which caps the amplification at and stabilises the fit at the cost of a small bias.
Example 12.61 (A tiny latent semantic analysis). Three documents have the term counts
rows indexing the terms car, automobile, banana. Find the singular values and interpret the rank- structure.
Solution. is symmetric, so its singular values are the absolute eigenvalues. The block has eigenvalues and , and the remaining block contributes . So the eigenvalues are and
The rank is : the third document is about something else entirely, and the first two terms are perfectly redundant. The first singular direction is — a single "vehicle" topic that pools car and automobile — and the second is , a "fruit" topic.
Sanity check: , and the sum of squared entries of is . ✓ A rank- truncation loses nothing here, because .□
Example 12.62 (Sizing a recommender model). A ratings matrix has users and items. Compare the storage of the full matrix with a rank- model.
Solution. Full matrix: numbers.
Rank- model: numbers, about .
The ratio is , so the model is roughly times smaller. Sanity check that is in the useful range: the break-even rank is , so is far below it. ✓□
Summary. For an matrix of rank with SVD :
- , and for .
- ; ; ; .
- , , , .
- is the best rank- approximation, with errors (spectral) and (Frobenius); storage .
- gives the minimum-norm least-squares solution .
- PCA: principal components are the of the centred , with variances .
- Polar: , rotation times stretch.