Scientia sine finibus

Linear Algebra / Unit 7, Symmetric Matrices / Topic 7.3

Units and Topics

Unit 7. Symmetric Matrices

7.3 The Singular Value Decomposition

The spectral theorem diagonalizes a symmetric matrix with one orthonormal basis. The singular value decomposition does the same work for any matrix, of any shape, by using two orthonormal bases. It writes each matrix as A = UΣVT. This topic builds the factorization, shows what it means in a picture, and uses it to find the rank, the best approximation of a matrix, and the solution of least squares problems that Topic 6.4 could not finish.

You need Topics 4.4, 6.3, 6.4, 7.1, and 7.2 for this topic.

1. Two Bases in Place of One

An eigenvector equation Ax = λx needs a square matrix, because the input and the output must be in the same space. Even for a square matrix, the eigenvectors are usually not perpendicular, and sometimes there are not enough of them.

The singular value decomposition uses one orthonormal basis v₁, v₂, … for the inputs and another orthonormal basis u₁, u₂, … for the outputs. The matrix sends each input basis vector to a multiple of the matching output basis vector.

Avi = σiui

The numbers σ₁, σ₂, … are called the singular values of A. They are never negative, and they are listed from the largest to the smallest. The vectors vi are called the right singular vectors, and the vectors ui are called the left singular vectors.

2. Where the Bases Come From

From Topic 7.2, the matrix ATA is symmetric and positive semidefinite for any matrix A. By the spectral theorem, it has orthonormal eigenvectors, and its eigenvalues are not negative.

  • The vectors vi are the orthonormal eigenvectors of ATA.
  • The singular values are the square roots of the eigenvalues of ATA: σi = √λi.
  • For each σi that is not zero, ui = Avi / σi.

The vectors ui built this way are orthonormal. For two different indexes i and j,

(Avi) · (Avj) = vi · (ATAvj)move A to the other side as its transpose(Avi) · (Avj) = σj²(vi · vj)vj is an eigenvector of ATA(Avi) · (Avj) = 0the eigenvectors are perpendicular

With i = j, the same calculation gives |Avi|² = σi², so the length of Avi is σi, and ui is a unit vector.

3. An Example

A = 3045 ATA = 25202025

The eigenvalues of ATA are 45 and 5, with the unit eigenvectors v₁ = (1, 1)/√2 and v₂ = (−1, 1)/√2. The singular values are σ₁ = √45, which is about 6.71, and σ₂ = √5, which is about 2.24.

Av₁ = 1/√2 39multiplyu₁ = 1/√10 13divide by σ₁ = √45Av₂ = 1/√2 −31multiplyu₂ = 1/√10 −31divide by σ₂ = √5

The vectors u₁ and u₂ are perpendicular unit vectors, as Part 2 showed.

The eigenvalues of A itself are 3 and 5, because A is triangular. The singular values are different numbers. The product is the same in size: σ₁σ₂ = √225 = 15, and the determinant of A is 15.

4. The Factorization A = UΣVT

Put the vectors vi in the columns of a matrix V, and the vectors ui in the columns of a matrix U. Put the singular values on the diagonal of a matrix Σ. The equations Avi = σiui, written together, are AV = UΣ. The matrix V is orthogonal, so multiplying by VT on the right gives the factorization.

The singular value decomposition. Each matrix A can be written as A = UΣVT. The matrices U and V are orthogonal, and Σ is zero except for the singular values on its diagonal.

For the example,

U = 1/√10 1−331 Σ = √4500√5 VT = 1/√2 11−11

The picture

The three factors act one after another, from right to left.

  • VT is orthogonal. It turns the input so that v₁ and v₂ land on the coordinate axes.
  • Σ stretches along the axes by the factors σ₁ and σ₂.
  • U is orthogonal. It turns the axes to the directions u₁ and u₂.

Any map of the plane is a turn or a reflection, then a stretch along the axes, then another turn or reflection. The unit circle goes to an ellipse. The half-lengths of its axes are the singular values, and the axes point along u₁ and u₂.

Try it: the singular vectors of a matrix

The sliders set the entries of the matrix with the rows a, b and c, d. The dashed arrows on the gray unit circle are the input vectors v₁ and v₂. The solid arrows are their images σ₁u₁ and σ₂u₂, which are the half-axes of the green ellipse. The drawing starts with one half of the matrix of Part 3, so that the ellipse fits on the grid.

5. Matrices of Any Shape, and the Rank

