Matrix Approximation
The SVD gave you an exact factorisation. This page throws part of it away on purpose.
The result is remarkable and it is easy to under-appreciate: if you keep only the largest singular values, the matrix you get back is not merely a good rank- approximation — it is the best one that exists, and its error is exactly . Not bounded by, not approximately: equal to. You know the error before you compute the approximation.
What you’ll learn
Section titled “What you’ll learn”- Equations 4.90 and 4.91: any rank- matrix is a sum of rank-1 outer products, weighted by the singular values.
- Equation 4.92: truncating that sum at gives the rank- approximation .
- Definition 4.23 and Theorem 4.24: the spectral norm, and the fact that it equals .
- Theorem 4.25, Eckart-Young: the truncation is optimal, and .
- The sketch of why no rank- matrix can do better, via the rank-nullity theorem.
- Example 4.15: reading two themes out of a movie-ratings matrix — and a transcription error in the book’s Equation 4.101b, diagnosed exactly.
- The storage arithmetic: when a factorisation actually saves anything, and when it does not.
Intuition: a matrix as a stack of transparencies
Section titled “Intuition: a matrix as a stack of transparencies”An outer product is the simplest nonzero matrix there is. Every row is a multiple of and every column is a multiple of , so it has rank 1 and it looks like a grid — one column pattern times one row pattern, and nothing else. The book makes exactly this point about Figure 4.11: the grid-like structure of each rank-1 matrix is imposed by the outer-product of the left and right-singular vectors.
The SVD says every matrix is a weighted stack of these transparencies, and it orders them by weight. The first carries the most; the last carries the least. Approximating is then simply not laying down the faint ones.
What makes it a theorem rather than a heuristic is that this particular stack is the right one. You could decompose a matrix into rank-1 pieces in infinitely many ways; only the SVD’s ordering has the property that the first pieces are the best pieces.
flowchart TD A["A, rank r"] --> SUM["A = Σᵢ σᵢ uᵢ vᵢᵀ
Eq 4.91: a weighted sum
of r rank-1 matrices"] SUM --> WHY["why: Σ is diagonal, so it pairs
only matching uᵢ with vᵢ;
terms i > r vanish because σᵢ = 0"] SUM --> TRUNC["stop at k < r
Â(k) = Σᵢ₌₁ᵏ σᵢ uᵢ vᵢᵀ
Eq 4.92, rank exactly k"] TRUNC --> DIFF["A − Â(k) = Σᵢ₌ₖ₊₁ʳ σᵢ uᵢ vᵢᵀ
Eq 4.96 — the leftovers"] NORM["spectral norm ‖A‖₂ = maxₓ ‖Ax‖₂/‖x‖₂
Def 4.23"] --> T424["Thm 4.24: ‖A‖₂ = σ₁"] DIFF --> T424 T424 --> EY["Thm 4.25 Eckart-Young
‖A − Â(k)‖₂ = σₖ₊₁
and no rank-k B does better"] EY --> USE["lossy compression, denoising,
regularising ill-posed problems,
and PCA in Chapter 10"]
The math
Section titled “The math”Every matrix is a sum of rank-1 pieces
Section titled “Every matrix is a sum of rank-1 pieces”Define the outer-product matrices
Then a matrix of rank satisfies
The book’s own reason is worth quoting because it is the whole argument: the diagonal structure of the singular value matrix multiplies only matching left- and right-singular vectors and scales them by the corresponding singular value . All terms vanish for because is a diagonal matrix. Any terms vanish because the corresponding singular values are .
So Equation 4.91 is not a new fact. It is written out term by term.
Truncating
Section titled “Truncating”The rank is exactly , not at most , because the are orthonormal and the for are nonzero.
Measuring the error
Section titled “Measuring the error”To say how good an approximation is you need a norm on matrices. §3.1 gave norms on vectors; the analogue here is:
Read it as: how long can any vector at most become when multiplied by ? The subscript matches the Euclidean norm on vectors on the right-hand side.
The book leaves the proof as an exercise — it is Exercise 4.11, and the next page works it. The intuition is immediate from the geometry of §4.5: and are rotations and change no length, so all the stretching is , and the most a unit vector can be stretched by a diagonal matrix is its largest entry.
The theorem
Section titled “The theorem”Two separate claims. Equation 4.94 is optimality: nothing of rank is closer. Equation 4.95 is exactness: the error is not bounded by , it equals it.
The second claim is nearly free. The difference is just the discarded tail,
which is itself a matrix in SVD form whose largest singular value is — so Theorem 4.24 gives Equation 4.95 immediately.
Why nothing of rank k does better
Section titled “Why nothing of rank k does better”The book’s argument is a proof by contradiction and it is short enough to follow completely. Suppose some with satisfied
Then has a null space of dimension at least , and for we have , hence
and by the matrix version of Cauchy-Schwarz,
But there is a -dimensional subspace — spanned by — on which . Adding the dimensions of those two subspaces gives , so they must share a nonzero vector, which cannot satisfy both inequalities. That contradicts the rank-nullity theorem (Theorem 2.24). Hence no such exists.
Notice what carried the argument: counting dimensions. Chapter 2’s rank-nullity theorem, which looked like bookkeeping at the time, is what makes the SVD optimal.
Worked example by hand
Section titled “Worked example by hand”Example 4.15 — two themes in a ratings table
Section titled “Example 4.15 — two themes in a ratings table”The matrix from Example 4.14, four movies by three viewers:
with . The first rank-1 piece is
Reproduced from the SVD to , which is the rounding of the book’s four printed decimals. The book’s reading: Ali and Beatrix like science fiction — Star Wars and Blade Runner, entries above — but this piece fails to capture Chandra’s ratings, which is unsurprising, since Chandra’s taste is not in the first singular direction.
The second piece captures the other theme, French art house. Combining them,
which reproduces Equation 4.102 to all four printed decimals. Compare against : every entry is within about . The conclusion the book draws is that can be ignored — there is no evidence of a third movie-theme category, and the whole space of themes is two-dimensional.
And Eckart-Young says exactly how good that is, before you look: . Measured on the book’s own printed : , the difference being the four-decimal rounding.
Eckart-Young, measured at every k
Section titled “Eckart-Young, measured at every k”import numpy as np
A = np.array([[5.0, 4, 1], [5, 5, 0], [0, 0, 5], [1, 0, 4]])
U, s, Vt = np.linalg.svd(A, full_matrices=False)
r = int(np.linalg.matrix_rank(A))
print(f"rank {r} ||A||_2 = {np.linalg.norm(A, 2):.6f} sigma_1 = {s[0]:.6f} (Theorem 4.24)")
print()
for k in range(0, r + 1):
Ak = (U[:, :k] * s[:k]) @ Vt[:k] if k else np.zeros_like(A)
spec = float(np.linalg.norm(A - Ak, 2))
frob = float(np.linalg.norm(A - Ak))
nxt = s[k] if k < len(s) else 0.0
tail = float(np.sqrt(np.sum(s[k:] ** 2)))
print(f" k={k} ||A-Ahat||_2 {spec:.6f} sigma_(k+1) {nxt:.6f} gap {abs(spec-nxt):.2e}"
f" ||.||_F {frob:.6f} sqrt(sum of tail sigma^2) {tail:.6f}")rank 3 ||A||_2 = 9.643811 sigma_1 = 9.643811 (Theorem 4.24)
k=0 ||A-Ahat||_2 9.643811 sigma_(k+1) 9.643811 gap 3.55e-15 ||.||_F 11.575837 sqrt(sum of tail sigma^2) 11.575837
k=1 ||A-Ahat||_2 6.363891 sigma_(k+1) 6.363891 gap 8.88e-16 ||.||_F 6.402883 sqrt(sum of tail sigma^2) 6.402883
k=2 ||A-Ahat||_2 0.705552 sigma_(k+1) 0.705552 gap 0.00e+00 ||.||_F 0.705552 sqrt(sum of tail sigma^2) 0.705552
k=3 ||A-Ahat||_2 0.000000 sigma_(k+1) 0.000000 gap 6.84e-15 ||.||_F 0.000000 sqrt(sum of tail sigma^2) 0.000000Equation 4.95 holds at every including the trivial ones. At the approximation is the zero matrix and the error is — which is Theorem 4.24 restated. At the error is zero.
The last two columns are a bonus the book does not state: the Frobenius error is , exactly, in every row. So the SVD truncation is optimal in that norm too, and its error there is also known in advance. At the two norms coincide, because only one singular value is left and a rank-1 matrix has the same spectral and Frobenius norm.
See it move
Section titled “See it move”The heatmaps are A, its rank-k reconstruction, and their difference on a shared colour scale. Each frame checks the Eckart-Young bound against a spectral norm measured by power iteration, independently of the singular values used to build the approximation.
From scratch
Section titled “From scratch”import numpy as np
def truncate(A, k):
"""Equation 4.92, built from the rank-1 pieces one at a time."""
A = np.asarray(A, dtype=float)
U, s, Vt = np.linalg.svd(A, full_matrices=False)
out = np.zeros_like(A)
for i in range(k):
out += s[i] * np.outer(U[:, i], Vt[i]) # Eq 4.90 and 4.92
return out, s
def spectral_norm(A, iters=500):
"""Definition 4.23 by power iteration on A^T A — no SVD involved."""
A = np.asarray(A, dtype=float)
x = np.ones(A.shape[1]) / np.sqrt(A.shape[1])
lam = 0.0
for _ in range(iters):
z = A.T @ (A @ x)
n = float(np.linalg.norm(z))
if n < 1e-300:
return 0.0
x, lam = z / n, n
return float(np.sqrt(lam))
A = np.array([[5.0, 4, 1], [5, 5, 0], [0, 0, 5], [1, 0, 4]])
_, s = truncate(A, 0)
r = int(np.linalg.matrix_rank(A))
print(f"Theorem 4.24: spectral_norm(A) {spectral_norm(A):.9f} sigma_1 {s[0]:.9f}")
print()
print("Theorem 4.25, with the norm measured independently of the singular values:")
for k in range(r + 1):
Ak, _ = truncate(A, k)
measured = spectral_norm(A - Ak)
bound = s[k] if k < len(s) else 0.0
print(f" k={k} rank(Ahat) {np.linalg.matrix_rank(Ak) if k else 0}"
f" measured {measured:.9f} sigma_(k+1) {bound:.9f}"
f" gap {abs(measured - bound):.2e}")Theorem 4.24: spectral_norm(A) 9.643810900 sigma_1 9.643810900
Theorem 4.25, with the norm measured independently of the singular values:
k=0 rank(Ahat) 0 measured 9.643810900 sigma_(k+1) 9.643810900 gap 3.55e-15
k=1 rank(Ahat) 1 measured 6.363890889 sigma_(k+1) 6.363890889 gap 8.88e-16
k=2 rank(Ahat) 2 measured 0.705552321 sigma_(k+1) 0.705552321 gap 3.33e-16
k=3 rank(Ahat) 3 measured 0.000000000 sigma_(k+1) 0.000000000 gap 6.16e-15The point of measuring the norm by power iteration rather than reading off the SVD is that it makes the check independent. If Equation 4.95 were merely a restatement, this table would be circular; because the left column comes from a separate algorithm — power iteration on , which never touches a singular vector — it is a test. Every gap is at machine precision, the worst being at where both quantities are zero and the comparison is absolute rather than relative.
Note also the rank(Ahat) column: it reads . Equation 4.92 promises rank exactly , and
the reason is that the are orthonormal, so no rank-1 piece can be absorbed into the
others.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”From the rank-1 pieces figure. Look at the top row before the bottom row. Every panel has visible horizontal and vertical banding, and that is not an artefact — an outer product must look like that, because every row is a multiple of the same row pattern. This is the observation the book attaches to Figure 4.11, and seeing five of them side by side makes the point that a single rank-1 matrix cannot represent anything localised.
The bottom row is the sum. The energy table explains why it converges so fast:
| cumulative share of squared energy | |
|---|---|
| 1 | |
| 2 | |
| 3 | |
| 5 | |
| 8 | (exact) |
This image was built from a small number of rank-1 ingredients — a gradient, two rectangles, a blob — so it has exact rank 8 and a fast-decaying spectrum. Real photographs are not exactly low rank; they are approximately low rank, which is why the same procedure still works but never becomes exact.
From the Eckart-Young figure. Two claims, two colours.
The green points test Equation 4.95. Over truncations the largest disagreement between the measured spectral error and is — machine precision. The points are on the diagonal, and the word to notice is “on”: an inequality would have produced a cloud below the line.
The red points test Equation 4.94. Every one is a random rank- matrix, rescaled to the same Frobenius size as the truncation so the comparison is not rigged by magnitude. Zero of 420 landed below the line, and the best one was still worse. Random search does not find a better rank- matrix because there isn’t one.
From the compression figure. The left panel puts three curves on top of each other: the spectral error, the Frobenius error and . The spectral curve and the curve are indistinguishable, which is Equation 4.95 again; the Frobenius curve sits slightly above, because it sums the whole tail rather than taking its largest element.
The right panel is the sober one, and it is the part the Stonehenge example can leave you over-optimistic about. A rank- factorisation of an matrix costs numbers, so it saves only when
For this image that threshold is — half the rank. For Stonehenge, , it is , so the book’s rank-5 approximation at is nowhere near it and the compression is genuine. The saving comes from the matrix being large and its useful rank being small, and it is the ratio that matters, not the rank. A matrix of rank 3 costs numbers factored against stored — a saving, but a thin one.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| how you might reduce a matrix’s rank | error in the spectral norm | optimal? |
|---|---|---|
| SVD truncation | exactly | yes, Theorem 4.25 |
| keep the largest-magnitude entries | unbounded | no |
| keep the largest-norm rows | unbounded | no |
| a random rank- projection | typically much worse; measured best of 420 was | no, but cheap and it comes with probabilistic bounds |
| a random rank- matrix | far worse | no |
| CUR / interpolative decomposition | within a factor of the optimum | no, but the factors are actual rows and columns, so they stay interpretable |
The last row is the honest trade. Truncation is optimal but its factors are dense combinations of everything; CUR is slightly worse but every factor is a real row or column of your data.
-
Equation 4.95 says the error equals sigma-k-plus-one. Why is that nearly free once you have Theorem 4.24?
Equation 4.96 makes the difference explicit as the sum from k+1 to r. The hard half of Theorem 4.25 is the other one — Equation 4.94, optimality, which needs the rank-nullity contradiction.
pch.quizShowAnswer
B — Because A minus A-hat(k) is itself the tail of the SVD sum, so it is a matrix already in SVD form whose largest singular value is sigma-k-plus-one — and Theorem 4.24 says the spectral norm IS the largest singular value — Equation 4.96 makes the difference explicit as the sum from k+1 to r. The hard half of Theorem 4.25 is the other one — Equation 4.94, optimality, which needs the rank-nullity contradiction.
-
The optimality argument reaches a contradiction by adding two dimensions. Which two, and what do they add up to?
A vector in both would have to satisfy ||Ax|| < sigma-k-plus-one ||x|| from being in the null space of B, and ||Ax|| >= sigma-k-plus-one ||x|| from being in the singular-vector span. Chapter 2's rank-nullity theorem is what forbids it.
pch.quizShowAnswer
B — The null space of B, which has dimension at least n-k, and the span of the first k+1 right-singular vectors, which has dimension k+1 — adding to n+1, so the two subspaces must share a nonzero vector — A vector in both would have to satisfy ||Ax|| < sigma-k-plus-one ||x|| from being in the null space of B, and ||Ax|| >= sigma-k-plus-one ||x|| from being in the singular-vector span. Chapter 2's rank-nullity theorem is what forbids it.
-
In 420 tests, zero random rank-k matrices beat the truncation and the best was 1.25 times worse. What does the 1.25 tell you that the zero does not?
A best-competitor ratio of 1.0001 would have left it open whether the zero count was a floating-point artefact. At 1.25 the gap is unambiguous, and it is the closest of 420 attempts — the typical competitor is far worse.
pch.quizShowAnswer
B — That the bound is not merely rarely violated but has real margin — random rank-k matrices are not even close, so the test is not just a near-tie decided by rounding — A best-competitor ratio of 1.0001 would have left it open whether the zero count was a floating-point artefact. At 1.25 the gap is unambiguous, and it is the closest of 420 attempts — the typical competitor is far worse.
-
The 64x64 image has exact rank 8. Why is that still only a 4-to-1 compression rather than 8-to-1?
This is why the book's Stonehenge example is so much more impressive: at 1432 by 1910 the break-even rank is 818, so rank 5 is a 0.611 percent cost. Big matrix, small useful rank.
pch.quizShowAnswer
B — Because a rank-k factorisation costs k(m+n+1) numbers, which is 8 times 129 equals 1032 against 4096 — the cost scales with m+n, not with n squared, so the saving depends on the ratio of k to mn/(m+n+1), which is 32 here — This is why the book's Stonehenge example is so much more impressive: at 1432 by 1910 the break-even rank is 818, so rank 5 is a 0.611 percent cost. Big matrix, small useful rank.
-
Truncation minimises the spectral norm error. Where does that guarantee stop being the guarantee you want?
Recommender systems are the standard example: with most entries unobserved the problem is no longer a single SVD and is generally hard, which is why iterative matrix-completion methods exist.
pch.quizShowAnswer
B — When entries are missing, when the loss is weighted or entrywise-L1, or when a faint feature matters more than its contribution to the norm — optimality with respect to a norm is not usefulness — Recommender systems are the standard example: with most entries unobserved the problem is no longer a single SVD and is generally hard, which is why iterative matrix-completion methods exist.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Eckart-Young at every k
Section titled “Exercise 1 – Eckart-Young at every k”Exercise 2 – The book’s Equation 4.100, and the slip in 4.101b
Section titled “Exercise 2 – The book’s Equation 4.100, and the slip in 4.101b”Exercise 3 – Nothing of rank k does better
Section titled “Exercise 3 – Nothing of rank k does better”Exercise 4 – When does a factorisation actually save anything?
Section titled “Exercise 4 – When does a factorisation actually save anything?”Exercise 5 – Truncation as denoising, and where it fails
Section titled “Exercise 5 – Truncation as denoising, and where it fails”Recall card
Section titled “Recall card”- Any rank-r matrix is a weighted sum of r rank-1 outer products, A = sum of sigma-i u-i v-i-transpose, because Sigma is diagonal and pairs only matching singular vectors.
- An outer product looks like a grid: every row is a multiple of one row pattern, which is why a single rank-1 piece cannot represent anything localised.
- The rank-k approximation truncates that sum at k and has rank exactly k.
- The spectral norm is the largest stretch a matrix applies to any vector, and Theorem 4.24 says it equals sigma-1.
- Eckart-Young, Theorem 4.25, makes two claims: the truncation is the closest rank-k matrix in the spectral norm, and its error is exactly sigma-k-plus-one — equal to, not bounded by.
- Exactness is nearly free from Theorem 4.24, because the difference is itself the tail of the SVD sum; optimality is the hard half and rests on the rank-nullity theorem.
- Measured: over 420 truncations the error matched sigma-k-plus-one to 6.22e-15, and zero of 420 random rank-k competitors did better, the best being 1.25 times worse.
- The Frobenius error is the square root of the discarded tail of squared singular values, exactly — so the truncation is optimal in that norm too.
- Low rank is not the same as few numbers. A rank-k factorisation costs k(m+n+1), so it saves only for k below mn/(m+n+1) — 32 for a 64 by 64 matrix, 818 for the book’s 1432 by 1910 Stonehenge photograph.
- Optimality is with respect to a norm, not usefulness. With missing entries, a weighted loss, or a faint but important feature, the SVD truncation is no longer the right answer.
Next: Matrix Phylogeny — the family tree of every matrix class in this chapter, and which decomposition applies to each.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading