Simple Algorithm
Machine Learning · Convergence · 30 min

Linear Algebra for ML: Eigenvectors & the SVD

Spectral theorems, low-rank approximation and why the SVD is everywhere.

Three facts carry a remarkable share of machine learning: symmetric matrices diagonalize in an orthonormal basis, every matrix has a singular value decomposition, and truncating that decomposition gives the best low-rank approximation there is. This lesson proves all three, then uses them to explain least squares, conditioning, the stability of eigenvectors and the randomized algorithms that make the SVD affordable at scale.

What you’ll learn

  • Prove the spectral theorem for real symmetric matrices, characterize positive semidefinite matrices, and show that every Gram matrix is positive semidefinite.
  • Derive the Rayleigh-quotient and Courant–Fischer characterizations of eigenvalues, and use them to prove Weyl's perturbation bound; state the Davis–Kahan bound for eigenvectors.
  • Construct the SVD from the spectral theorem and prove the Eckart–Young–Mirsky theorem.
  • Express least squares through the pseudoinverse, quantify conditioning, derive key matrix-calculus identities, and state the error bound of randomized SVD.

The spectral theorem and positive semidefinite matrices

DerivationProof
  1. λ v∗v=v∗Av=(Av)∗v=λˉ v∗v⟹λ=λˉ\lambda\,\mathbf v^*\mathbf v=\mathbf v^*A\mathbf v=(A\mathbf v)^*\mathbf v=\bar\lambda\,\mathbf v^*\mathbf v\quad\Longrightarrow\quad\lambda=\bar\lambda

    Eigenvalues are real. Let Av=λvA\mathbf v=\lambda\mathbf v with v∈Cd\mathbf v\in\C^d nonzero, and write v∗\mathbf v^* for the conjugate transpose. Because AA is real and symmetric, (Av)∗=v∗A(A\mathbf v)^*=\mathbf v^*A, so

  2. λ1 u1⊤u2=(Au1)⊤u2=u1⊤Au2=λ2 u1⊤u2⟹(λ1−λ2) u1⊤u2=0\lambda_1\,\mathbf u_1^\top\mathbf u_2=(A\mathbf u_1)^\top\mathbf u_2=\mathbf u_1^\top A\mathbf u_2=\lambda_2\,\mathbf u_1^\top\mathbf u_2\quad\Longrightarrow\quad(\lambda_1-\lambda_2)\,\mathbf u_1^\top\mathbf u_2=0

    Eigenvectors of distinct eigenvalues are orthogonal. Move AA across the inner product:

  3. q1⊤Aw=(Aq1)⊤w=λ1 q1⊤w=0\mathbf q_1^\top A\mathbf w=(A\mathbf q_1)^\top\mathbf w=\lambda_1\,\mathbf q_1^\top\mathbf w=0

    Induction on dd. The characteristic polynomial has a root, real by the first step, so there is a real unit eigenvector q1\mathbf q_1. Its orthogonal complement W=q1⊥W=\mathbf q_1^\perp is invariant under AA, because for w∈W\mathbf w\in W:

  4. A=QΛQ⊤,Q=[q1 ⋯ qd]A=Q\Lambda Q^\top,\qquad Q=[\mathbf q_1\ \cdots\ \mathbf q_d]

    AA restricted to the (d−1)(d-1)-dimensional space WW is again symmetric, so by induction WW has an orthonormal eigenbasis q2,…,qd\mathbf q_2,\dots,\mathbf q_d. Together with q1\mathbf q_1 it diagonalizes AA:

For symmetric AA the following are equivalent, and define a positive semidefinite (PSD) matrix, written A⪰0A\succeq0: (i) x⊤Ax≥0\mathbf x^\top A\mathbf x\ge0 for every x\mathbf x; (ii) every eigenvalue is ≥0\ge0; (iii) A=B⊤BA=B^\top B for some matrix BB (take B=Λ1/2Q⊤B=\Lambda^{1/2}Q^\top); (iv) AA is a Gram matrix, Aij=bi⊤bjA_{ij}=\mathbf b_i^\top\mathbf b_j for some vectors bi\mathbf b_i (the columns of BB). Strict inequalities give positive definite matrices, exactly those with a Cholesky factorization A=LL⊤A=LL^\top, LL lower triangular with positive diagonal. Cholesky costs about d3/3d^3/3 operations, half of a general LU factorization, and is how positive definite systems are solved, how Gaussian samples μ+Lz\boldsymbol\mu+L\mathbf z are drawn and how log⁡det⁡A=2∑ilog⁡Lii\log\det A=2\sum_i\log L_{ii} is computed.

