Lecture 52 · Week 13· 17:14

The SVD in action and what comes next

Low-rank approximation, image compression, a look at Jordan form.

Play: Lecture 52: The SVD in action and what comes next
Lecture · 17:14 · Open on YouTube · Report a problem with this video
TranscriptThe full text of the lecture. Click any sentence to play the video from there.

Today: the SVD at work

Welcome to the last lecture of the course. In lecture fifty one, we proved that every real matrix has a singular value decomposition: A equals U sigma V transpose, with orthogonal matrices U and V, and the singular values on the diagonal of capital sigma. Multiplying it out splits A into a sum. A is sigma one u one v one transpose, plus sigma two u two v two transpose, and so on, up to sigma r u r v r transpose, where r is the rank of A. Each term is a column times a row. For example, the column (one, two), times the row (one, two, three), is the matrix with rows (one, two, three), and (two, four, six). Every column is a multiple of the same column, so its rank is one.

We call the terms sigma j u j v j transpose the layers of A. They come in order of size, since sigma one is the largest singular value. Today's idea is to keep only the first few layers. Here is the plan. First, the layers, and how to cut the sum short. Then two ways to measure how far apart two matrices are. Then the Eckart Young theorem: cutting the sum short gives the best approximation of lower rank. Then an application, compressing an image. And finally, a look at what comes after this course: the Jordan normal form.

Layers and truncation

A column u times a row v transpose is the m by n matrix with entries u j times v k. Its row j is u j times the row v transpose. And it acts on a vector x simply: u v transpose x is the number v dot x, times u. Throughout this lecture, A is a real m by n matrix of rank r, with a singular value decomposition. So A v j is sigma j u j for j up to r, and zero after that. Here is the definition. For k from zero to r, the rank k truncation, A k, is the sum of the first k layers. A zero is the zero matrix, and A r is A itself.

The truncation keeps the first k pairs. A k sends v j to sigma j u j when j is at most k, and to zero when j is larger, because the v's are orthonormal. Its column space is spanned by sigma one u one up to sigma k u k, which are orthogonal and nonzero, so its rank is exactly k. What is left over, A minus A k, is the sum of the remaining layers. Its nonzero singular values are sigma k plus one, down to sigma r. Let's see an example. Take the three by two matrix A whose first row is (seven, one), whose second row is (six, eight), and whose third row is (minus one, seven). Its right singular vectors are v one, one fifth of (three, four), and v two, one fifth of (four, minus three).

Multiply. A times the vector (three, four), is the vector (twenty five, fifty, twenty five). That is twenty five times (one, two, one), so A v one is five times (one, two, one). Its length is five root six. So sigma one is five root six, and u one is one over root six, times (one, two, one). In the same way, A times the vector (four, minus three), is the vector (twenty five, zero, minus twenty five), so A v two is five times (one, zero, minus one). Its length is five root two. So sigma two is five root two, and u two is one over root two, times (one, zero, minus one). Now the layers. In sigma one u one v one transpose, the numbers five root six, one over root six and one fifth multiply to one. So the first layer is the column (one, two, one), times the row (three, four). Its first row is (three, four), its second row is (six, eight), and its third row is (three, four). This is A one.

In the second layer, five root two, one over root two and one fifth also multiply to one. So it is the column (one, zero, minus one), times the row (four, minus three). Its first row is (four, minus three), its second row is (zero, zero), and its third row is (minus four, three). Add the two layers, entry by entry, and we get A back: three plus four is seven, four minus three is one, and so on. So A one is A without its second layer. How good an approximation is it?

How far apart are two matrices?

To answer, we need a length for matrices. The Frobenius norm of a matrix is the square root of the sum of the squares of all its entries. It is the length of the m n entries, read as one long vector. Adding up column by column, its square is the sum of the squared lengths of the columns. An orthogonal matrix keeps the length of every column. So multiplying by an orthogonal matrix, on the left or on the right, does not change the Frobenius norm. Apply this to A equals U sigma V transpose. The Frobenius norm of A equals that of capital sigma, whose only nonzero entries are the singular values. So the squared Frobenius norm of A is sigma one squared, plus and so on, up to sigma r squared.

