Lecture 51 · Week 13· 19:20
Singular value decomposition
Geometry and computation of the SVD.
Saved in this browser only. No account needed.
TranscriptThe full text of the lecture. Click any sentence to play the video from there.
Today: what every matrix does
Welcome back. In lecture forty nine, the spectral theorem told us that a real symmetric matrix has an orthonormal basis of eigenvectors. In that basis, the matrix only stretches, along perpendicular axes. But most matrices are not symmetric, and many are not even square. A three by two matrix sends the plane into space. It has no eigenvectors at all, because A x and x live in different spaces. Today's theorem says that every real matrix, of any shape, still acts by stretching along perpendicular axes, as long as we use one orthonormal basis for the inputs, and another one for the outputs.
Here is a first look. The matrix A with rows (two, two), and (minus one, two), sends the unit circle to an ellipse. The ellipse has two perpendicular axes, of half lengths three and two, and they are the images of two perpendicular unit vectors on the circle. Finding those vectors, and those lengths, is the singular value decomposition. Here is the plan. First, the matrix A transpose A, and the singular values. Then the decomposition itself, with its proof. Then its geometry, and the largest stretch. And finally, how to compute it, and what it says about the four fundamental subspaces.
Singular values
Throughout today, A is a real m by n matrix, and R n and R m carry the dot product. Everything starts from lengths. The squared length of A x is A x dot A x, and by the transpose rule of lecture fifteen, that is x dot A transpose A x. So the matrix A transpose A knows how much A stretches every vector. Proposition: A transpose A is symmetric, and every eigenvalue of it is greater than or equal to zero. It is symmetric, because its transpose is A transpose times A transpose transpose, which is A transpose A again.
Now let v be an eigenvector of length one, with eigenvalue lambda. Then lambda equals lambda times v dot v, which is v dot lambda v, which is v dot A transpose A v, which is the squared length of A v. A squared length is never negative. Since A transpose A is real and symmetric, the spectral theorem gives an orthonormal basis of R n, v one up to v n, made of its eigenvectors. We number them so that the eigenvalues decrease: lambda one is at least lambda two, and so on down to lambda n, which is at least zero. Definition. The singular values of A are the square roots of these eigenvalues: sigma j is the square root of lambda j. So sigma one is the largest, and none of them is negative.
The proof gave us more. The squared length of A v j is lambda j, so the length of A v j is sigma j. The singular value sigma j is the factor by which A stretches the eigenvector v j. Back to our matrix. A transpose A has the entries four plus one, which is five, four minus two, which is two, twice, and four plus four, which is eight. Its characteristic polynomial is t squared, minus thirteen t, plus thirty six, which factors as t minus nine, times t minus four. So the eigenvalues are nine and four, and the singular values are three and two.
Notice that these are not eigenvalues of A. The characteristic polynomial of A is t squared, minus four t, plus six, and its roots are not even real. Eigenvalues ask which directions A keeps. Singular values ask how much A changes lengths. The eigenvectors. For nine, A transpose A minus nine I has rows (minus four, two), and (two, minus one), so v one is the vector (one, two), divided by root five. For four, the rows are (one, two), and (two, four), so v two is the vector (minus two, one), divided by root five. They are perpendicular, as the spectral theorem promised.
Now the key fact. Proposition: the vectors A v one up to A v n are orthogonal, and the length of A v j is sigma j. The number r of nonzero singular values is the rank of A. The proof is one line. A v j dot A v k equals v j dot A transpose A v k, which is lambda k, times v j dot v k. That is zero when j and k are different, and lambda j when they are equal. For the rank: by the line above, the length of A v j is sigma j, so A v j is zero exactly when sigma j is zero, that is, for j greater than r, since the sigma j decrease. A zero eigenvalue causes no trouble: it only means that v j lies in the null space of A. The other r images are orthogonal and nonzero, so they are independent. They span the column space, because every x is a combination of the v j. So the rank is r.
In our example, A v one is the vector (six, three), over root five, which is three times the vector (two, one), over root five. And A v two is the vector (minus two, four), over root five, which is two times the vector (minus one, two), over root five. Their lengths are three and two, and they are perpendicular. That is the ellipse we saw at the start.
Every matrix has an SVD
So A sends the orthonormal vectors v j to orthogonal vectors of lengths sigma j. Divide by those lengths. For j up to r, let u j be A v j, divided by sigma j. These u j are orthonormal vectors in R m, and A v j equals sigma j u j. Here is the main theorem. Let A be a real m by n matrix of rank r. Then A equals U sigma V transpose, where U is an orthogonal m by m matrix, and V is an orthogonal n by n matrix. Sigma is the m by n matrix with the positive singular values sigma one, down to sigma r, as its first r diagonal entries, and zeros everywhere else.
A word about letters. In this lecture and the next, U and V always mean these two orthogonal matrices, never a subspace or a vector space. And capital sigma is a matrix, not a sum. The proof puts together everything we have built, so it is worth taking slowly, and pausing if you need to. Step one. Take the orthonormal eigenvectors v one up to v n of A transpose A, in order of decreasing eigenvalue, as the columns of V. Orthonormal columns make the square matrix V orthogonal. Step two. For j up to r, the vectors u j are orthonormal, by the proposition. If r is less than m, extend them to an orthonormal basis of R m, with Gram-Schmidt, as in lecture forty seven. These are the columns of U, which is orthogonal.
Step three. We compare A V and U sigma, column by column. Column j of A V is A v j. Column j of U sigma is sigma j u j when j is at most r, and zero when j is larger. For j up to r, A v j equals sigma j u j, by the definition of u j. For j larger than r, the length of A v j is sigma j, which is zero, so A v j is zero. So A V equals U sigma. Step four. V is orthogonal, so V V transpose is the identity. So A equals A V V transpose, and replacing A V by U sigma, that is U sigma V transpose. That proves the theorem.
Definition. A factorisation A equals U sigma V transpose of this kind is a singular value decomposition of A, or S V D for short. The columns v j of V are the right singular vectors, and the columns u j of U are the left singular vectors. The singular values are fixed by A, because they come from the eigenvalues of A transpose A. The singular vectors are not. Replacing v j and u j by their negatives gives another decomposition, and a repeated singular value allows even more choices.
Rotate, stretch, rotate
For our matrix, the decomposition is this. The vectors v one and v two are the unit eigenvectors of A transpose A that we found, for the eigenvalues nine and four, and each u j is A v j divided by sigma j. So U has the columns u one, which is A v one over three, the vector (two, one), over root five, and u two, which is A v two over two, the vector (minus one, two), over root five. Sigma has three and two on its diagonal. And V has the columns v one and v two. Let's check it. U times sigma has the first column six, three, and the second column minus two, four, both over root five. Times V transpose, the first row is six plus four, and twelve minus two, so ten and ten. The second row is three minus eight, and six plus four, so minus five and ten. Divided by five, that is A. Now read A equals U sigma V transpose from right to left, as three steps. First, V transpose. It is orthogonal, so it keeps lengths and angles, and it turns v one and v two onto e one and e two. The circle stays a circle.
Second, sigma stretches. It stretches e one by three, and e two by two. The circle becomes an ellipse, with its axes along the coordinate axes. Third, U is orthogonal. It turns e one and e two onto u one and u two, and the ellipse turns with them. The result is exactly the image of the circle under A, with half axes three u one and two u two. Watch the three steps once more.
Here both U and V happen to be rotations. In general an orthogonal matrix may also reflect. So every real two by two matrix is a rotation or reflection, then a stretch along the axes, then another rotation or reflection. The same picture works in every dimension. When r equals n, A maps the unit sphere of R n onto an ellipsoid in the column space, with half axes sigma j u j. When r is less than n, the directions v r plus one up to v n are crushed to zero, and the image is a flattened, filled ellipsoid. The picture also answers a natural question: which unit vector does A stretch the most? Theorem: for every unit vector x, the length of A x lies between sigma n and sigma one. The largest value, sigma one, is reached at v one, and the smallest, sigma n, at v n.
Proof. Write x as c one v one, plus up to c n v n. Since the v j are orthonormal, the squares of the c j add up to one. The vectors c j A v j are orthogonal, with lengths the absolute value of c j, times sigma j. So by Pythagoras, the squared length of A x is the sum of c j squared, sigma j squared. Each sigma j squared is at most sigma one squared, so this sum is at most sigma one squared. In the same way, it is at least sigma n squared. Take square roots. And x equal to v one gives sigma one exactly. So in our example, no unit vector is stretched by more than three, or by less than two. The eigenvalues of A could not tell us this. Here they are not even real.
The smallest singular value matters too. When n is at most m, the columns of A are independent exactly when sigma n is positive, and a tiny sigma n warns that they are close to dependent. This is how numerical software measures near dependence, as promised in lecture eleven.
Computing an SVD
Here is the recipe. One, find the eigenvalues of A transpose A, and an orthonormal basis of eigenvectors v j. Two, take square roots, to get the sigma j. Three, for each nonzero sigma j, set u j equal to A v j over sigma j. Four, if needed, complete the u j to an orthonormal basis of R m. Let's do it for a three by two matrix A, with the first row two, two, the second row zero, one, and the third row one, zero. A transpose A has the entries four plus zero plus one, which is five, four plus zero plus zero, which is four, twice, and four plus one plus zero, which is five. Its characteristic polynomial is t squared, minus ten t, plus nine, which is t minus nine, times t minus one. So sigma one is three, and sigma two is one.
For v one, we solve A transpose A, minus nine I, times x, equals zero. That matrix has the first row minus four, four, and the second row four, minus four, so x one equals x two. The vector (one, one) has length root two, so v one is the vector (one, one), over root two. In the same way, the eigenvalue one gives v two, the vector (one, minus one), over root two. Then u one is A v one over three. A times the vector (one, one), is the vector (four, one, one), so u one is the vector (four, one, one), over three root two. And u two is A v two over one, the vector (zero, minus one, one), over root two. We need a third vector u three, orthogonal to u one and u two. Those two span the column space, so u three must lie in its orthogonal complement, the null space of A transpose.
Solving two x one plus x three equals zero, and two x one plus x two equals zero, gives the vector (one, minus two, minus two), and dividing by its length, three, gives u three. So A equals U sigma V transpose, with U three by three, sigma three by two, with three and one on its diagonal and a row of zeros, and V two by two. That last row of zeros means that u three is never reached by A. This example shows a general fact. Theorem: the first r right singular vectors are an orthonormal basis of the row space, and the rest are an orthonormal basis of the null space. The first r left singular vectors are an orthonormal basis of the column space, and the rest, of the null space of A transpose.
The proof counts dimensions. The row space and the column space have dimension r, the null space has dimension n minus r, and the null space of A transpose has dimension m minus r. Orthonormal vectors are independent, and the counts match, so we only need to check that each list lies in the right subspace. Transposing A equals U sigma V transpose gives A transpose u j equals sigma j v j, for j up to r. So for those j, v j lies in the column space of A transpose, which is the row space, and u j, which is A v j over sigma j, lies in the column space. For larger j, A v j and A transpose u j are zero, so v j and u j lie in the two null spaces. So one decomposition gives orthonormal bases of all four fundamental subspaces of lecture twenty seven.
Only the first r columns of U and V meet a nonzero entry of sigma. Corollary: A equals sigma one u one v one transpose, plus up to sigma r u r v r transpose, a sum of r matrices of rank one. This is the reduced, or outer product, form. Proof. Apply both sides to each v k. On the right, v j transpose v k is zero unless j equals k, so we get sigma k u k when k is at most r, and zero otherwise. That is A v k. Two matrices that agree on a basis are equal. In our example, three u one v one transpose has the first row two, two, and the other two rows one half, one half. And u two v two transpose has the first row zero, zero, the second row minus one half, one half, and the third row one half, minus one half. Their sum is A.
Try it yourself
You can try all of this yourself, on this lecture's page at Open Semester dot com. The ink circle is the unit circle, the right singular vectors v one and v two are coral and blue, and the gold point is a unit vector x. Press play, and watch the three steps. V transpose turns v one and v two onto the axes, sigma stretches them by three and two, and U turns the ellipse into place. Now drag the gold point around the circle. Its image runs around the ellipse, and its length never goes above three, or below two.
You can also change A. For the shear with rows (one, one), and (zero, one), the circle still becomes an ellipse, with singular values of about one point six two and zero point six two. And for the matrix with rows (one, two), and (two, four), the rank is one. The second singular value is zero, and the whole circle is flattened onto a segment.
To sum up
One more remark. Over the complex numbers, the same proof works with A star A, and gives A equals U sigma V star, with unitary U and V. Let's sum up. The singular values of A are the square roots of the eigenvalues of A transpose A. They measure how much A stretches, from sigma one at most, down to sigma n. Every real matrix has a singular value decomposition, A equals U sigma V transpose: an orthogonal change of axes, a stretch along the axes, and another orthogonal change of axes.
It gives orthonormal bases of the four fundamental subspaces, and it writes A as a sum of r pieces of rank one, sigma j u j v j transpose, the largest first. Before the next lecture, read section eleven point three of the course book, try the problems on sheet thirteen about the singular value decomposition, and do the lecture check on this lecture's page at Open Semester dot com. Next time, we keep only the first few pieces of that sum. That is low-rank approximation, the idea behind image compression.
In this lecture
Materials
Try it
Rotate, stretch, rotate
Press play, or move the step slider: VT turns the right singular vectors v1, v2 onto the axes, Σ stretches by σ1 and σ2, and U turns (or reflects and turns) the ellipse into place. Pick a matrix or set its entries. Drag the gold point x around the circle: the length of Ax always lies between σ2 and σ1.
Check yourself
3 questions, from warm-up to stretch
Work each one out on paper, type your answer and press Check. Stuck? Open a hint; the worked solution is there when you need it.
- Question 1 of 3 Warm-up
Find the singular values of .
Hint 1 of 2
By Definition 11.3.2 the singular values are the square roots of the eigenvalues of , listed from the largest down. Start with .
Hint 2 of 2
, so . It is diagonal: its eigenvalues are its diagonal entries.
Worked solution
- .
- Its eigenvalues are and , with the orthonormal eigenvectors and .
- So and . Indeed has length and has length . (The eigenvalues of itself are : they are not the singular values.)
- Question 2 of 3 Core
Let . Find and , and the largest value of over all unit vectors in .
Hint 1 of 2
is , so it has two singular values, from the matrix . Its entries are the dot products of the columns of . For the last part, use Theorem 11.3.10.
Hint 2 of 2
, with characteristic polynomial .
Worked solution
- The columns of are and , so .
- , so and .
- By Theorem 11.3.10, for every unit vector , and is reached at . So the largest value of is . Check: and .
- Question 3 of 3 Stretch
Let . Find and . In a singular value decomposition , the second column of can be . Of which of the four fundamental subspaces is an orthonormal basis?
Hint 1 of 2
has trace and determinant . For the last part, use Theorem 11.3.13: what is the rank of ?
Hint 2 of 2
The eigenvalues of are and , so . By Theorem 11.3.13, are a basis of and a basis of . Compute .
Worked solution
- , with . So and , and the rank is .
- The eigenvectors are (for ) and (for ). Then , so , and .
- By Theorem 11.3.13 with : is an orthonormal basis of , of , of and of . So the answer is .
- In outer-product form (Corollary 11.3.14), , one matrix of rank one.
How did it go?