Machine learning is full of PSD matrices. A covariance matrix is one, since v⊤Sv\mathbf v^\top S\mathbf v is a variance. So is any kernel Gram matrix Kij=⟨φ(xi),φ(xj)⟩K_{ij}=\langle\varphi(\mathbf x_i),\varphi(\mathbf x_j)\rangle, because c⊤Kc=∥∑iciφ(xi)∥2≥0\mathbf c^\top K\mathbf c=\norm{\sum_ic_i\varphi(\mathbf x_i)}^2\ge0, the fact behind every kernel method. So is the Hessian of a twice-differentiable convex function.

Check your understanding

Which of these symmetric matrices is not positive semidefinite?

  1. (1−1−11)\begin{pmatrix}1&-1\\-1&1\end{pmatrix}
  2. (2112)\begin{pmatrix}2&1\\1&2\end{pmatrix}
  3. (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix}
  4. (4000)\begin{pmatrix}4&0\\0&0\end{pmatrix}
Show the answer

C. (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix}

Its eigenvalues are 33 and −1-1 (eigenvectors (1,1)(1,1) and (1,−1)(1,-1)): x=(1,−1)\mathbf x=(1,-1) gives x⊤Ax=1−2−2+1=−2<0\mathbf x^\top A\mathbf x=1-2-2+1=-2<0. Positive entries do not make a matrix PSD; the off-diagonal entries must be small relative to the diagonal, for a 2×22\times2 matrix a122≤a11a22a_{12}^2\le a_{11}a_{22} with nonnegative diagonal.

Rayleigh quotients, Courant–Fischer and perturbation

Sort the eigenvalues of a symmetric AA as λ1≥⋯≥λd\lambda_1\ge\dots\ge\lambda_d. In the eigenbasis, c=Q⊤x\mathbf c=Q^\top\mathbf x, the Rayleigh quotient is a weighted average of the eigenvalues, RA(x)=x⊤Axx⊤x=∑iλici2∑ici2R_A(\mathbf x)=\dfrac{\mathbf x^\top A\mathbf x}{\mathbf x^\top\mathbf x}=\dfrac{\sum_i\lambda_ic_i^2}{\sum_ic_i^2}, so λd≤RA(x)≤λ1\lambda_d\le R_A(\mathbf x)\le\lambda_1, with equality at the bottom and top eigenvectors. This is PCA in one line: the unit direction of greatest variance maximizes v⊤Sv\mathbf v^\top S\mathbf v, so it is the top eigenvector of the covariance, and the best kk-dimensional subspace maximizes tr⁡(V⊤SV)\operatorname{tr}(V^\top SV) over orthonormal V∈Rd×kV\in\R^{d\times k}, attained by the top kk eigenvectors.

Eigenvalues are stable. For symmetric AA and EE, RA+E(x)=RA(x)+RE(x)R_{A+E}(\mathbf x)=R_A(\mathbf x)+R_E(\mathbf x) and ∣RE(x)∣≤∥E∥2\abs{R_E(\mathbf x)}\le\norm{E}_2. Feeding this into both sides of Courant–Fischer gives Weyl's inequality: ∣λk(A+E)−λk(A)∣≤∥E∥2\abs{\lambda_k(A+E)-\lambda_k(A)}\le\norm{E}_2 for every kk. A sample covariance that is off by 0.10.1 in spectral norm has every eigenvalue within 0.10.1 of the truth.

Eigenvectors are not, unless the eigenvalues are separated. If λ1=λ2\lambda_1=\lambda_2, any direction in their span is a top eigenvector, and an arbitrarily small perturbation decides which one you get. The Davis–Kahan sin⁡θ\sin\theta theorem (Davis & Kahan, 1970) bounds the rotation by the perturbation divided by an eigengap. In the form of Yu, Wang & Samworth (2015), which needs only the population gap: for symmetric Σ\Sigma, Σ^\hat\Sigma with top eigenvectors v1\mathbf v_1, v^1\hat{\mathbf v}_1,

