Unit 10, lesson 47

Singular Value Decomposition and Its Geometry

What the singular value decomposition says about a real matrix of any shape, how singular values pair right and left singular vectors, and how they give the rank, the kernel and the largest stretch.

  • Video 47
  • Geometry and Computation of the SVD

Three dials feed two meters. The first dial moves only the first meter, the second dial moves only the second, and the third dial moves both meters by the same amount. Three inputs are read through just two numbers, so some combination of turns must leave both meters still, and it is not obvious which inputs behave simply. This lesson shows that every real matrix, square or rectangular, has perpendicular input directions that it stretches onto perpendicular output directions or erases, and reads the rank, the kernel and the largest stretch from those directions.

Key terms

Singular value decomposition

Definition Let AA be a real m×nm \times n matrix, a map from Rn\mathbb{R}^n to Rm\mathbb{R}^m, and let q=min⁡(m,n)q = \min(m, n). A singular value decomposition, or SVD, of AA is a factorization

A=UΣV⊤A = U\Sigma V^{\top}

in which UU is an m×mm \times m orthogonal matrix, VV is an n×nn \times n orthogonal matrix, and Σ\Sigma is an m×nm \times n rectangular diagonal matrix. That means Σij=0\Sigma_{ij} = 0 whenever i≠ji \ne j, and the diagonal entries Σii=σi\Sigma_{ii} = \sigma_i for i=1,…,qi = 1, \dots, q satisfy

σ1≥σ2≥⋯≥σq≥0.\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_q \ge 0.

Every real matrix has a singular value decomposition, and the next card explains where the factors come from. Read from right to left, the factorization acts in three steps. First V⊤V^{\top} gives the coordinates of an input along the orthonormal columns of VV. Then Σ\Sigma multiplies the first qq coordinates by σ1,…,σq\sigma_1, \dots, \sigma_q, drops any coordinates beyond the mmth, and fills the remaining output coordinates with zeros when m>nm > n. Finally UU assembles the output from the orthonormal columns of UU. The orthogonal factors preserve lengths and angles and may include reflections as well as rotations, so every change of length happens in Σ\Sigma.

In plain words Every matrix does three simple things in turn. It measures the input along well-chosen perpendicular axes, stretches each measurement by a nonnegative factor or erases it, and lays the results along perpendicular axes of the output space. The input axes belong to the input space and the output axes to the output space, which may have a different dimension.

Example Tuples such as (1,1,2)(1, 1, 2) stand for column vectors on this page. The matrix

A=[101011]A = \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \end{bmatrix}

sends (x,y,z)(x, y, z) to (x+z,y+z)(x + z, y + z), the dials and meters of the opening. One SVD has

U=12[111−1],Σ=[300010],\begin{gathered} U = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \\[0.4em] \Sigma = \begin{bmatrix} \sqrt{3} & 0 & 0 \\ 0 & 1 & 0 \end{bmatrix}, \end{gathered}

and VV with columns v1=16(1,1,2)\mathbf{v}_1 = \tfrac{1}{\sqrt{6}}(1, 1, 2), v2=12(1,−1,0)\mathbf{v}_2 = \tfrac{1}{\sqrt{2}}(1, -1, 0) and v3=13(−1,−1,1)\mathbf{v}_3 = \tfrac{1}{\sqrt{3}}(-1, -1, 1). Follow the input x=(2,−1,1)\mathbf{x} = (2, -1, 1) through the factors. Its coordinates along the columns of VV are the dot products vi⋅x\mathbf{v}_i \cdot \mathbf{x},

V⊤x=[3/63/20].V^{\top}\mathbf{x} = \begin{bmatrix} 3/\sqrt{6} \\ 3/\sqrt{2} \\ 0 \end{bmatrix}.

The factor Σ\Sigma multiplies the first coordinate by 3\sqrt{3}, keeps the second and drops the third, which gives (3/2,3/2)(3/\sqrt{2}, 3/\sqrt{2}). Then UU combines its columns u1=12(1,1)\mathbf{u}_1 = \tfrac{1}{\sqrt{2}}(1, 1) and u2=12(1,−1)\mathbf{u}_2 = \tfrac{1}{\sqrt{2}}(1, -1) with these weights,

