Hyoungseo Son
Linear Algebra
Contents · Linear Algebra

Part 1 · Vectors & Spaces

Part 4 · Orthogonality

Part 5 · Eigenvalues

Part 6 · Singular Value Decomposition

  • The Singular Value Decomposition

Part 6 · Singular Value Decomposition

The Singular Value Decomposition

7 min read

Eigenvalues demanded a square, cooperative matrix. The singular value decomposition demands nothing. Every matrix, any shape, real or rectangular, factors into a rotation, a set of axis-aligned stretches, and another rotation. It is the closest thing linear algebra has to a universal normal form.

The factorization

For any real ARm×nA \in \mathbb{R}^{m\times n} there exist orthogonal matrices UU and VV and a diagonal Σ\Sigma so that

A=UΣV,UU=Im,VV=In,A = U\,\Sigma\,V^{\top}, \qquad U^{\top}U = I_m,\quad V^{\top}V = I_n, Σ=diag(σ1,,σr),σ1σ2σr>0.\Sigma = \operatorname{diag}(\sigma_1,\dots,\sigma_r), \qquad \sigma_1 \ge \sigma_2 \ge \dots \ge \sigma_r > 0 .

The σi\sigma_i are the singular values, the columns uiu_i of UU the left singular vectors, and the columns viv_i of VV the right singular vectors. The defining relation is Avi=σiuiA v_i = \sigma_i u_i: each right singular vector is sent to a scaled left singular vector. Equivalently AA is a sum of rank-one pieces,

A=i=1rσiuivi.A = \sum_{i=1}^{r} \sigma_i\, u_i v_i^{\top} .

The viv_i are the orthonormal eigenvectors of AAA^{\top}A, the uiu_i those of AAAA^{\top}, and σi2\sigma_i^{2} their shared eigenvalues.1

The geometry: sphere to ellipsoid

Read A=UΣVA = U\Sigma V^{\top} right to left on a unit vector xx. First VV^{\top} rotates xx into the singular basis. Then Σ\Sigma stretches coordinate ii by σi\sigma_i. Then UU rotates the result out. Writing x=i(vix)vix = \sum_i (v_i^{\top}x)\, v_i,

Ax=i=1rσi(vix)ui.A x = \sum_{i=1}^{r} \sigma_i\, (v_i^{\top} x)\, u_i .

So the image of the unit sphere is an ellipsoid whose semi-axes are the vectors σiui\sigma_i u_i: the directions come from UU, the lengths are the singular values. The rank rr is exactly the number of nonzero σi\sigma_i, the number of axes the ellipsoid actually has.

A maps the unit circle to an ellipseinteractive
domain: unit circle
image: ellipse
v₁ , σ₁u₁v₂ , σ₂u₂
A = [[2.0, 0.0], [1.0, 1.0]]
σ₁
2.29
σ₂
0.87
σ₁·σ₂
2.00
|det A|
2.00

The circle stretches into an ellipse with semi-axes σ₁ and σ₂. Their product σ₁σ₂ equals |det A|, the area scale factor.

Set the four entries of a 2×2 A. Left: the unit circle and its right singular directions v₁, v₂. Right: the image ellipse, with the left singular directions u₁, u₂ scaled by σ₁, σ₂. Both panels share one scale, so you watch the circle become the ellipse. σ₁σ₂ tracks |det A|; drive σ₂ to 0 and the ellipse collapses to a segment (rank 1).

Rank, approximation, and the pseudoinverse

Truncating the sum after kk terms gives the best rank-kk approximation of AA,

Ak=i=1kσiuivi,AAk2=σk+1,AAkF2=i>kσi2.A_k = \sum_{i=1}^{k} \sigma_i\, u_i v_i^{\top}, \qquad \lVert A - A_k \rVert_2 = \sigma_{k+1}, \qquad \lVert A - A_k \rVert_F^{2} = \sum_{i>k} \sigma_i^{2} .

No rank-kk matrix comes closer in either the spectral or the Frobenius norm. This is the Eckart-Young theorem, and it is why the SVD underlies image compression, denoising, and latent-factor models.2

When AA is not invertible the SVD still supplies the right inverse. Inverting each nonzero stretch gives the pseudoinverse

A+=VΣ+U,Σ+=diag ⁣(1σ1,,1σr) ⁣ ⁣,A^{+} = V\,\Sigma^{+}\,U^{\top}, \qquad \Sigma^{+} = \operatorname{diag}\!\left(\tfrac{1}{\sigma_1},\dots,\tfrac{1}{\sigma_r}\right)^{\!\top}\!,

and x=A+bx = A^{+}b is the least-squares solution of Ax=bAx = b of smallest norm.

PCA is the SVD of centered data

Center a data matrix XRn×dX \in \mathbb{R}^{n\times d} by subtracting the column means, then take X=UΣVX = U\Sigma V^{\top}. The right singular vectors viv_i are the principal directions, the eigenvectors of the sample covariance 1n1XX\tfrac{1}{n-1}X^{\top}X, and the variance captured along viv_i is σi2/(n1)\sigma_i^{2}/(n-1). Principal component analysis is not a separate algorithm: it is the SVD of the centered data, and the leading singular values say how much of the spread lives in how few directions.1

A 2×2 by hand

Take

A=[2011],AA=[5111].A = \begin{bmatrix} 2 & 0 \\ 1 & 1 \end{bmatrix}, \qquad A^{\top}A = \begin{bmatrix} 5 & 1 \\ 1 & 1 \end{bmatrix} .

The singular values are the square roots of the eigenvalues of AAA^{\top}A. For a symmetric 2×22\times2 matrix the eigenvalues follow from the trace and determinant. Here tr=6\operatorname{tr} = 6 and det=5111=4\det = 5\cdot 1 - 1\cdot 1 = 4, so

λ=6±62442=3±5,λ15.236,λ20.764.\lambda = \frac{6 \pm \sqrt{6^{2} - 4\cdot 4}}{2} = 3 \pm \sqrt{5}, \qquad \lambda_1 \approx 5.236,\quad \lambda_2 \approx 0.764 .

Taking square roots,

σ1=3+52.288,σ2=350.874.\sigma_1 = \sqrt{3+\sqrt5} \approx 2.288, \qquad \sigma_2 = \sqrt{3-\sqrt5} \approx 0.874 .

Two checks. The product of the singular values is the area scale factor: σ1σ2=det(AA)=4=2\sigma_1\sigma_2 = \sqrt{\det(A^{\top}A)} = \sqrt{4} = 2, and indeed detA=2101=2\det A = 2\cdot 1 - 0\cdot 1 = 2. The sum of their squares is the squared Frobenius norm: σ12+σ22=6=22+02+12+12\sigma_1^{2} + \sigma_2^{2} = 6 = 2^{2} + 0^{2} + 1^{2} + 1^{2}. Both hold, so the ellipse this AA draws has semi-axes near 2.292.29 and 0.870.87, enclosing an area πσ1σ2=2π\pi\,\sigma_1\sigma_2 = 2\pi times that of the unit circle.

Footnotes

  1. Trefethen & Bau, Numerical Linear Algebra (1997). 2

  2. Strang, Introduction to Linear Algebra (5th ed., 2016).