sin⁡∠(v^1,v1) ≤ 2 ∥Σ^−Σ∥2λ1(Σ)−λ2(Σ)\sin\angle(\hat{\mathbf v}_1,\mathbf v_1)\ \le\ \frac{2\,\norm{\hat\Sigma-\Sigma}_2}{\lambda_1(\Sigma)-\lambda_2(\Sigma)}
With an eigengap of 1 and an estimation error of 0.1, the estimated principal direction is within arcsin⁡0.2≈11.5∘\arcsin0.2\approx11.5^\circ of the true one. The same bound, applied to graph Laplacians, is a standard tool for analyzing spectral clustering.

The SVD and the best low-rank approximation

DerivationExistence, from the spectral theorem
  1. ui⊤uj=vi⊤A⊤Avjσiσj=λj vi⊤vjσiσj=δij\mathbf u_i^\top\mathbf u_j=\frac{\mathbf v_i^\top A^\top A\mathbf v_j}{\sigma_i\sigma_j}=\frac{\lambda_j\,\mathbf v_i^\top\mathbf v_j}{\sigma_i\sigma_j}=\delta_{ij}

    A⊤AA^\top A is symmetric and PSD, so A⊤A=VΛV⊤A^\top A=V\Lambda V^\top with orthonormal vi\mathbf v_i and λ1≥⋯≥λr>0=λr+1=…\lambda_1\ge\dots\ge\lambda_r>0=\lambda_{r+1}=\dots. Set σi=λi\sigma_i=\sqrt{\lambda_i} and, for i≤ri\le r, ui=Avi/σi\mathbf u_i=A\mathbf v_i/\sigma_i. These are orthonormal:

  2. A=A∑i=1nvivi⊤=∑i=1r(Avi) vi⊤=∑i=1rσi uivi⊤A=A\sum_{i=1}^{n}\mathbf v_i\mathbf v_i^\top=\sum_{i=1}^{r}(A\mathbf v_i)\,\mathbf v_i^\top=\sum_{i=1}^{r}\sigma_i\,\mathbf u_i\mathbf v_i^\top

    For i>ri>r, ∥Avi∥2=vi⊤A⊤Avi=0\norm{A\mathbf v_i}^2=\mathbf v_i^\top A^\top A\mathbf v_i=0, so Avi=0A\mathbf v_i=\mathbf 0. Expanding the identity in the basis of the vi\mathbf v_i finishes the construction:

DerivationProof
  1. ∥(A−B)x∥2=∥Ax∥2=∑i=1k+1σi2ci2 ≥ σk+12∑i=1k+1ci2=σk+12\norm{(A-B)\mathbf x}^2=\norm{A\mathbf x}^2=\sum_{i=1}^{k+1}\sigma_i^2c_i^2\ \ge\ \sigma_{k+1}^2\sum_{i=1}^{k+1}c_i^2=\sigma_{k+1}^2

    Spectral norm. BB has rank at most kk, so its null space has dimension at least n−kn-k and meets the (k+1)(k+1)-dimensional span of v1,…,vk+1\mathbf v_1,\dots,\mathbf v_{k+1} in some unit vector x=∑i≤k+1civi\mathbf x=\sum_{i\le k+1}c_i\mathbf v_i. Then Bx=0B\mathbf x=\mathbf 0, and

  2. σi+k(A)≤σi(A−B)⟹∥A−B∥F2=∑i≥1σi(A−B)2≥∑i≥1σi+k(A)2=∑i>kσi2\sigma_{i+k}(A)\le\sigma_i(A-B)\quad\Longrightarrow\quad\norm{A-B}_F^2=\sum_{i\ge1}\sigma_i(A-B)^2\ge\sum_{i\ge1}\sigma_{i+k}(A)^2=\sum_{i>k}\sigma_i^2

    Frobenius norm. Weyl's inequality for singular values (from Courant–Fischer applied to A⊤AA^\top A) gives σi+j−1(X+Y)≤σi(X)+σj(Y)\sigma_{i+j-1}(X+Y)\le\sigma_i(X)+\sigma_j(Y). Take X=A−BX=A-B, Y=BY=B and j=k+1j=k+1, where σk+1(B)=0\sigma_{k+1}(B)=0:

Predict before you look

A matrix has singular values 10,5,2,110,5,2,1. Its best rank-2 approximation has what relative error ∥A−A2∥F/∥A∥F\norm{A-A_2}_F/\norm{A}_F, in percent?

Show the answer

19.6 %