32 u1+32 u2=32[11]+32[1−1]=[30],\begin{aligned} \frac{3}{\sqrt{2}}\,\mathbf{u}_1 + \frac{3}{\sqrt{2}}\,\mathbf{u}_2 &= \frac{3}{2}\begin{bmatrix} 1 \\ 1 \end{bmatrix} + \frac{3}{2}\begin{bmatrix} 1 \\ -1 \end{bmatrix} \\[0.4em] &= \begin{bmatrix} 3 \\ 0 \end{bmatrix}, \end{aligned}

which agrees with the direct product Ax=(2+1,−1+1)=(3,0)A\mathbf{x} = (2 + 1, -1 + 1) = (3, 0).

Singular values

Definition The singular values of a real m×nm \times n matrix AA are the diagonal entries σ1≥⋯≥σq≥0\sigma_1 \ge \cdots \ge \sigma_q \ge 0 of Σ\Sigma in an SVD, where q=min⁡(m,n)q = \min(m, n). They are determined by AA alone, whichever SVD is used. The n×nn \times n matrix A⊤AA^{\top}A is symmetric, and x⊤A⊤Ax=∥Ax∥2≥0\mathbf{x}^{\top}A^{\top}A\mathbf{x} = \lVert A\mathbf{x} \rVert^2 \ge 0 for every x\mathbf{x}, so its eigenvalues are real and nonnegative. If they are listed with repetition as λ1≥⋯≥λn\lambda_1 \ge \cdots \ge \lambda_n, then

σi=λi,i=1,…,q,\sigma_i = \sqrt{\lambda_i}, \qquad i = 1, \dots, q,

and when n>mn > m the remaining eigenvalues λm+1,…,λn\lambda_{m+1}, \dots, \lambda_n are all 00. The positive singular values are also the square roots of the positive eigenvalues of the m×mm \times m matrix AA⊤AA^{\top}, with the same multiplicities.

This is also why an SVD exists. The spectral theorem gives an orthonormal basis v1,…,vn\mathbf{v}_1, \dots, \mathbf{v}_n of Rn\mathbb{R}^n made of eigenvectors of A⊤AA^{\top}A, listed so that their eigenvalues decrease. For each ii with σi>0\sigma_i > 0 set ui=Avi/σi\mathbf{u}_i = A\mathbf{v}_i / \sigma_i. These vectors are orthonormal, because

ui⋅uj=vi⊤A⊤Avjσiσj=σj2 (vi⋅vj)σiσj,\mathbf{u}_i \cdot \mathbf{u}_j = \frac{\mathbf{v}_i^{\top}A^{\top}A\mathbf{v}_j}{\sigma_i\sigma_j} = \frac{\sigma_j^2\,(\mathbf{v}_i \cdot \mathbf{v}_j)}{\sigma_i\sigma_j},

which is 11 when i=ji = j and 00 otherwise. The remaining vi\mathbf{v}_i satisfy Avi=0A\mathbf{v}_i = \mathbf{0}, since ∥Avi∥2=λi=0\lVert A\mathbf{v}_i \rVert^2 = \lambda_i = 0. Any orthonormal basis of Rm\mathbb{R}^m that extends the ui\mathbf{u}_i gives UU, and then AV=UΣAV = U\Sigma.

In plain words Singular values are the stretch factors of the map, listed from largest to smallest and never negative. A singular value of zero marks an input direction that the map erases.

Example For the matrix AA above,

A⊤A=[101011112]A^{\top}A = \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \\ 1 & 1 & 2 \end{bmatrix}

has eigenvalues 33, 11 and 00, with eigenvectors v1\mathbf{v}_1, v2\mathbf{v}_2 and v3\mathbf{v}_3. For instance A⊤A (1,1,2)=(3,3,6)A^{\top}A\,(1, 1, 2) = (3, 3, 6). Here q=2q = 2, so the singular values are σ1=3\sigma_1 = \sqrt{3} and σ2=1\sigma_2 = 1, and the eigenvalue 00 belongs to the extra input direction. The smaller matrix AA⊤AA^{\top} has rows (2,1)(2, 1) and (1,2)(1, 2) and eigenvalues 33 and 11, the same two squares.

