📐Least Squares and Data Fitting
The Singular Value Decomposition
A = UΣVᵀ, singular values as gains, rank and pseudoinverse, low-rank approximation, regularisation
The Netflix Prize, 2006–2009
In October 2006 Netflix releases 100 million ratings — 480,189 customers, 17,770 films, one to five stars — and offers $1,000,000 to the first team that predicts held-out ratings 10% more accurately than its own system, Cinematch. Of the 8.5 billion possible customer–film pairs, about 99% are blank.
Two months in, a contestant posting as Simon Funk publishes a blog post describing a startlingly simple idea. Suppose each film can be described by a few hidden numbers — how much action, how much romance, how serious — and each customer by how much they like each of those. Then the whole ratings matrix is approximately the product of a tall thin matrix and a short wide one: a low-rank matrix. Fit the factors to the ratings you have, and the product predicts the ones you do not.
Three years and thousands of teams later, on 21 September 2009, BellKor's Pragmatic Chaos — a merger of teams from AT&T Labs, Austria and Canada — is awarded the prize. Their blend combines hundreds of models; at its core is matrix factorisation. The mathematics underneath is the most informative decomposition in linear algebra.
💡The SVD
Every matrix — any shape, any rank — can be written
with () and () orthogonal and diagonal with , the singular values; is the rank. Read it as a recipe: . The matrix takes the orthonormal directions to orthonormal directions , stretched by . Every matrix maps the unit sphere to an ellipsoid whose semi-axes are .
Derivation
Where the SVD comes from
Start from the square, symmetric matrix (). A theorem of linear algebra — the spectral theorem — says every symmetric matrix has orthonormal eigenvectors with real eigenvalues (Unit 6 shows how they are computed). These eigenvalues cannot be negative:
So define , ordered from largest to smallest, and for each the vector . These s are orthonormal too:
By construction for every (for both sides are zero). Put the s in the columns of , the s in (completed with further orthonormal columns if ), and the s on the diagonal of : . Multiply on the right by :
A consequence for lesson 5-1. : the singular values of are , so . (Libraries do not compute the SVD this way, for exactly that reason; Golub and Kahan's algorithm works on directly.)
Almost everything one wants to know about a matrix can be read off its SVD:
- Norm and condition: and — the definitions of lesson 3-2 made concrete.
- Rank: the number of nonzero singular values. In floating point nothing is exactly zero, so the numerical rank counts above a tolerance such as .
- Null space: the with — input directions the matrix destroys. Range: the with .
- Pseudoinverse: . is the least-squares solution of smallest norm — well defined even when the columns are dependent.
Derivation
The norm, and least squares, in singular coordinates
Measure every input in the basis of the and every output in the basis of the . Orthogonal matrices preserve length (lesson 5-2), so nothing is lost by doing so — and in these coordinates is just .
The 2-norm. Write , so . Then and
with equality for . So . For a square invertible the same argument applied to gives , hence .
Least squares. With and ,
Each term of the first sum is made zero by ; the second sum cannot be changed at all — it is the part of outside the range of . If some , the matching does not appear in the residual and can be anything: the solution is not unique. Choosing those gives the shortest , because . The result is the pseudoinverse solution
📐A rank-deficient matrix
has third column = first + second. Its singular values are , and : numerical rank 2. The null-space direction is — exactly the dependency. For , QR would break down on the zero pivot; the pseudoinverse gives the minimum-norm solution , and says precisely which combination of unknowns the data cannot determine.
💡The best low-rank approximation
Truncate the sum after terms: . The error is the rest of the sum, — itself an SVD, whose largest singular value is . The Eckart–Young theorem (1936, quoted here without its proof) adds that no matrix of rank does better:
Storage drops from numbers to . When the singular values fall quickly — as they do for smooth data, images, and anything governed by a few underlying factors — a small captures almost everything.
📐Hidden tastes in a ratings matrix
Simulate 300 users rating 120 films, where tastes come from three hidden factors, plus rating noise. The singular values of the observed matrix are — then a cliff to : three factors, and noise. The rank-3 approximation reproduces the true tastes with 5.3% error using 3.5% of the storage. Keeping more singular values makes the fit to the observed matrix better but the estimate of the true tastes worse — rank 10 gives 11.8% error — because the extra layers model the noise. Choosing is choosing what to believe.
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
Ill-posed problems and regularisation. In , the SVD writes the solution as . Noise in has components along every , and dividing by tiny multiplies them enormously. Deblurring a signal, reconstructing a load from measured strains, inverting seismic or gravity data — all have singular values that decay towards zero, and the naive solution is pure amplified noise. Two cures:
- Truncated SVD: keep only the terms with above a threshold.
- Tikhonov regularisation (Andrey Tikhonov, 1963): minimise , which replaces by the filter — gently suppressing small singular values rather than cutting them.
For a blurred step-and-bump signal with noise, the naive solve is off by a factor of more than ; truncated SVD with 40 terms gives 15% error and Tikhonov with gives 14%. Too little regularisation lets noise through, too much blurs the answer.
Derivation
Where Tikhonov's filter factors come from
Minimise . The calculus of lesson 5-1 applies with one extra term, whose gradient is :
Insert the SVD: and . In the coordinates the system is diagonal, one equation per singular value:
Compare with the unregularised . When the factor is almost : nothing changes. When it is about , which goes to zero instead of blowing up. The single parameter marks the singular value below which the data are no longer trusted.
🕰From Beltrami to Golub–Kahan
Eugenio Beltrami (1873) and Camille Jordan (1874) discovered the decomposition for square matrices while studying bilinear forms; Eckart and Young (1936) proved the approximation theorem for rectangular ones in a psychometrics journal. It was a theoretical tool until 1965, when Gene Golub and William Kahan published a stable way to compute it — bidiagonalisation by Householder reflections followed by an implicit QR iteration — and Golub and Christian Reinsch turned it into the algorithm (1970) that LAPACK still descends from.
💡Where you will use this
Attitude Determination: the optimal rotation in Wahba's problem comes straight from the SVD of a 3 × 3 matrix. Structural health monitoring and Vibration: proper orthogonal decomposition — the SVD of a matrix of sensor time histories — extracts dominant mode shapes. Optimal Guidance and Control: model reduction (balanced truncation) keeps the large Hankel singular values. Data-driven engineering: principal component analysis, recommendation systems, image compression and every 'reduced-order model'.
📚Further reading
- Lloyd N. Trefethen and David Bau, Numerical Linear Algebra (SIAM, 1997), Lectures 4–5, 'The Singular Value Decomposition' and 'More on the SVD', and Lecture 31, 'Computing the SVD'.
- Gilbert Strang, Introduction to Linear Algebra (5th ed., Wellesley–Cambridge, 2016), chapter 7, 'The Singular Value Decomposition' — the geometry, gently.
- Per Christian Hansen, Discrete Inverse Problems: Insight and Algorithms (SIAM, 2010) — truncated SVD and Tikhonov regularisation for real ill-posed problems.
↓But there is a problem
Everything in this unit so far has assumed the model is linear in its unknowns. Many of the most important measurement models are not.
A GNSS receiver measures the time a signal takes to arrive from each satellite. Multiplied by the speed of light, that is the distance — plus an unknown receiver clock error. The receiver position sits inside a square root, and the clock error is a fourth unknown.
In 1944, at the US Army's Frankford Arsenal, a mathematician named Kenneth Levenberg wrote a short paper on fitting such models. Nineteen years later a statistician at DuPont, Donald Marquardt, rediscovered and improved his idea. Every curve-fitting tool you will ever use runs their algorithm.