∥A−A2∥F2=22+12=5\norm{A-A_2}_F^2=2^2+1^2=5 and ∥A∥F2=100+25+4+1=130\norm{A}_F^2=100+25+4+1=130, so the relative error is 5/130≈0.196\sqrt{5/130}\approx0.196. The rank-2 approximation keeps 125/130≈96%125/130\approx96\% of the "energy" ∑σi2\sum\sigma_i^2, yet its relative error in norm is about 20%: energy fractions are squares, and they flatter. In spectral norm the error is σ3=2\sigma_3=2, also 20% of ∥A∥2=10\norm{A}_2=10.

For centered data X=UΣV⊤X=U\Sigma V^\top, the right singular vectors are the principal directions, σi2/n\sigma_i^2/n the variances along them and UΣU\Sigma the scores. Eckart–Young says that projecting onto the top kk directions minimizes the total squared reconstruction error among all rank-kk approximations, not just projections, and computing them from the SVD of XX avoids forming X⊤XX^\top X, which, as the next step shows, squares the condition number.

Least squares, conditioning and matrix calculus

DerivationLeast squares through the SVD
  1. ∥Xw−y∥2=∥Σc−y~∥2=∑i=1r(σici−y~i)2+∑i>ry~i2\norm{X\mathbf w-\mathbf y}^2=\norm{\Sigma\mathbf c-\tilde{\mathbf y}}^2=\sum_{i=1}^{r}\big(\sigma_ic_i-\tilde y_i\big)^2+\sum_{i>r}\tilde y_i^2

    Write X=UΣV⊤X=U\Sigma V^\top with UU and VV square orthogonal, and rotate: c=V⊤w\mathbf c=V^\top\mathbf w, y~=U⊤y\tilde{\mathbf y}=U^\top\mathbf y. Orthogonal maps preserve norms, so the residual splits coordinate by coordinate:

  2. w+=X+y=∑i=1rui⊤yσi vi,X+=VΣ+U⊤\mathbf w^+=X^+\mathbf y=\sum_{i=1}^{r}\frac{\mathbf u_i^\top\mathbf y}{\sigma_i}\,\mathbf v_i,\qquad X^+=V\Sigma^+U^\top

    The minimizers have ci=y~i/σic_i=\tilde y_i/\sigma_i for i≤ri\le r, with cr+1,…c_{r+1},\dots free (they span the null space of XX). Setting the free ones to zero gives the minimum-norm solution, the pseudoinverse applied to y\mathbf y:

  3. w^λ=(X⊤X+λI)−1X⊤y=∑i=1rσiσi2+λ (ui⊤y) vi → λ→0+  w+\hat{\mathbf w}_\lambda=(X^\top X+\lambda I)^{-1}X^\top\mathbf y=\sum_{i=1}^{r}\frac{\sigma_i}{\sigma_i^2+\lambda}\,(\mathbf u_i^\top\mathbf y)\,\mathbf v_i\ \xrightarrow{\ \lambda\to0^+\ }\ \mathbf w^+

    Noise in y\mathbf y along ui\mathbf u_i is multiplied by 1/σi1/\sigma_i, so tiny singular values make the solution unstable. Ridge regression replaces 1/σi1/\sigma_i by σi/(σi2+λ)\sigma_i/(\sigma_i^2+\lambda), a filter that is close to 1/σi1/\sigma_i for large σi\sigma_i and close to 00 for small ones:

The condition number κ(A)=σmax⁡/σmin⁡\kappa(A)=\sigma_{\max}/\sigma_{\min} quantifies that instability. For a square invertible system Ax=bA\mathbf x=\mathbf b, a perturbation δb\delta\mathbf b moves the solution by δx=A−1δb\delta\mathbf x=A^{-1}\delta\mathbf b, so ∥δx∥≤∥δb∥/σmin⁡\norm{\delta\mathbf x}\le\norm{\delta\mathbf b}/\sigma_{\min}, while ∥b∥≤σmax⁡∥x∥\norm{\mathbf b}\le\sigma_{\max}\norm{\mathbf x}. Dividing,

∥δx∥∥x∥ ≤ κ(A) ∥δb∥∥b∥.\frac{\norm{\delta\mathbf x}}{\norm{\mathbf x}}\ \le\ \kappa(A)\,\frac{\norm{\delta\mathbf b}}{\norm{\mathbf b}}.