Right and left singular vectors

Definition In an SVD A=UΣV⊤A = U\Sigma V^{\top} of a real m×nm \times n matrix, the columns v1,…,vn\mathbf{v}_1, \dots, \mathbf{v}_n of VV are the right singular vectors, an orthonormal basis of the input space Rn\mathbb{R}^n. The columns u1,…,um\mathbf{u}_1, \dots, \mathbf{u}_m of UU are the left singular vectors, an orthonormal basis of the output space Rm\mathbb{R}^m. Comparing columns in AV=UΣAV = U\Sigma and in A⊤U=VΣ⊤A^{\top}U = V\Sigma^{\top} gives

Avi=σiui,A⊤ui=σivi,i=1,…,q.\begin{gathered} A\mathbf{v}_i = \sigma_i\mathbf{u}_i, \qquad A^{\top}\mathbf{u}_i = \sigma_i\mathbf{v}_i, \\[0.4em] i = 1, \dots, q. \end{gathered}

When n>mn > m, the right singular vectors without a partner satisfy Avi=0A\mathbf{v}_i = \mathbf{0} for i>mi > m. When m>nm > n, the left singular vectors without a partner satisfy A⊤ui=0A^{\top}\mathbf{u}_i = \mathbf{0} for i>ni > n. Each vi\mathbf{v}_i is an eigenvector of A⊤AA^{\top}A and each ui\mathbf{u}_i is an eigenvector of AA⊤AA^{\top}, with eigenvalue σi2\sigma_i^2 when i≤qi \le q and eigenvalue 00 beyond.

In plain words Right singular vectors are input directions and left singular vectors are output directions. The map carries the iith right singular vector to the iith left one, stretched by σi\sigma_i, and sends a right singular vector without a partner to zero, so these perpendicular inputs go to perpendicular outputs or to zero. Other perpendicular pairs of inputs need not keep their right angle. The two vectors of a pair belong to the input space and the output space, which may even have different dimensions, so in general they are not two arrows in one picture.

Example For the matrix AA above, with u1=12(1,1)\mathbf{u}_1 = \tfrac{1}{\sqrt{2}}(1, 1) and u2=12(1,−1)\mathbf{u}_2 = \tfrac{1}{\sqrt{2}}(1, -1),

Av1=16[33]=3 u1,Av2=u2,Av3=0.\begin{gathered} A\mathbf{v}_1 = \frac{1}{\sqrt{6}}\begin{bmatrix} 3 \\ 3 \end{bmatrix} = \sqrt{3}\,\mathbf{u}_1, \\[0.4em] A\mathbf{v}_2 = \mathbf{u}_2, \qquad A\mathbf{v}_3 = \mathbf{0}. \end{gathered}

In the other direction A⊤u1=12(1,1,2)=3 v1A^{\top}\mathbf{u}_1 = \tfrac{1}{\sqrt{2}}(1, 1, 2) = \sqrt{3}\,\mathbf{v}_1. The inputs v1\mathbf{v}_1 and v2\mathbf{v}_2 are perpendicular in R3\mathbb{R}^3, and their images 3 u1\sqrt{3}\,\mathbf{u}_1 and u2\mathbf{u}_2 are perpendicular in R2\mathbb{R}^2. The third input direction has no partner, since R2\mathbb{R}^2 has room for only two perpendicular directions.

Largest stretch

Definition Let AA be a real m×nm \times n matrix with largest singular value σ1\sigma_1 and first right singular vector v1\mathbf{v}_1. Then

max⁡∥x∥=1∥Ax∥=σ1,\max_{\lVert \mathbf{x} \rVert = 1} \lVert A\mathbf{x} \rVert = \sigma_1,

