Numerical Linear Algebra/QR, Householder, and Numerical Least Squares

Lesson 8.51,011 words

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 least-squares solution projects onto the column space of ; the residual is orthogonal to that plane, which is the content of the normal equation .

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.

Forming squares the condition number: a moderately conditioned becomes a severely conditioned normal-equation matrix, doubling the digits lost.

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.

The stable least-squares pipeline: factor directly, form , and back-substitute — never touching the ill-conditioned .

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.

A Householder reflector across the hyperplane sends the column to , zeroing every entry below the first while preserving .

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.

Algorithm:HouseholderQR(A)\textsc{HouseholderQR}(A) — full QR of ARm×nA \in \mathbb{R}^{m\times n}
  1. 1
    for k=1k = 1 to nn do
  2. 2
    aAk:m,ka \gets A_{k:m,\,k}
    column below the diagonal
  3. 3
    ρsign(a1)a2\rho \gets -\operatorname{sign}(a_1)\,\lVert a\rVert_2
  4. 4
    vaρe1v \gets a - \rho\, e_1
    reflector vector, cancellation-free
  5. 5
    Ak:m,k:nAk:m,k:n2vvv(vAk:m,k:n)A_{k:m,\,k:n} \gets A_{k:m,\,k:n} - \tfrac{2}{v^\top v}\, v\,(v^\top A_{k:m,\,k:n})
    apply reflector
  6. 6
    store vv
    Q kept implicitly as its reflectors
  7. 7
    end for
  8. 8
    return R=upper part of A,  {vk}R = \text{upper part of } A,\; \{v_k\}

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

MethodSolveCost ()ConditioningUse 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

  1. 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 .
  2. Bornemann, §17 — Orthogonalization: the stable reduction , backward stability from , the -free augmented-matrix variant, and the cost comparison with the normal equations.
  3. 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 ╌╌