And A minus A k has the singular values sigma k plus one, down to sigma r. So the squared error of the truncation is the sum of the squares of the singular values we left out. Check it on the example. The squares of the entries of A are forty nine, one, thirty six, sixty four, one, and forty nine. They add up to two hundred, which is one hundred fifty plus fifty, sigma one squared plus sigma two squared. The leftover A minus A one is the second layer. The squares of its entries are sixteen, nine, zero, zero, sixteen, and nine, which add up to fifty, sigma two squared. So A one keeps three quarters of the squared length of A, and its relative error, the square root of fifty over two hundred, is one half.

The second way to measure a matrix asks how much it can stretch a vector. The operator norm of A is the largest length of A x, over all unit vectors x. By the largest stretch theorem of lecture fifty one, it is sigma one, reached at x equal to v one. Here, for the two by two matrix with rows (two, one), and (one, two), the unit circle becomes an ellipse. The longest arrow to the ellipse has length sigma one, which is three. For A minus A k, the largest singular value is sigma k plus one. So in the operator norm, the error of the truncation is sigma k plus one, the first singular value we left out. In our example, both errors of A one equal sigma two, five root two, because the leftover is a single layer.

The Eckart–Young theorem

Now the main theorem, due to Eckart and Young. Let k be less than r, and let B be any real m by n matrix of rank at most k. Then the operator norm of A minus B is at least sigma k plus one, the error of A k. The same holds in the Frobenius norm. In words: among all matrices of rank at most k, the truncation A k is the closest to A, in both norms. There are infinitely many candidates, and the best one is simply the S V D, cut short. We prove the operator norm part. The proof combines several results of the course, so take it slowly, and pause if you need to. First, a fact about stretching.

Write a vector x in the orthonormal basis v one up to v n, with coefficients c j. Then A x is the sum of c j sigma j u j. Since the u's are orthonormal, Pythagoras gives the squared length of A x: the sum of sigma j squared times c j squared. Now take x in the span of the first k plus one vectors, v one up to v k plus one. Then only those coefficients can be nonzero, and each of their sigmas is at least sigma k plus one. So the length of A x is at least sigma k plus one times the length of x. Now the proof. B has rank at most k, so by the rank nullity theorem, its null space has dimension at least n minus k. And the span W of v one up to v k plus one has dimension k plus one.

The two dimensions add up to more than n. So by forced intersections, from lecture twenty four, the two subspaces share a nonzero vector. Scale it to a unit vector x. Since B x is zero, A minus B, times x, is just A x. And since x lies in W, the length of A x is at least sigma k plus one. So A minus B stretches a unit vector by at least sigma k plus one, and its operator norm is at least that much. This proves the first part. The Frobenius part follows by applying the first part once for each singular value of A minus B. The details are in the book.

For our example, no matrix of rank at most one comes closer to A than A one does: the distance five root two cannot be beaten, in either norm.

Compressing an image

Now an application. A grey scale image is a matrix: one entry for each pixel, its grey value, from zero for black to one for white. This landscape was generated from a formula for this course: a sky, a sun, two mountain ridges, and their reflection in a lake. It has two hundred forty rows and three hundred sixty columns, so it takes eighty six thousand four hundred numbers to store. We call this matrix X. A single layer is a very plain picture. Each of its rows is a multiple of the same row, v transpose, so every row has the same pattern, only lighter or darker. Here are the first three layers of X, with mid grey for zero.

Here are the singular values of X, on a logarithmic scale. They fall quickly. Sigma one is about one hundred seventy nine, sigma five is under five, sigma twenty is about one point two, and sigma fifty is about one half. To store X k, we keep k columns u j, with two hundred forty entries each, k rows v j transpose, with three hundred sixty entries each, and the k numbers sigma j. That is k times six hundred one numbers. With one layer, six hundred one numbers, less than one percent of the image, we get only bands: roughly, the brightness of each row and of each column.