and the maximum is attained at x=v1\mathbf{x} = \mathbf{v}_1, so σ1\sigma_1 equals the induced Euclidean norm ∥A∥2\lVert A \rVert_2. To see this, write a unit vector as x=c1v1+⋯+cnvn\mathbf{x} = c_1\mathbf{v}_1 + \cdots + c_n\mathbf{v}_n with c12+⋯+cn2=1c_1^2 + \cdots + c_n^2 = 1. Then Ax=σ1c1u1+⋯+σqcquqA\mathbf{x} = \sigma_1 c_1\mathbf{u}_1 + \cdots + \sigma_q c_q\mathbf{u}_q, and since the ui\mathbf{u}_i are orthonormal,

∥Ax∥2=∑i=1qσi2ci2≤σ12∑i=1nci2=σ12.\lVert A\mathbf{x} \rVert^2 = \sum_{i=1}^{q} \sigma_i^2 c_i^2 \le \sigma_1^2 \sum_{i=1}^{n} c_i^2 = \sigma_1^2.

When m≥nm \ge n the same computation shows that the smallest stretch of a unit vector is σn\sigma_n, attained at vn\mathbf{v}_n. For an invertible n×nn \times n matrix this gives the condition number κ2(A)=σ1/σn\kappa_2(A) = \sigma_1 / \sigma_n.

In plain words No unit input is stretched by more than σ1\sigma_1, and the first right singular vector is stretched by exactly that much. So the largest singular value measures the size of the map as its greatest stretch factor.

Example For the matrix AA above the largest stretch is 3\sqrt{3}, reached at v1\mathbf{v}_1, whose image 3 u1=(3/6)(1,1)\sqrt{3}\,\mathbf{u}_1 = (3/\sqrt{6})(1, 1) has length 3\sqrt{3}. The unit vector e3=(0,0,1)\mathbf{e}_3 = (0, 0, 1) goes to (1,1)(1, 1), of length 2<3\sqrt{2} < \sqrt{3}. A unit vector with coordinates c1,c2,c3c_1, c_2, c_3 along the right singular vectors goes to 3 c1u1+c2u2\sqrt{3}\,c_1\mathbf{u}_1 + c_2\mathbf{u}_2 with c12+c22=1−c32≤1c_1^2 + c_2^2 = 1 - c_3^2 \le 1. So the unit circle in the plane of v1\mathbf{v}_1 and v2\mathbf{v}_2 maps onto the ellipse with semiaxes 3 u1\sqrt{3}\,\mathbf{u}_1 and u2\mathbf{u}_2, and the whole unit sphere of R3\mathbb{R}^3 maps onto the filled region bounded by that ellipse. The component along the erased direction v3\mathbf{v}_3 pulls a point inward.

Rank from singular values

Definition Let A=UΣV⊤A = U\Sigma V^{\top} be an SVD of a real m×nm \times n matrix, and let rr be the number of positive singular values, counted with repetition. Then rank⁡A=r\operatorname{rank} A = r, and

Col⁡A=span⁡{u1,…,ur},Null⁡A=span⁡{vr+1,…,vn},Row⁡A=span⁡{v1,…,vr},Null⁡A⊤=span⁡{ur+1,…,um},\begin{aligned} \operatorname{Col} A &= \operatorname{span}\{\mathbf{u}_1, \dots, \mathbf{u}_r\}, \\[0.4em] \operatorname{Null} A &= \operatorname{span}\{\mathbf{v}_{r+1}, \dots, \mathbf{v}_n\}, \\[0.4em] \operatorname{Row} A &= \operatorname{span}\{\mathbf{v}_1, \dots, \mathbf{v}_r\}, \\[0.4em] \operatorname{Null} A^{\top} &= \operatorname{span}\{\mathbf{u}_{r+1}, \dots, \mathbf{u}_m\}, \end{aligned}