Double precision stores numbers to a relative accuracy of about 10−1610^{-16}, so as a rule of thumb you lose about log⁡10κ\log_{10}\kappa significant digits. The normal equations use X⊤XX^\top X, whose condition number is κ(X)2\kappa(X)^2; Householder QR (X=QRX=QR, then solve Rw=Q⊤yR\mathbf w=Q^\top\mathbf y) and the SVD work on XX itself, which is why least-squares software uses them.

Function of x\mathbf x or XXGradientWhere it appears
b⊤x\mathbf b^\top\mathbf xb\mathbf blinear models
x⊤Ax\mathbf x^\top A\mathbf x(A+A⊤)x(A+A^\top)\mathbf x, which is 2Ax2A\mathbf x for symmetric AAquadratic losses, Gaussian log-densities
∥Ax−b∥2\norm{A\mathbf x-\mathbf b}^22A⊤(Ax−b)2A^\top(A\mathbf x-\mathbf b)least squares
tr⁡(AX)\operatorname{tr}(AX)A⊤A^\toptrace manipulations
log⁡det⁡X\log\det X (for det⁡X>0\det X>0)X−⊤X^{-\top}Gaussian likelihoods, log-determinant penalties
a⊤X−1b\mathbf a^\top X^{-1}\mathbf b−X−⊤ab⊤X−⊤-X^{-\top}\mathbf a\mathbf b^\top X^{-\top}covariance estimation
Each identity follows from a first-order expansion, read off as f(X+E)≈f(X)+⟨∇f,E⟩f(X+E)\approx f(X)+\langle\nabla f,E\rangle with ⟨G,E⟩=tr⁡(G⊤E)\langle G,E\rangle=\operatorname{tr}(G^\top E). For instance x⊤Ax\mathbf x^\top A\mathbf x changes by δ⊤Ax+x⊤Aδ=((A+A⊤)x)⊤δ\boldsymbol\delta^\top A\mathbf x+\mathbf x^\top A\boldsymbol\delta=\big((A+A^\top)\mathbf x\big)^\top\boldsymbol\delta, and X−1X^{-1} changes by −X−1EX−1-X^{-1}EX^{-1}.
DerivationThe gradient of log det, and the Gaussian covariance estimate
  1. log⁡det⁡(X+E)=log⁡det⁡X+log⁡det⁡(I+X−1E)=log⁡det⁡X+∑ilog⁡(1+μi)≈log⁡det⁡X+tr⁡(X−1E)\log\det(X+E)=\log\det X+\log\det(I+X^{-1}E)=\log\det X+\sum_i\log(1+\mu_i)\approx\log\det X+\operatorname{tr}(X^{-1}E)

    Factor out XX; for a small EE, the eigenvalues μi\mu_i of M=X−1EM=X^{-1}E are small, and log⁡(1+μ)≈μ\log(1+\mu)\approx\mu:

  2. ℓ(Λ)=n2log⁡det⁡Λ−n2tr⁡(ΛS)+const⟹∇Λℓ=n2Λ−1−n2S\ell(\Lambda)=\frac n2\log\det\Lambda-\frac n2\operatorname{tr}(\Lambda S)+\text{const}\quad\Longrightarrow\quad\nabla_\Lambda\ell=\frac n2\Lambda^{-1}-\frac n2S

    Since tr⁡(X−1E)=⟨X−⊤,E⟩\operatorname{tr}(X^{-1}E)=\langle X^{-\top},E\rangle, the gradient is X−⊤X^{-\top}. Apply it to the Gaussian log-likelihood in the precision matrix Λ=Σ−1\Lambda=\Sigma^{-1}, with SS the average of (xi−μ)(xi−μ)⊤(\mathbf x_i-\boldsymbol\mu)(\mathbf x_i-\boldsymbol\mu)^\top:

  3. Σ^=Λ^−1=S\hat\Sigma=\hat\Lambda^{-1}=S

    The log-likelihood is concave in Λ\Lambda (log det is concave on positive definite matrices), so the stationary point is the maximum: the maximum-likelihood covariance is the sample covariance with divisor nn, whenever SS is invertible.

Randomized SVD, and the frontier

A full SVD of an m×nm\times n matrix costs on the order of mnmin⁡(m,n)mn\min(m,n) operations, too much for large data even when only the top kk components matter. Randomized SVD (Halko, Martinsson & Tropp, 2011) first finds the range: multiply AA by k+pk+p random Gaussian vectors, a small oversampling pp such as 5 or 10. The products are random combinations of the columns, dominated by the top singular directions, so an orthonormal basis QQ of them nearly spans the top-kk left singular subspace. Everything else happens in the small matrix Q⊤AQ^\top A.