The construction of Part 2 never used a square matrix. For a matrix with m rows and n columns, V is n by n, U is m by m, and Σ has the same shape as A.

The number of singular values that are not zero is the rank r of the matrix. The singular vectors give orthonormal bases for the four subspaces of Topic 4.4.

VectorsSubspace
v₁, …, vrThe row space of A
The remaining vectors vThe null space of A
u₁, …, urThe column space of A
The remaining vectors uThe left null space of A

A sum of rank one matrices

Multiplying out UΣVT gives one term for each singular value that is not zero.

A = σ₁u₁v₁T + σ₂u₂v₂T + … + σrurvrT

Each term is a matrix of rank 1. This is the same kind of sum as the sum of projections in Topic 7.1, with two sets of vectors.

A matrix of rank 1

A = 1224 ATA = 5101020

The eigenvalues of ATA are 25 and 0, so σ₁ = 5 and σ₂ = 0. The rank is 1. The vector v₁ = (1, 2)/√5 is the unit vector along the row space, and u₁ = Av₁/5 = (1, 2)/√5 is the unit vector along the column space. The whole matrix is the single term A = 5u₁v₁T.

6. The Best Approximation of a Matrix

The terms of the sum are ordered by size, because σ₁ is the largest singular value. Keeping only the first k terms gives a matrix of rank k. A theorem of Eckart and Young states that this matrix is the closest matrix of rank k to A.

A photograph is a matrix of brightness values. When its singular values fall quickly, a few terms of the sum reproduce the picture well, and the terms need much less storage than the full matrix. In statistics, the same idea finds the directions in which a set of data varies the most, which is called principal component analysis.

The largest singular value has a direct meaning: σ₁ is the largest value of |Ax| over all unit vectors x. It measures the largest stretch that the matrix can produce.

7. The Pseudoinverse and Least Squares

Topic 6.4 solved Ax = b in the least squares sense when the columns of A are independent. When the columns are dependent, many vectors give the same smallest error, and Topic 6.4 left the choice open. The singular value decomposition makes the choice.

The pseudoinverse of A is written A⁺. It inverts A on the part where A can be inverted, and it sends the rest to zero. Each nonzero singular value σ is replaced by 1/σ, and the roles of U and V are exchanged.

A⁺ = 1/σ₁v₁u₁T + … + 1/σrvrurT

The vector A⁺b is a least squares solution of Ax = b. Among all of the least squares solutions, it is the one with the smallest length. It lies in the row space, and it has no part in the null space.

The rank 1 example

For the matrix with the rows 1, 2 and 2, 4, the pseudoinverse is (1/5)v₁u₁T.

A⁺ = 1/25 1224 b = 510 A⁺b = 12

The system is x + 2y = 5, written twice. Its solutions are (5, 0) + t(−2, 1). The pseudoinverse picks (1, 2), which is the solution that is perpendicular to the null space direction (−2, 1). No other solution is shorter.

When A is square and invertible, the pseudoinverse is the inverse. When A has independent columns, the pseudoinverse gives the least squares solution of Topic 6.4.

Common Mistakes

  • Taking the eigenvalues of A as its singular values. The singular values are the square roots of the eigenvalues of ATA. The two sets of numbers agree only for special matrices, such as positive semidefinite matrices.
  • Forgetting the square root, and reporting the eigenvalues of ATA as the singular values.
  • Writing a negative singular value. A singular value is never negative. A sign is carried by the vectors u or v.
  • Finding U from AAT separately, with signs that do not match V. Use ui = Avi / σi, so that each u is paired with its v.
  • Writing the factors in the wrong order, or using V in place of VT.
  • Counting the singular values that are zero when finding the rank.

Summary

FactStatement
Singular value decompositionA = UΣVT, with orthogonal U and V
Singular valuesThe square roots of the eigenvalues of ATA, never negative
Singular vectorsAvi = σiui
PictureA turn, a stretch along the axes, and another turn. The unit circle goes to an ellipse with the half-lengths σ₁ and σ₂
RankThe number of singular values that are not zero
Best approximationThe first k terms of σ₁u₁v₁T + σ₂u₂v₂T + …
PseudoinverseA⁺b is the shortest least squares solution of Ax = b

Practice

Work each problem on paper first. Then open the answer to check your work.

1. Find the singular values of 200−3.

ATA is the diagonal matrix with the entries 4 and 9. The singular values are the square roots, listed from the largest: 3 and 2.

