QR, Householder, and Numerical Least Squares
The least-squares problem reduces to the normal equations, but forming AᵀA squares the condition number and can wreck accuracy. The stable route computes a QR factorization directly on A and solves Rx = Qᵀb.
╌╌╌╌
An overdetermined system , with more equations than unknowns, usually has no exact solution: the data does not lie in the column space of . The least-squares problem asks for the next best thing, the making as close to as possible. The classical answer is the normal equations, which are numerically the wrong thing to compute directly. The stable alternative is orthogonalization, built from the Householder reflector.
The least-squares problem and normal equations
Fitting a linear model to noisy measurements gives , where is the design matrix ( measurements, parameters, ), the parameters, and unknown noise. Replacing the noise by a computable residual , the least-squares estimator minimizes its length.
Minimizing sets its gradient to zero. This is the normal equation.
The geometry carries the method: the best approximation is the orthogonal projection of onto , and what makes it best is that the leftover is perpendicular to that subspace, which is exactly .
The direct algorithm forms , then solves it by Cholesky, at a cost of flops. It is cheap, and for anything but a well-conditioned it is inaccurate.
Conditioning of the normal equations
The condition number of the least-squares problem grows with , the ratio of extreme singular values of . Forming squares it:
Solving the normal equation therefore inherits a condition number of , even though the underlying least-squares problem is only -conditioned when the residual is small. By the rule of thumb, squaring the condition number doubles the number of significant digits lost. If in double precision — a middling value — then , and the normal equations can lose every digit while the problem itself still permits eight. The information destroyed in computing cannot be recovered afterward.
Orthogonalization: the stable route
The fix is Stiefel's principle of direct attack
: operate on itself, never on
. A QR factorization supplies it.
Substituting into the normal equation collapses it. Since and , cancelling the invertible leaves a triangular system:
This is solved by one back substitution. Its stability follows from the unitary factor: reading the solve as factorization followed by back substitution, the inverse of the factorization step is well-conditioned because . The factors never grow, so the benign case of the previous lesson holds unconditionally.2
There is even a -free variant: factor the augmented matrix , and the
extra column delivers and the residual norm directly, so never needs to be formed. In MATLAB the entire
least-squares solve is the single backslash x = A\b, which runs exactly this
orthogonalization.
Householder reflectors
Three algorithms build the QR factorization: modified Gram–Schmidt (project each
column against the earlier orthonormal ones), Givens rotations (zero one subdiagonal
entry at a time), and Householder reflectors (zero a whole column below the diagonal
at once). The last is the standard, used by LAPACK's qr, because it is the most
stable and produces the most accurate .3
A Householder reflector reflects space across the hyperplane orthogonal to a chosen vector :
It is symmetric, orthogonal, and its own inverse (), with . Being unitary, it preserves lengths, which is what makes it numerically safe.
To zero the entries of a column below the first, choose so that . Because a reflection is an isometry, , and the reflecting vector is
The sign of is chosen opposite to the first entry on purpose: it makes an addition of like-signed numbers rather than a subtraction, avoiding the cancellation the opposite sign choice would cause. This is the cancellation-avoidance lesson applied to the reflector's own construction.
- 1for to do
- 2column below the diagonal
- 3
- 4reflector vector, cancellation-free
- 5apply reflector
- 6storeQ kept implicitly as its reflectors
- 7end for
- 8return
The reflector is applied without ever forming : each application is a rank-one update with , costing flops. Storing the vectors instead of the matrix keeps implicit, and products or cost only . A full Householder QR of costs
roughly twice the normal-equation cost when .
Choosing a least-squares method
| Method | Solve | Cost () | Conditioning | Use when |
|---|---|---|---|---|
| Normal equations | (Cholesky) | , well-conditioned , large residual | ||
| Orthogonalization | (Householder QR) | ill-conditioned , small residual — the default |
The normal equations keep a niche: when is well-conditioned and the residual is large, their lower cost is worth the squared condition number. Everywhere else, orthogonalization is the right choice: about twice the flops, with the condition number unsquared and the solve backward stable. Iterated, the same QR factorization becomes the standard algorithm for eigenvalues.
Footnotes
- Bornemann, Numerical Linear Algebra, §16 — Normal Equation: the least-squares setup , the normal equation with s.p.d., its solution via Cholesky, and the condition relation . ↩
- Bornemann, §17 — Orthogonalization: the stable reduction , backward stability from , the -free augmented-matrix variant, and the cost comparison with the normal equations. ↩
- Bornemann, §9 — QR Decomposition (modified Gram–Schmidt, Givens rotations) and Appendix D — The Householder Method: the reflector , the cancellation-free sign choice , and the cost. ↩
╌╌ END ╌╌