where a span of no vectors means {0}\{\mathbf{0}\}. The reason is that x=c1v1+⋯+cnvn\mathbf{x} = c_1\mathbf{v}_1 + \cdots + c_n\mathbf{v}_n goes to Ax=σ1c1u1+⋯+σrcrurA\mathbf{x} = \sigma_1 c_1\mathbf{u}_1 + \cdots + \sigma_r c_r\mathbf{u}_r. These outputs fill the span of u1,…,ur\mathbf{u}_1, \dots, \mathbf{u}_r, and the output is zero exactly when c1=⋯=cr=0c_1 = \cdots = c_r = 0. The same argument applied to A⊤ui=σiviA^{\top}\mathbf{u}_i = \sigma_i\mathbf{v}_i gives the other two lines. So the kernel is spanned by the right singular vectors with singular value zero together with the unpaired ones beyond index mm. All of this is exact. When singular values are computed in floating point, a tiny value may stand for an exact zero or for a genuinely small stretch, and treating it as zero is a separate decision that should be stated.

In plain words Count the nonzero stretch factors and you have the rank. The input directions with zero stretch, or with no output partner at all, make up the kernel, and the leftover output directions, perpendicular to everything the map reaches, make up the left null space.

Example The matrix AA above has singular values 3\sqrt{3} and 11, so its rank is 22. Its column space is all of R2\mathbb{R}^2 and its kernel is the line spanned by v3\mathbf{v}_3, which matches rank-nullity, 2+1=32 + 1 = 3. For that reason the input x+5v3\mathbf{x} + 5\mathbf{v}_3 produces the same output (3,0)(3, 0) as x=(2,−1,1)\mathbf{x} = (2, -1, 1), and so does every point of the line through x\mathbf{x} in the direction v3\mathbf{v}_3. A 3×23 \times 2 matrix with singular values 44 and 00 would instead have rank 11, a kernel spanned by v2\mathbf{v}_2, and a left null space spanned by u2\mathbf{u}_2 and u3\mathbf{u}_3.

Singular values versus eigenvalues

Definition Eigenvalues and singular values answer different questions. An eigenvalue of a square matrix AA is a number λ\lambda with Ax=λxA\mathbf{x} = \lambda\mathbf{x} for some nonzero x\mathbf{x}, so input and output are compared in the same space. A diagonalization A=PDP−1A = PDP^{-1} uses one basis on both sides, that basis need not be orthonormal, and over R\mathbb{R} it may not exist. Eigenvalues can be negative and need not be real. Singular values exist for every real matrix of any shape, are real and nonnegative, and come with two orthonormal bases, one for each space. For a square matrix

∣det⁡A∣=σ1σ2⋯σn,\lvert \det A \rvert = \sigma_1\sigma_2\cdots\sigma_n,

because det⁡U\det U and det⁡V\det V equal ±1\pm 1. If AA is symmetric with eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n, its singular values are ∣λ1∣,…,∣λn∣\lvert \lambda_1 \rvert, \dots, \lvert \lambda_n \rvert arranged in decreasing order, and if AA is also positive semidefinite the two lists coincide. Symmetric positive semidefinite matrices are the only real square matrices whose eigenvalues, counted with multiplicity, are exactly their singular values, so for every other real square matrix the two lists differ.

In plain words An eigenvector is a direction that the map sends back onto its own line. A singular pair joins an input direction to an output direction, usually a different one, by a nonnegative stretch. Signs and turning belong to the orthogonal factors, never to the singular values.

Example The matrix diag⁡(−3,1)\operatorname{diag}(-3, 1) has eigenvalues −3-3 and 11 but singular values 33 and 11. One SVD takes V=IV = I, Σ=diag⁡(3,1)\Sigma = \operatorname{diag}(3, 1) and U=diag⁡(−1,1)U = \operatorname{diag}(-1, 1), a reflection that carries the sign. The matrix

R=[0−120]R = \begin{bmatrix} 0 & -1 \\ 2 & 0 \end{bmatrix}

has characteristic polynomial χR(t)=t2+2\chi_R(t) = t^2 + 2, so it has no real eigenvalues at all. Still R⊤R=diag⁡(4,1)R^{\top}R = \operatorname{diag}(4, 1), so its singular values are 22 and 11, and R=UΣV⊤R = U\Sigma V^{\top} with V=IV = I, Σ=diag⁡(2,1)\Sigma = \operatorname{diag}(2, 1) and UU the counterclockwise quarter turn with columns (0,1)(0, 1) and (−1,0)(-1, 0). In both examples the absolute value of the determinant is the product of the singular values, 3=3⋅13 = 3 \cdot 1 and 2=2⋅12 = 2 \cdot 1.