With five layers, about three and a half percent of the numbers, the ridges appear. The relative error, in the Frobenius norm, is under six percent. With twenty layers, about fourteen percent of the numbers, the picture is hard to tell from the original at this size. The relative error is two and a half percent. With fifty layers, about thirty five percent, the error is about one percent. And by the Eckart Young theorem, for each k, no matrix of rank at most k is closer to the original.

Watch the layers add up, from one layer to fifty. In practice, image formats use a related idea. They cut the picture into small blocks, and use one fixed orthonormal basis, built from cosines, for every block. The S V D finds the best basis for each matrix, which is why it is used wherever data has a few dominant directions, from statistics to recommendation systems.

Try it yourself

You can try this yourself, on this lecture's page at Open Semester dot com. The slider sets k, the number of layers kept, and the picture in the middle is X k. With k equal to one, X one is only bands. The plot below marks the singular value that was kept, and the line under the pictures counts the numbers stored and gives the relative error. Move k up to five, and then to twenty. The ridges appear, the share of numbers stored grows slowly, and the error falls quickly.

The picture on the right is layer k on its own. The first layers carry the large shapes, and the late layers carry only fine detail. The panel at the bottom shows what is stored, arranged like our picture of a layer. On the left stand the k columns u, with two hundred forty entries each. On top lie the k rows v transpose, with three hundred sixty entries each. And in the corner, on the diagonal, are the k numbers sigma. Each new layer adds one column, one number and one row, six hundred one numbers in all. Try your own k, and compare the picture, the storage and the error.

What comes next: the Jordan normal form

Finally, a look ahead. The spectral theorem diagonalises a real symmetric matrix with one orthonormal basis. The S V D handles every matrix, with two orthonormal bases. What if we want a single basis, used on both sides, as in P inverse A P? From chapter eight, we know that diagonalising can fail. Here is an example. Take A with rows (seven, minus nine), and (one, one). Its trace is eight, and its determinant is seven plus nine, which is sixteen. So its characteristic polynomial is t squared minus eight t plus sixteen, which is t minus four, squared.

The matrix A minus four I has rows (three, minus nine), and (one, minus three). It is not zero, so its null space is only the line spanned by p one, equal to (three, one). There is one independent eigenvector, and A is not diagonalisable. The best substitute is a vector p two that the matrix A minus four I sends to p one. The second row gives x one minus three x two equals one, and x two equal to minus one gives p two, equal to (minus two, minus one). Then A p one is four p one, and A p two is p one plus four p two.

Written in full, A p one is four p one plus zero p two, and A p two is one p one plus four p two. These coefficients are the columns of the matrix of A in the basis p one, p two. So P inverse A P is the matrix with rows (four, one), and (zero, four): four on the diagonal, and a one just above it. Such a matrix is a Jordan block. The Jordan block J ell of lambda is ell by ell, with lambda on the diagonal, ones just above it, and zeros everywhere else. The Jordan normal form theorem says: for every complex square matrix A, there is an invertible P such that P inverse A P is block diagonal, with Jordan blocks on the diagonal. The blocks are unique, up to their order. Its proof belongs to a second course in linear algebra.

In the language of this course, each block gives one independent eigenvector. So the number of blocks for lambda is its geometric multiplicity, and their sizes add up to its algebraic multiplicity. A is diagonalisable exactly when every block has size one. And the largest block for lambda has the size of the exponent of t minus lambda in the minimal polynomial. That is the minimal polynomial test of lecture forty four, seen from the Jordan form. But the Jordan form is fragile. Change the zero below the diagonal of J two of four to a small number epsilon. The eigenvalues become four plus root epsilon and four minus root epsilon, so the matrix is diagonalisable, however small epsilon is.

That is why computations with real data use orthogonal matrices and the S V D. The Jordan form is above all a tool for understanding.

To sum up, and the road ahead

Let's sum up. The S V D writes A as a sum of rank one layers, largest first, and the truncation A k keeps the first k of them. Its error is sigma k plus one in the operator norm, and the square root of the sum of the remaining sigma j squared in the Frobenius norm. By the Eckart Young theorem, no matrix of rank at most k does better. For an image, this stores k times m plus n plus one numbers, instead of m times n. And a square matrix that cannot be diagonalised still has a Jordan normal form, the subject of a second course.

