Where QR pays the square
Worth reading first: The projection and the right angle · The road that squares the problem · Orthogonal is a number.
The projection and the right angle described two roads from the one condition that defines a least-squares solution, . Expanded, it is the normal equations, , and “forming is the single worst thing that can be done to this problem”, since a condition number of a million becomes and half of the digits have gone before the solve begins. The other road factors and solves , a triangular system with . “The condition number is untouched, because every step was orthogonal and orthogonal steps have .”
That is a correct statement about . The reading it invites is a statement about the answer, that the error in the solution from QR is a modest multiple of the unit roundoff times . Wedin’s perturbation theory has said otherwise since 1973, and the textbooks say so in a line: a least-squares solution’s sensitivity to the matrix is , where is the angle between and the column space, whichever algorithm is used. The measurement here is about how that looks in practice and what it does to the comparison of the two roads, for which the earlier essay gave one verdict without looking at the angle.
A turned column moves the foot
The picture for why this can be true needs only one column.
The least-squares solution is where the perpendicular from meets the column space. Turn the column by a small angle , which is what a perturbation of does. If was lying on the column, the foot barely moves. If stands well off it, the perpendicular has length , and turning the line moves the foot by about . So the residual is a lever, and its length multiplies whatever turns the column.
With several columns, one of the directions in the column space is thin, of size . A perturbation of size can turn that direction by as much as , since a small perturbation of a thin direction is a large change of angle. And the foot’s movement along that direction, which has length , has to be expressed in by dividing again by . That gives the error in a size of , and that is . Neither factor of arises from the arithmetic of any particular route. They are both in the problem. QR is not exempt, because nothing about orthogonal steps prevents a backward error from turning a thin direction, since the backward error is small only relative to the whole matrix.
Scoring against the stored data
To measure this properly, the reference has to be right, and that takes more care here than it usually does. A designed problem has a known only until has been rounded into its stored form. Past that point the exact solution of the stored problem differs from the designed by precisely the term under test: times the rounding in . A designed solution as reference would show a square for QR on every problem, for a reason that has nothing to do with QR.
So the reference here is the exact solution of the doubles that were stored. Every double is an integer over a power of two, so the normal equations of those integers can be solved by fraction-free elimination in big integers, with no rounding anywhere, and the result converted to a double at the end. It is the first time here that a route’s error can be read with the problem’s own rounding removed from the reckoning, and the method is one the exact field developed for other reasons.
The problems are of order 24 by 6, with singular values geometric from one to , singular vectors random, and from 10 to . Five draws are taken at each setting and the median is reported. Five angles are used: a consistent system, and of , , 1 and 1,000. The routes are Householder QR ending in a triangular solve, and the normal equations solved by Cholesky.
At a tangent of one, QR’s error runs from at through at and at to at . The fitted slope is 1.98. Those are the digits of a method that squares the condition number, and the dotted line that says what “the condition number is untouched” would predict is five decades below at the top. Turn the dial to a consistent system and it comes down to that line, with a slope of 0.97 and an error of at . QR is exactly what the earlier essay said on that setting.
Then the intermediate tangent shows the two terms handing over, and the formula says where. At a tangent of the two terms in are equal at . The measurement agrees: QR’s error is at and at , still near the first term, then at and at , on the way up the second. The overall fitted slope across this tangent is 1.6, which is a straight line drawn through a corner.
What the normal equations cost, now
The road through has its error at slope two whatever the angle: at on a consistent system, at a tangent of one, and at a thousand. So it changes very little as the angle changes, while QR’s rises to meet it.
The disadvantage is a function of the angle, and the range is enormous. At the normal equations’ error is times QR’s on a consistent system, at a tangent of , 4,000 at , eleven at one, and 0.87 at a thousand. At the last of those the normal equations are, by a small margin that is within the scatter, the more accurate road. The road that squares the problem measured its factor at a consistent system and in the setting of the seminormal equations, where this gap is widest. In the last column of the figure the phrase “the single worst thing” has no content, because the road being compared with it has its own square to pay.
That matters in actual practice, because a tangent of order one is very common. A fit of data with noise in it has a residual as large as the noise, and if a model explains half the variance in the data the tangent is one. For that data, and for a matrix whose condition number is a thousand, the normal equations cost a factor of about fifteen, rather than the million that the rule of thumb suggests. Fifteen is still worth avoiding, and what it would take to do so costs little. But the advice’s justification is a different thing from what is usually said, and a person who has profiled a solver and needs a tenfold speed-up should know that this is a factor of ten in error on their problem and not of a million.
A code can read the gap in advance
The figure’s shape has a formula, and the formula uses only two numbers a code already holds after any solve. The normal equations’ error goes as : the square of the condition number from forming the matrix, and the same square on the right-hand side’s large part. QR’s goes as . Their ratio is , and that is the factor the choice of road is worth.
Over the twelve settings measured, from a gap of 950 to millions and down to about one, that ratio predicts the measured factor to within about a factor of twenty, mostly nearer. It is a statement about orders of magnitude, in a measurement of five draws per setting, and that is what is wanted from it. The formula has three regimes that a reader can keep in mind. Below a tangent of the gap is itself, the rule of thumb in its full strength, a million at . Between and one the gap is , so it depends on the angle and not the matrix: a tangent of gives about a thousand at any condition number that is well above that. And past one the gap is one.
The middle regime is the unfamiliar one. A code with a residual of about a thousandth of its data is at a gap of about a thousand, whether is or , and the size of the condition number has dropped out of the comparison altogether. The tangent is cheap to read: is available from the solution in hand. An estimate of is available from for a few more products, as the condition estimators show. So a code that has solved once can report what the other road would have cost it, or whether it can move to the cheaper one, from numbers it already has.
The residual never pays
The residual is another matter entirely. Wedin’s bound on it has no square: alone, because the residual is a projection, and a turn of the column by moves the projected vector by about times its size whatever the thin direction does. In the measurement, at a tangent of one, the residual’s relative error runs from to , with a fitted slope of 1.00, and it lies below the line for . At the solution’s error is more than a million times the residual’s.
So the same computed problem has its residual right to ten digits and its solution right to four. That goes against an instinct formed by the linear-system case, in which a small residual gives no assurance about the solution in the other direction. Here both are computed by a stable method and each is as good as its problem allows, and the two problems have different condition numbers. A code printing a residual for a poorly conditioned fit with a large residual is printing the good number. And the worst residual belongs to the route is about the separate case in which a route loses the residual’s accuracy for reasons of its own.
And the square needs a small solution
Everything above uses a problem with a random solution. A collection this size has already shown how much that choice can matter: the test that made the answer small found that building from a random picks out the smallest answer a problem can have. The same thing happens here. A second family of problems uses the same matrices and angles, but with the fit drawn at random in the column space rather than the solution drawn at random.
With a random fit, the thin directions get about the same share of the fit as any other, so the solution has a component of size about along the thinnest. A solution that long absorbs one factor of in its own relative error. QR’s error at and a tangent of one falls from to , with a slope of 1.05. At a tangent of a thousand the slope is still 1.05.
The same observation was made about right-hand sides in the road that squares the problem, in the setting of a seminormal route. What is added here is that it controls whether QR itself pays. The condition number with its correct factor reads , where is , which runs from one for a solution on the thick directions to for one on the thin. The square is real only for a solution that does not lean on the thin directions. A solution that does has already been declared large, and the relative error is measured against that large size. It is not that QR has become better there; the absolute error is the same, and the denominator has grown.
This leaves a question for anyone holding a real fit. A polynomial basis with a smooth target gives a solution with moderate coefficients, which lies at the small- end and pays the full square, and so does anything in which the true parameters are of a sensible size. The valley with no bottom is about a fit of that kind, and its coefficient digits are what this essay’s error is measuring, while a basis built from the points removes the and with it this whole effect.
What the two roads now are
The rule that survives is narrower than the one stated at the top. Prefer QR over the normal equations when the residual is small, because there it is the difference between and . When the residual is comparable to the data the gap has mostly closed, and it should be decided on other grounds: the cost of QR is twice that of forming on a tall matrix; the normal equations cannot handle above at all, where they fail with a Cholesky breakdown rather than an error, and that was not reached here. Those are good reasons and they remain.
The phrase “orthogonal steps have ” needs the same narrowing. Orthogonal steps do not amplify what they are given. So the backward error of a QR solve is small, a few units of roundoff in and , and that is what QR’s stability actually means. It does not mean that an answer from a small backward error is accurate. Whose fault it is is a question to ask of every route, and here its answer is plain. The digits lost at and a tangent of one are not lost by QR. They are the problem’s, and QR declines to lose any more of them.
Where these numbers come from
Twenty-four by six is small and five draws are few, and the small size is what makes exact arithmetic affordable. The singular values are geometric and the vectors random, so the matrix has no structure that a structured problem would. The constant in front of the square, about 1/50 of at a tangent of one, depends on the random vectors’ alignment and on the order. The slope is the measured thing here. No route with iterative refinement or with a corrected seminormal step has been measured here, and refinement is known to change the second term. And the condition numbers stop at , below the point at which the normal equations fail outright, so the comparison is not of the full range of either route.
Still open: the refinement that cannot fix it, and a larger system with the same angle
Refinement in the same precision. One step of refinement using the residual reduces a linear solve’s error to its forward limit. The prediction with a sign is that on these problems, with a tangent of one and a random solution, one or two steps of fixed-precision refinement do not lower QR’s error at by more than a factor of three, because the error is in the problem’s stored data and not in the factorisation, whereas with the residual computed in double the working precision the term falls by a factor of at least , since then the stored data are being refined against rather than absorbed.
A larger problem. The prediction is that from 24 by 6 to 200 by 50, at the same and tangent, QR’s error rises by no more than a factor of ten, and that the slope stays above 1.9, so that the square is not a small-matrix effect. If the constant grows like , which the backward error of Householder QR allows, it will show up there and not in anything measured so far.
What links here
Computed from the collection, not written here: the essays that point at this one.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- A constraint is a weight at infinity — both name condition number, exact ground truth, least squares, normal equations, qr factorisation
- Influence is decided before the data — both name condition number, least squares, normal equations, orthogonal projection, residual
- The factor a sparse code keeps anyway — both name condition number, least squares, normal equations, qr factorisation, residual
- When the matrix is wrong too — both name condition number, least squares, normal equations, orthogonal projection, residual
- Feasible and wrong — both name condition number, exact ground truth, qr factorisation, residual
- One minus a leverage is a subtraction — both name condition number, normal equations, qr factorisation, residual
Named objects
A flat tag is an object no other essay names yet.
Condition numberExact ground truthLeast squaresNormal equationsOrthogonal projectionQR factorisationResidual