Check yourself

  1. A real 3×43 \times 4 matrix AA has singular values 55, 22 and 00. Find its rank, the dimension of its kernel and the dimension of the kernel of A⊤A^{\top}. What is the largest length of AxA\mathbf{x} for a unit vector x\mathbf{x}?
Show the answer

The rank counts the positive singular values, so it is 22, not 33. The input space is R4\mathbb{R}^4, so the kernel has dimension 4−2=24 - 2 = 2. It is spanned by v3\mathbf{v}_3, whose singular value is 00, and by the unpaired v4\mathbf{v}_4. The output space is R3\mathbb{R}^3, so the kernel of A⊤A^{\top} has dimension 3−2=13 - 2 = 1 and is spanned by u3\mathbf{u}_3. The largest stretch is σ1=5\sigma_1 = 5, reached at v1\mathbf{v}_1.

  1. Find the singular values, the rank and the largest stretch of the matrix below, and give a full SVD.
M=[300−200]M = \begin{bmatrix} 3 & 0 \\ 0 & -2 \\ 0 & 0 \end{bmatrix}
Show the answer

The product M⊤M=diag⁡(9,4)M^{\top}M = \operatorname{diag}(9, 4) has eigenvalues 99 and 44 with eigenvectors e1\mathbf{e}_1 and e2\mathbf{e}_2, so the singular values are 33 and 22, the rank is 22, and the largest stretch is 33, at e1\mathbf{e}_1. Take V=IV = I. Then u1=Me1/3=(1,0,0)\mathbf{u}_1 = M\mathbf{e}_1 / 3 = (1, 0, 0) and u2=Me2/2=(0,−1,0)\mathbf{u}_2 = M\mathbf{e}_2 / 2 = (0, -1, 0), and u3=(0,0,1)\mathbf{u}_3 = (0, 0, 1) completes the basis and spans the kernel of M⊤M^{\top}. So U=diag⁡(1,−1,1)U = \operatorname{diag}(1, -1, 1) and

Σ=[300200].\Sigma = \begin{bmatrix} 3 & 0 \\ 0 & 2 \\ 0 & 0 \end{bmatrix}.

The product UΣU\Sigma is MM. The negative entry is absorbed by u2\mathbf{u}_2, and the singular value stays 22.

  1. The shear BB with rows (1,1)(1, 1) and (0,1)(0, 1) has the eigenvalue 11 twice. Someone concludes that its singular values are 11 and 11. Test the claim with the unit vector x=12(1,1)\mathbf{x} = \tfrac{1}{\sqrt{2}}(1, 1), then find the singular values.
Show the answer

The image is Bx=12(2,1)B\mathbf{x} = \tfrac{1}{\sqrt{2}}(2, 1), of length 5/2≈1.58\sqrt{5/2} \approx 1.58. The largest singular value is the largest stretch, so it exceeds 11 and the claim is false. To find the singular values, use

B⊤B=[1112],B^{\top}B = \begin{bmatrix} 1 & 1 \\ 1 & 2 \end{bmatrix},

whose characteristic polynomial χB⊤B(t)=t2−3t+1\chi_{B^{\top}B}(t) = t^2 - 3t + 1 has roots (3±5)/2(3 \pm \sqrt{5})/2. Since ((5±1)/2)2=(3±5)/2\bigl((\sqrt{5} \pm 1)/2\bigr)^2 = (3 \pm \sqrt{5})/2, the singular values are

σ1=1+52≈1.618,σ2=5−12≈0.618.\begin{aligned} \sigma_1 &= \frac{1 + \sqrt{5}}{2} \approx 1.618, \\[0.4em] \sigma_2 &= \frac{\sqrt{5} - 1}{2} \approx 0.618. \end{aligned}

Their product is (5−1)/4=1=∣det⁡B∣(5 - 1)/4 = 1 = \lvert \det B \rvert, as it must be. A repeated eigenvalue does not determine how unevenly the map stretches different directions.

How this lesson connects