python
import numpy as np

def randomized_svd(A, k, p=10, q=2, seed=0):
    rng = np.random.default_rng(seed)
    Omega = rng.standard_normal((A.shape[1], k + p))  # random test matrix
    Q, _ = np.linalg.qr(A @ Omega)                     # basis for the sampled range
    for _ in range(q):                                 # power iterations, re-orthonormalized
        Q, _ = np.linalg.qr(A.T @ Q)
        Q, _ = np.linalg.qr(A @ Q)
    B = Q.T @ A                                        # small (k + p) x n matrix
    U_small, s, Vt = np.linalg.svd(B, full_matrices=False)
    return (Q @ U_small)[:, :k], s[:k], Vt[:k]

The whole algorithm touches AA only through a few matrix products, 2(q+1)2(q+1) passes in all, so it works for matrices too large for memory and parallelizes well. After qq power iterations the sampled matrix is (AA⊤)qA(AA^\top)^qA, whose singular values are σi2q+1\sigma_i^{2q+1}: the top kk dominate the rest far more sharply.

Think first For k=10k=10, p=5p=5 and min⁡(m,n)=1000\min(m,n)=1000, how large is the bracket in the bound? And what do two power iterations do to the corresponding factor [1+42min⁡(m,n)/(k−1)]1/(2q+1)\big[1+4\sqrt{2\min(m,n)/(k-1)}\big]^{1/(2q+1)}?

1+41541000=1+15⋅1000≈1231+\tfrac{4\sqrt{15}}{4}\sqrt{1000}=1+\sqrt{15}\cdot\sqrt{1000}\approx123: a pessimistic worst-case factor. With power iterations the factor is [1+42000/9]1/(2q+1)≈60.61/(2q+1)\big[1+4\sqrt{2000/9}\big]^{1/(2q+1)}\approx60.6^{1/(2q+1)}: about 3.9 for q=1q=1 and 2.3 for q=2q=2. When the singular values decay, the actual error is usually much closer to σk+1\sigma_{k+1} than any of these bounds, and the paper's refined bounds explain why.

Key takeaways

  • Symmetric matrices diagonalize as QΛQ⊤Q\Lambda Q^\top with real eigenvalues and orthonormal eigenvectors. PSD matrices are exactly the Gram matrices B⊤BB^\top B; covariances, kernel matrices and convex Hessians are PSD, and positive definite ones factor as LL⊤LL^\top (Cholesky).
  • Rayleigh quotients and Courant–Fischer characterize eigenvalues variationally, which gives PCA and Weyl's bound ∣λk(A+E)−λk(A)∣≤∥E∥2\abs{\lambda_k(A+E)-\lambda_k(A)}\le\norm E_2. Eigenvectors are stable only relative to the eigengap: sin⁡θ≤2∥E∥2/(λ1−λ2)\sin\theta\le2\norm{E}_2/(\lambda_1-\lambda_2).
  • Every matrix has an SVD ∑iσiuivi⊤\sum_i\sigma_i\mathbf u_i\mathbf v_i^\top, built from the spectral theorem of A⊤AA^\top A. The truncated SVD is the best rank-kk approximation, with errors σk+1\sigma_{k+1} (spectral) and ∑i>kσi2\sqrt{\sum_{i>k}\sigma_i^2} (Frobenius).
  • The pseudoinverse gives the minimum-norm least-squares solution ∑i(ui⊤y/σi)vi\sum_i(\mathbf u_i^\top\mathbf y/\sigma_i)\mathbf v_i; small singular values amplify noise and rounding by up to κ=σ1/σr\kappa=\sigma_1/\sigma_r, and the normal equations square κ\kappa.
  • Randomized SVD sketches the range with k+pk+p random vectors and is within a modest factor of σk+1\sigma_{k+1} in expectation; a few power iterations drive that factor toward 1.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

The singular values of AA are σ1≥σ2≥…\sigma_1\ge\sigma_2\ge\dots. What is the smallest possible spectral-norm error ∥A−B∥2\norm{A-B}_2 over all matrices BB of rank at most kk?

  1. σk\sigma_k
  2. σk+1\sigma_{k+1}
  3. ∑i>kσi2\sqrt{\sum_{i>k}\sigma_i^2}
  4. σ1−σk\sigma_1-\sigma_k
