How can we put zeros below the diagonal of a matrix without changing any lengths? Elimination creates zeros with row operations, but those operations generally change the length of , which is exactly what a least-squares problem minimizes. A reflection changes no lengths, and one well-chosen reflection sends an entire column to a multiple of . This lesson constructs these Householder reflectors, chooses their sign so that the vector defining each one is formed without cancellation, assembles them into a QR factorization, and reads both the least-squares solution and its residual from it. Everything here is real, a tuple such as stands for a column vector, and is the Euclidean norm.
Key terms
Householder reflector
Definition Let be nonzero. The Householder reflector determined by is the matrix
The matrix is the orthogonal projector onto the line spanned by . So reverses the component of a vector along and keeps the component perpendicular to . In particular , and whenever . In this is the mirror reflection in the plane perpendicular to , and the same formula works in every dimension. The matrix is symmetric and orthogonal, and it is its own inverse. Indeed , and because the scalar in the middle cancels one factor of the denominator,
Hence and
Consequently for every , inner products are preserved as well, and . Multiplying by a nonzero number does not change . Over one uses , which is Hermitian and unitary, with the phase of the first entry in place of the sign chosen below. This lesson stays with real matrices.
In plain words A Householder reflector is a mirror. It flips the single direction and leaves everything perpendicular to alone, so it moves vectors without stretching them.
Example For we have , so
Then , and the vector , which is perpendicular to , satisfies . Each column of has length , and the columns are mutually perpendicular, as orthogonality requires.
Stable sign choice
Definition Let with , and suppose its tail is not zero. Let , let if and if , so that the sign of is taken to be , and set
Then , and the reflector of satisfies . To check this, note that , so
Both are positive because , and therefore
The other sign, , also gives a reflector that sends to in exact arithmetic. Its first entry, however, has absolute value . When is close to the axis this is a difference of two nearly equal numbers, and such a difference can lose most of its significant digits. The stable choice adds the two nonnegative numbers and , so this step has no cancellation. That explains the design choice. It is not by itself a proof that the whole algorithm is stable, which needs an error analysis of every operation, including the computation of .
When the tail is already zero, including the case , there is nothing to eliminate, and the algorithm uses . A reflector is never formed from the zero vector, whose denominator would be . A zero leading entry with a nonzero tail is not such a case. There the formula applies with .
In plain words Reflect the column onto the first axis, on the side opposite to its first entry, or on the negative side when that entry is zero. Then the vector that defines the mirror is built from a sum of two lengths rather than a difference, and nothing is lost to cancellation.
Example For we get and , so , a multiple of , and is the reflector of the previous example. Here and , so .
To see the cancellation, take , with , and suppose is rounded to six significant digits, giving . The other sign computes the first entry in place of the true value of about , so the computed vector is . Its reflector is , which sends to and eliminates nothing. The stable choice computes , within a relative of the true value , and its reflector sends to about , very close to the target .
Householder QR factorization
Definition Let with . For , look at column of the current matrix in rows through . If its entries below row are all zero, take . Otherwise take the stable reflector of size that sends this piece of the column to a multiple of its first unit vector. Embed it as
which acts only on rows through . When the last step is the identity, since a single entry has no tail. The zeros already created in columns survive, because in those columns rows through are zero and sends zero to zero. After the last step
where is upper triangular and the zero block has rows. Each is symmetric and orthogonal, so is orthogonal with , and
This shows that every real matrix with has such a factorization, with no assumption on its rank. If has full column rank , then has the same rank, so it is invertible and its diagonal entries are nonzero. They may be negative. Changing the sign of column of together with row of gives another factorization, so a nonnegative diagonal can always be arranged if a convention requires it. In practice is often stored as the list of vectors that define the reflectors rather than multiplied out.
In plain words Each reflector clears one column below the diagonal and leaves the columns already cleared alone. After reflections the matrix is upper triangular, and the product of the reflectors records the way back to .
Example Let
The first column is , and the reflector of the previous examples gives
In rows and the second column is . Its leading entry is zero but its tail is not, so a reflector is needed. With and the vector is , and its reflector has rows and , which sends to . Hence
and
Multiplying back, times the first column of is , and times the first column plus times the second is . So .
Triangular solve
Definition Let be upper triangular with nonzero diagonal entries , and let . The system has exactly one solution, found by back substitution from the last equation upward,
for in turn. It takes about arithmetic operations and never forms . A lower triangular system is solved the same way from the top down, by forward substitution. If some , the matrix is singular and the substitution breaks down at that step. For a QR factorization this happens exactly when does not have full column rank, and a rank-revealing method such as QR with column pivoting or the SVD is then needed. To solve a square invertible system with , apply and solve . Least squares uses the same step on the first coordinates of .
In plain words A triangular system can be solved one unknown at a time. The last equation contains only the last unknown, and each equation above it brings in just one new unknown.
Example For the matrix above and ,
The triangular solve uses the first two entries. The second equation gives , and the first equation then gives . The third entry is not used by the solve. It returns below as the residual.
Full and reduced QR
Definition Let with . A full QR factorization is with orthogonal and upper triangular in its top block and zero in its last rows. Split into its first columns and its last columns . The zero rows of multiply , so the reduced, or thin, QR factorization is
When the matrix is not orthogonal, since . If has full column rank, then is invertible, the columns of form an orthonormal basis of the column space of , the matrix is the orthogonal projector onto that column space, and the columns of form an orthonormal basis of its orthogonal complement. In that case the reduced factorization with positive diagonal entries in is unique. When the block is not unique, since any orthonormal basis of the complement will do. When there is no , and the full and reduced factorizations coincide.
In plain words For a matrix with independent columns, the full factorization extends an orthonormal basis of the column space to an orthonormal basis of all of . The reduced one keeps only the part that spans the column space. That part is enough to rebuild , but it does not show the residual, which then has to be computed separately.
Example For the matrix above, consists of the first two columns of , the block is the third column , and
The projector onto the column space is
Changing the signs of both columns of and both rows of gives the reduced factorization with positive diagonal,
which is what Gram-Schmidt produces from the columns of .
Least-squares residual from QR
Definition Let with have full column rank and a full QR factorization with as above, and let . Because preserves lengths and , for every
The two terms come from the first and the last coordinates, which are perpendicular groups. The second term does not depend on . The first is zero exactly for , computed by a triangular solve, so is the unique least-squares solution, and the minimal residual norm is
The residual itself is , the component of perpendicular to the column space, so . It is zero exactly when lies in the column space of . Watch for this when only the reduced factorization is kept. The triangular system is then solved exactly, which says nothing about whether lies in the column space. The omitted component still exists and can be computed as .
In plain words In the orthonormal coordinates given by the columns of , the first coordinates of can be matched exactly and the others cannot be matched at all. Those leftover coordinates make up the residual, and their length is the smallest possible error.
Example For and above, gave . The leftover coordinate is , so the minimal residual norm is , and the residual is times the third column of ,
Its length is , and . In exact arithmetic the reduced factorization gives the same norm through . In floating point this difference of squares loses most of its digits when the residual is small, so it is better to compute the vector directly, or to read the residual norm from the last entries of . By contrast, the right-hand side has , and the zero last coordinate shows that lies in the column space.
Check yourself
- Find the stable Householder vector for and compute . What does the algorithm do with the column ?
Show the answer
The first entry is , so , and . Hence , with and , so . A zero leading entry is no reason to skip the step, because the tail still has to be eliminated.
The column already has a zero tail, so the algorithm uses the identity and leaves it alone. The negative entry on the diagonal of is perfectly acceptable.
- A matrix has the reduced QR factorization with
For , find the least-squares solution, the residual and its norm.
Show the answer
First . Back substitution gives , so , and then , so .
The matrix is with rows , , and , so and , with norm . As a check, , and . The triangular system was solved exactly, yet the residual is not zero. It is the part of that the reduced factorization does not show.
- For , find the stable vector and . A classmate always uses , whatever the sign of . Check that this also works in exact arithmetic for , and explain what goes wrong for when is rounded to six significant digits.
Show the answer
Here and , so , with and . Then .
The classmate’s vector is , with and , so its reflector sends to . That is correct in exact arithmetic, but the first entry is a difference.
For we have , which rounds to . The classmate’s first entry becomes instead of about , so the computed vector is . Its reflector is , which sends to and leaves the tail in place. The stable rule computes , with no cancellation, and its reflector sends to about .