The eigenvalue −3 of A gives the singular value 3. A singular value is never negative.

2. Find the singular value decomposition of A = 0210.

ATA = 1004the eigenvalues are 4 and 1σ₁ = 2with v₁ = (0, 1)σ₂ = 1with v₂ = (1, 0)u₁ = Av₁/2 = (1, 0)u₂ = Av₂/1 = (0, 1)

U = I, Σ = 2001, and VT = 0110.

3. Find the singular values of the shear 1101.

ATA = 1112, with the trace 3 and the determinant 1. Its eigenvalues are (3 + √5)/2 and (3 − √5)/2, which are about 2.618 and 0.382.

The singular values are the square roots, about 1.618 and 0.618. Their product is 1, which is the determinant of the shear.

4. Find the singular value and the singular vectors of the rank 1 matrix 3400.

ATA = 9121216the eigenvalues are 25 and 0σ₁ = 5with v₁ = (0.6, 0.8)u₁ = Av₁/5 = (1/5)(5, 0) = (1, 0)

The matrix is 5u₁v₁T.

5. Use the pseudoinverse of Part 7 to find the shortest least squares solution of x + 2y = 5 and 2x + 4y = 0.

A⁺b = 1/25 1224 50A⁺b = (0.2, 0.4)

The two equations cannot both be true. The vector (0.2, 0.4) gives the smallest error, and it is the shortest vector that does so.

6. Show that ATA and AAT have the same eigenvalues that are not zero.

Let ATAv = λv with λ not zero. Multiply both sides by A: AAT(Av) = λ(Av).

The vector Av is not zero, because ATAv is not zero. So Av is an eigenvector of AAT with the same eigenvalue λ.

Python Practice

Step 1. Find a singular value decomposition

The instruction np.linalg.svd gives three results. The first is the matrix U. The second is the list of singular values, from the largest to the smallest. The third is VT, which is already transposed. Three names with commas between them receive the three results.

Python

The singular values are 6.708 and 2.236, which are √45 and √5, as in Part 3. Python can give a column of U and the matching row of VT with the opposite signs. The product is the same.

Now find the singular values of the shear of Practice Problem 3, with the rows 1, 1 and 0, 1.

Python

Step 2. Rebuild the matrix

The instruction np.diag(s) makes the diagonal matrix Σ from the list of singular values. The product UΣVT should give the matrix A back.

Python

The result is the matrix A, apart from very small rounding errors.

Step 3. Compare with the eigenvalues of ATA

From Part 2, the singular values are the square roots of the eigenvalues of ATA. The instruction np.linalg.eigvalsh lists those eigenvalues from the smallest to the largest.

Python

The eigenvalues of ATA are 5 and 45, and their square roots are the singular values. The last line prints the eigenvalues of A itself, which are 3 and 5. They are not the singular values.

Step 4. The rank and the best approximation

The matrix below has 3 rows and 3 columns, but its third row is 2 times the second row minus the first row, so its rank is 2. The third singular value shows this.

Python

The third singular value is 0, so the rank is 2. The first singular value is much larger than the second, so the first term of the sum in Part 5 is already close to A. The code below calculates that term. Here U[:, 0] is the first column of U, and Vt[0] is the first row of VT.

Python

Each entry of this rank 1 matrix is close to the matching entry of A. Now add the second term, so that B holds the first two terms of the sum. The result should be A itself, because the third singular value is 0.

Python

Step 5. The pseudoinverse

The instruction np.linalg.pinv calculates the pseudoinverse of Part 7. The code below uses the rank 1 matrix of that part. The instruction np.linalg.solve cannot solve this system, because the matrix has no inverse.

Python

The pseudoinverse has the entries 0.04, 0.08, 0.08, and 0.16, which is the matrix A divided by 25. The solution is (1, 2). Now change the right side to (5, 0), as in Practice Problem 5. That system has no exact solution.

Python

The result (0.2, 0.4) is the shortest vector that makes the error as small as possible.

Quiz

This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.

Choose how your answers are checked

1. Find the singular values of 03−20.

2. The singular values of a matrix A are which numbers?

3. The singular values of a 2 by 2 matrix are 6 and 2. Find the absolute value of its determinant.

4. A matrix with 3 rows and 5 columns has the singular values 4, 2, and 0. What is its rank?

5. Let A = 1224 and b = (0, 5). Find the vector A⁺b, where A⁺ is the pseudoinverse of A.

Next: Topic 8.1, Complex Numbers