Show the answer

B. σk+1\sigma_{k+1}

Eckart–Young–Mirsky: the truncated SVD AkA_k is optimal, with ∥A−Ak∥2=σk+1\norm{A-A_k}_2=\sigma_{k+1}, the largest singular value left out. The square-root sum is the optimal error in the Frobenius norm.

Question 2

You perturb a symmetric matrix AA by a symmetric EE with ∥E∥2=0.01\norm{E}_2=0.01. Which statement is guaranteed?

  1. Every eigenvalue and every eigenvector moves by at most about 0.010.01
  2. Eigenvalues can move arbitrarily, but eigenvectors are stable
  3. Nothing can be said without knowing the dimension
  4. Every eigenvalue moves by at most 0.010.01, but an eigenvector can rotate a lot if its eigenvalue is close to another one
Show the answer

D. Every eigenvalue moves by at most 0.010.01, but an eigenvector can rotate a lot if its eigenvalue is close to another one

Weyl's inequality bounds every eigenvalue shift by ∥E∥2\norm{E}_2, whatever the spectrum. Eigenvectors are controlled only relative to the eigengap: Davis–Kahan bounds the rotation by about 2∥E∥2/gap2\norm{E}_2/\text{gap}, which is large when eigenvalues nearly coincide, and when they coincide, the eigenvector is not even unique.

Question 3

A design matrix has condition number κ(X)=106\kappa(X)=10^6. Why do careful solvers avoid forming X⊤XX^\top X for least squares?

  1. Because X⊤XX^\top X is not symmetric
  2. Because X⊤XX^\top X can be singular even when XX has full column rank
  3. Because κ(X⊤X)=κ(X)2=1012\kappa(X^\top X)=\kappa(X)^2=10^{12}, which can cost about 12 of double precision's 16 significant digits
  4. Because forming X⊤XX^\top X costs more than an SVD
Show the answer

C. Because κ(X⊤X)=κ(X)2=1012\kappa(X^\top X)=\kappa(X)^2=10^{12}, which can cost about 12 of double precision's 16 significant digits

The singular values of X⊤XX^\top X are the squares σi2\sigma_i^2, so the condition number squares. Rounding errors of relative size 10−1610^{-16} are amplified by up to κ\kappa, so 101210^{12} leaves only a few reliable digits. QR or SVD works on XX directly, where the amplification is governed by κ(X)\kappa(X) (with a κ2\kappa^2 term only when the residual is large).

Question 4

XX has more columns than rank, so least squares min⁡w∥Xw−y∥2\min_{\mathbf w}\norm{X\mathbf w-\mathbf y}^2 has infinitely many minimizers. Which one is X+yX^+\mathbf y, with X+=VΣ+U⊤X^+=V\Sigma^+U^\top?

  1. The minimizer of smallest Euclidean norm, the one with no component in the null space of XX
  2. An arbitrary one, depending on the SVD routine
  3. The one with the smallest residual, which is unique
  4. The one with the fewest nonzero coefficients
Show the answer

A. The minimizer of smallest Euclidean norm, the one with no component in the null space of XX

In the rotated coordinates c=V⊤w\mathbf c=V^\top\mathbf w, the residual depends only on c1,…,crc_1,\dots,c_r, which must equal ui⊤y/σi\mathbf u_i^\top\mathbf y/\sigma_i; the remaining coordinates span the null space and are free. Σ+\Sigma^+ sets them to zero, which minimizes ∥w∥=∥c∥\norm{\mathbf w}=\norm{\mathbf c}. It is also the limit of ridge regression as λ→0+\lambda\to0^+ and the point gradient descent from zero converges to.

Further reading

  • C. Eckart & G. Young, "The approximation of one matrix by another of lower rank," Psychometrika 1, 211–218 (1936).
  • Y. Yu, T. Wang & R. J. Samworth, "A useful variant of the Davis–Kahan theorem for statisticians," Biometrika 102(2), 315–323 (2015).
  • N. Halko, P.-G. Martinsson & J. A. Tropp, "Finding structure with randomness: probabilistic algorithms for constructing approximate matrix decompositions," SIAM Review 53(2), 217–288 (2011).
  • L. N. Trefethen & D. Bau, Numerical Linear Algebra (SIAM, 1997).
  • R. A. Horn & C. R. Johnson, Matrix Analysis, 2nd ed. (Cambridge University Press, 2012).