This was the last lecture. We began with arrows in the plane, and went on to systems of equations, matrices, vector spaces, linear maps, determinants, eigenvalues, inner products, and finally the spectral theorem and the S V D. Before the recitation, read section eleven point four of the course book, try problem eleven on sheet thirteen about compressing an image, and do the lecture check on this lecture's page at Open Semester dot com. Next comes recitation thirteen, and then the final exam. Thank you for learning with us.

In this lecture

  1. 0:00Today: the SVD at work
  2. 1:26Layers and truncation
  3. 4:42How far apart are two matrices?
  4. 7:03The Eckart–Young theorem
  5. 9:23Compressing an image
  6. 11:42Try it yourself
  7. 12:47What comes next: the Jordan normal form
  8. 15:50To sum up, and the road ahead

Materials

Try it

Compress an image with the SVD

X, the original

Loading the image…

Xk keeps the first k layers σjujvjT of the SVD of the 240 × 360 landscape X from the lecture. It needs k(240 + 360 + 1) = 601k numbers instead of 86 400. Move k and compare the picture, the storage and the relative error ‖X − Xk‖F / ‖X‖F. The picture on the right is layer k alone (mid grey is 0), and the plot marks how fast the singular values fall. The last panel shows what is stored: the k columns uj on the left, the k rows vjT on top and the k numbers σj on the diagonal in the corner between them, around their product Xk. Each new layer fills in entry by entry.

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.

  1. Question 1 of 3 Warm-up

    Let , with . Find , the square of the operator norm , and , where is the rank-one truncation of an SVD of .

    Hint 1 of 2

    is the sum of the squares of the entries (Definition 11.4.3). For the other two you need the singular values: they are the square roots of the eigenvalues of (Definition 11.3.2).

    Hint 2 of 2

    The eigenvalues of have sum (the trace) and product (the determinant), so they are and . Then (Definition 11.4.6) and (Corollary 11.4.7).

    Worked solution
    1. By Definition 11.4.3, .
    2. has trace and determinant , so its characteristic polynomial is . The singular values are and (Definition 11.3.2).
    3. Check with Proposition 11.4.4(b): .
    4. By Definition 11.4.6, , so . By Corollary 11.4.7 with , , so . Here is the single layer , so as well.
  2. Question 2 of 3 Core

    A real matrix has the singular values , and . Find . Then, over all real matrices of rank at most , find the smallest possible value of and of .

    Hint 1 of 2

    Proposition 11.4.4(b) gives from the singular values. For the rest, the Eckart–Young theorem (Theorem 11.4.8) names the closest matrix of rank at most .

    Hint 2 of 2

    The closest is the truncation , with . By Corollary 11.4.7, and .

    Worked solution
    1. By Proposition 11.4.4(b), , so .
    2. Here . By the Eckart–Young theorem (Theorem 11.4.8) with , every of rank at most has and . So the smallest values are reached at .
    3. By Corollary 11.4.7, and .
    4. So keeps of the in , and its relative error is .
  3. Question 3 of 3 Stretch

    Let . Find its eigenvalue , an eigenvector of the form , and the number of Jordan blocks in its Jordan normal form. Is diagonalisable?

    Diagonalisable?
    Hint 1 of 2

    Use the trace and the determinant, as in Example 11.4.13: .

    Hint 2 of 2

    and , so . Now find the null space of : each Jordan block gives one independent eigenvector.

    Worked solution
    1. and , so and .
    2. . Its first row is times the second, so the null space is the line . With : , so and . Check: .
    3. There is one independent eigenvector, so the geometric multiplicity of is : one Jordan block, and its size is the algebraic multiplicity . The Jordan form is (Theorem 11.4.12).
    4. The block has size , so is not diagonalisable. (For a basis as in Example 11.4.13, solve : the first row gives , and gives .)

Found a mistake, or something not working on this page? Report it and we'll fix it. See what we've corrected.