Low-rank reconstruction
Quick answer
Low-rank reconstruction retains only the k largest singular values and associated directions: Aₖ = U[:, :k] diag(s[:k]) Vᵀ[:k, :]. It gives a matrix of rank at most k. The truncated SVD minimizes Frobenius reconstruction error among matrices of rank at most k; squared error equals the sum of the discarded singular values squared. It is useful for approximating redundant measurements, but compression accuracy is not predictive accuracy. For centered data the right singular directions also define projections used in PCA, covered later.
Predict the error before reconstructing
Suppose a matrix has singular values 5, 2, 1. Keeping only the largest component discards 2 and 1. The squared error is 2² + 1² = 5; Frobenius error is √5. Keeping zero components yields the zero matrix.
s = [5, 2, 1]k = 1print(sum(value*value for value in s[k:]))print(sum(value*value for value in s[:k])/sum(value*value for value in s))Expected output:
50.8333333333333334The retained squared energy is 25/30. For centered data this ratio corresponds to retained total sample variance; for arbitrary uncentered A it is only a squared-energy ratio.
Measure reconstruction error and conditioning
Optional local lab (Python 3.13.5, NumPy 2.3.5, CPU, float64). Use a small rectangular matrix and keep one singular direction. The Frobenius norm is the square root of the sum of squared entries. For a nonsingular square matrix, its 2-norm condition number is largest divided by smallest singular value. A high value signals possible sensitivity to perturbations, not necessarily a large error on every input. solve handles nonsingular square systems without explicitly forming an inverse.
import numpy as npA = np.array([[4., 0.], [0., 1.], [0., 0.]])U, s, Vh = np.linalg.svd(A, full_matrices=False)k = 1Ak = (U[:, :k]*s[:k]) @ Vh[:k, :]print(round(float(np.linalg.norm(A-Ak, ord="fro")), 8))B = np.diag([1., 0.001])b = np.array([1., 0.001])x = np.linalg.solve(B, b)print(round(float(np.linalg.cond(B)), 8))print(bool(np.allclose(B @ x, b, atol=1e-12, rtol=1e-12)))Expected output:
1.01000.0TrueThe discarded singular value is 1, so reconstruction error is 1. The small system has a large condition number despite the tiny residual. Changing the second right-hand-side entry by 0.001 changes its solution component by 1. A direct solve avoids unnecessary inverse formation, but cannot remove inherent ill-conditioning.
Common mistakes
Do not choose k using held-out test labels. Fit the subspace on training data and project held-out samples using the same directions and training mean. A rank-k matrix does not guarantee smaller storage unless factors are stored instead of the dense reconstruction. A small residual is not proof of a small solution error for an ill-conditioned system. For rank deficiency or rectangular least-squares problems use an appropriate least-squares method, not a forced inverse.
Practice and next steps
Complete the chapter milestone: project a new two-dimensional centered reading onto one retained right singular direction and compare direct reconstruction error with discarded singular values. Next: calculus and automatic differentiation foundations.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Low-rank reconstruction — knowledge check
Apply matrix geometry to small numerical fixtures.
Singular values are 6, 3, 2. What is squared rank-one reconstruction error?
What does rank-zero reconstruction produce?
For a nonsingular square matrix with singular values 5 and 0.01, what is its 2-norm condition number?
What is the preferred direct computation for nonsingular square A x = b?
Does smaller training reconstruction error guarantee better test prediction?