Orthogonality, measured

What the appended block inherits

Modified Gram–Schmidt on [A b] solves least squares as well as Householder, although its Q is not orthogonal. A block code appends b as one more block. Block modified Gram–Schmidt inherits the rescue at every placement of the ill-conditioning: at κ = 10⁸ the appended block gives 6.9·10⁻¹⁰ where the same Q through Qᵀb gives 8.9·10⁻³. Block classical Gram–Schmidt gets the same wrong answer both ways, to the last bit. And the variant whose Q is orthogonal to 10⁻¹⁵ — two passes with Cholesky QR inside — is a hundred thousand times worse than Householder when the ill-conditioning is inside the blocks, because its R is wrong.

Worth reading first: Two Gram–Schmidts · Which pairs are allowed to be small · The projection and the right angle.

The right-hand side as one more column found that modified Gram–Schmidt is a better least-squares solver than its own Q deserves. At κ = 10⁸ its Q is 8.3·10⁻¹⁰ from orthogonal, and multiplying b by that QTQ^{\mathsf T} gives an answer wrong by 10⁻². Hand the same routine b as an extra column and it is right to 2.7·10⁻¹⁰, better than Householder. The reason is Björck and Paige’s: modified Gram–Schmidt is exactly Householder QR on the matrix with n rows of zeros stacked on top, and its last column of R is QTbQ^{\mathsf T}b computed the way that factorisation computes it, each coefficient against what was left of b after the previous ones. Classical Gram–Schmidt projects the original b every time, so its last column of R is the same dot products as QTbQ^{\mathsf T}b and it gains nothing, to the last bit.

A stable block is not a stable basis then moved to blocks, measured four block variants’ loss of orthogonality with the ill-conditioning placed between the blocks, inside them or everywhere, and left the connecting question open: “A block solver would append b to its last block, and whether the equivalence behind that result has a block form — and which of the four variants here inherits it — is the question that connects this essay back to the one before it.”

It has an answer, and the answer comes with a second finding the orthogonality measurements could not have produced: the variant whose Q is the most orthogonal of the four is, on one placement, the worst least-squares solver.

Four variants, two routes, one exact answer

The matrices are the preceding essay’s: 64 rows, 16 columns, blocks of four, κ from 10² to 10¹², with the ill-conditioning either spread through a generic matrix, placed only in the angles between blocks, or placed only inside each block. The four variants are one pass of block classical Gram–Schmidt with Householder inside each block, one pass of block modified Gram–Schmidt with Householder inside, two passes of block classical with Householder inside, and two passes of block classical with Cholesky QR inside.

Each variant now also returns its R, and each is used two ways. The first multiplies b by QTQ^{\mathsf T} and back-substitutes. The second does what a block code does when b arrives with the matrix: appends it as a block of width one and runs it through the same between-block projections as every other block — against all the finished blocks at once for a classical outer loop, against them one at a time for a modified one, and twice for the two-pass variants. Its coefficients are then the last column of R. The problems are consistent, b = Ax for a fixed x of moderate size, so that the relative error does not shrink as κ grows, and every answer is compared with the least-squares solution computed exactly in rationals from the stored doubles.

The R of a two-pass variant needs a word, because it is where the second finding lives. Each pass removes the finished blocks’ components and factorises what is left, so a block’s final columns are its original columns times the inverse of the product of the two passes’ triangular factors, and its coefficients against the finished blocks are the two passes’ coefficients carried through that product. A code that wants to solve with the factorisation has to accumulate that R, and it inherits whatever the inner factorisation got wrong in the first pass: the second pass corrects the basis, not the record of how the basis was reached. Every figure below uses R accumulated this way, and the factorisation residual ‖QR − A‖ ÷ ‖A‖ is measured for each variant alongside its orthogonality.

Block modified Gram–Schmidt inherits the rescue

Block Gram–Schmidt as a least-squares solver, blocks of four: ill-conditioning between blocks, none insideThe relative forward error of the least-squares solution against κ(A) for 64×16 consistent problems in blocks of four, median over three seeds, against the exact rational solution: block modified Gram–Schmidt with b multiplied by the transpose of Q and with b appended as one more block, block classical Gram–Schmidt (the two routes agree to the last bit), and Householder. At κ = 10⁸: block MGS through the transpose of Q times b 0.00894, as a block 6.92·10⁻¹⁰; block CGS 2.02; Householder 1.4·10⁻⁹. Errors above 9 are drawn at 9.three seeds, medianblock MGS, Qᵀb, κ 10⁸0.0089block MGS, b as a block6.9·10⁻¹⁰Householder1.4·10⁻⁹10²10⁴10⁶10⁸10¹⁰10¹²10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴110⁴10⁸κ(A)relative error of xblock MGS, Qᵀbblock CGS, either routeblock MGS, b as a blockHouseholderthe same Q in both block MGS routesonly the order in which b meets it differs
Fig. 1 Forward error against κ(A): block modified Gram–Schmidt through QTbQ^{\mathsf T}b and with b appended as a block, block classical Gram–Schmidt (both routes), and Householder. The dial moves where the ill-conditioning sits.

With the ill-conditioning between the blocks, block modified Gram–Schmidt through QTbQ^{\mathsf T}b is wrong by 1.3·10⁻⁵ at κ = 10⁶, 8.9·10⁻³ at 10⁸ and has no correct digit from 10¹⁰. The same Q and R with b appended as a block give 3.0·10⁻¹², 6.9·10⁻¹⁰ and 2.2·10⁻⁶ at 10¹² — against Householder’s 1.5·10⁻¹¹, 1.4·10⁻⁹ and 1.3·10⁻⁵. The appended block is not merely rescued to Householder’s level; like the column case, it lands a little below it.

Turn the dial. On the generic matrix the appended block gives 1.1·10⁻⁹ at κ = 10⁸ against QTbQ^{\mathsf T}b’s 0.23; with the ill-conditioning inside the blocks, 5.6·10⁻⁹ against 7.3·10⁻². At every placement and every κ from 10⁶ up, the appended block is within ten times Householder and the QTbQ^{\mathsf T}b route is at least three orders worse. The rescue does not care which level the ill-conditioning is at, which is the first difference from the preceding essay’s orthogonality curves, where each level mattered.

The reason is the same as for columns, lifted a level. A block modified outer loop removes the finished blocks’ components from b one block at a time, updating b between them, so each block’s coefficients are computed against what was left of b after the previous blocks — the sequential structure Björck and Paige’s argument uses. Inside each finished block the coefficients are dot products against the block’s own columns all at once, which is classical within the block; but each block’s Q came from Householder and is orthogonal within itself to rounding, so projecting against it all at once commits no error that projecting one column at a time would avoid. The loss of orthogonality that ruins QTbQ^{\mathsf T}b is between blocks, and between blocks the appended block is projected sequentially.

The block version is not quite the column version. Column-wise modified Gram–Schmidt on [A b] gives 2.7·10⁻¹⁰, 1.9·10⁻¹⁰ and 1.7·10⁻⁹ at κ = 10⁸ on the three placements; the block version gives 6.9·10⁻¹⁰, 1.1·10⁻⁹ and 5.6·10⁻⁹, between two and a half and six times worse. Both are inside Householder’s range at every point — Householder gives 1.4·10⁻⁹, 2.8·10⁻⁹ and 5.1·10⁻⁹ — so the difference does not change what a code should do. It is the price of projecting against four columns at once inside each block, and it is small because those four columns are orthogonal among themselves.

Block classical Gram–Schmidt gains nothing

What appending b as a block buys block Gram–Schmidt: the error through the transpose of Q over the appended block'sThe ratio of the forward error with b multiplied by the transpose of Q to the error with b appended as one more block, against κ(A), on logarithmic axes, for block modified Gram–Schmidt at three placements of the ill-conditioning and for block classical Gram–Schmidt, whose ratio is one at every κ and placement. For block MGS the ratio grows about as κ(A), reaching 5.71·10¹² at κ = 10¹².10²10⁴10⁶10⁸10¹⁰10¹²10⁻¹10¹10³10⁵10⁷10⁹10¹¹10¹³κ(A)Qᵀb error ÷ appended-block errorblock MGS, mixedblock MGS, acrossblock MGS, insideblock CGS, every placementa ratio of one: the appended block changed nothingclassical projects b against every block at once
Fig. 2 The error through QTbQ^{\mathsf T}b divided by the error with b appended as a block, against κ(A), for block modified Gram–Schmidt at three placements and for block classical Gram–Schmidt.

For block classical Gram–Schmidt the ratio is exactly one, at every κ and every placement. Its outer loop projects a new block against all the finished blocks at once, Q(QTW)Q(Q^{\mathsf T}W), so the appended b is projected as Q(QTbQ^{\mathsf T}b) and its column of R is QTbQ^{\mathsf T}b, the same numbers in the same order. Two Gram–Schmidts located the whole difference between the classical and modified algorithms in which vector each projection is taken against, and appending b as a block is one more projection; the classical loop takes it against the original.

For block modified Gram–Schmidt the ratio grows about as κ(A) — from a few hundred at 10² to 6·10¹² at 10¹² on the generic matrix. That is the ratio of κ2\kappa^2 to κ, the QTbQ^{\mathsf T}b route’s κ(A)2u\kappa(A)^2u error over the appended block’s κ(A)u\kappa(A)u. It is the column result, unchanged by blocking.

The two-pass variants, and what the appended block adds to an orthogonal Q

The two-pass Householder variant is the preceding essay’s safe choice, orthogonal to 3·10⁻¹⁵ on every placement, and as a solver it is safe too: through QTbQ^{\mathsf T}b it is within a few times Householder at every κ and placement. The appended block still helps it a little at the top of the range. At κ = 10¹² on the generic matrix its QTbQ^{\mathsf T}b route gives 2.0·10⁻⁵ and its appended block 2.7·10⁻⁶, against Householder’s 3.2·10⁻⁵; between the blocks, 3.8·10⁻⁵ against 3.6·10⁻⁶. An orthogonal Q is not the whole of QTbQ^{\mathsf T}b’s error, since forming QTbQ^{\mathsf T}b in floating point still rounds each product, and the appended block’s sequential projections round differently. The effect is a factor of up to ten and it is in the appended block’s favour everywhere it appears.

The most orthogonal Q, and the worst answer

The two-pass variants hardly need the appended block, since their Q is orthogonal to rounding and multiplying by its transpose is safe. With Householder inside, both routes stay within a few times Householder’s error everywhere. With Cholesky QR inside, on the generic matrix and between the blocks, the same is true.

With the ill-conditioning inside the blocks it is not, and nothing in the orthogonality measurement said so.

Two passes of block Gram–Schmidt with Cholesky QR inside ill-conditioned blocks: orthogonality, factorisation and solveOn 64×16 matrices whose ill-conditioning sits inside blocks of four, median over three seeds, against κ(A): the loss of orthogonality of Q, the relative residual of the factorisation QR − A, and the least-squares error through the transpose of Q times b, beside Householder's error. At κ = 10⁶ the orthogonality is 1.22·10⁻¹⁵, the factorisation residual 4.61·10⁻¹¹ and the error 1.23·10⁻⁵, against Householder's 9.31·10⁻¹¹. From κ = 10⁸ the Cholesky factorisation stops on at least one seed of three.ill-conditioned insideorthogonality at 10⁶1.2·10⁻¹⁵factorisation residual4.6·10⁻¹¹error of x1.2·10⁻⁵10²10⁴10⁶10⁸10¹⁰10¹²10⁻¹⁷10⁻¹⁵10⁻¹³10⁻¹¹10⁻⁹10⁻⁷10⁻⁵10⁻³10⁻¹κ(A)relative size‖QᵀQ − I‖‖QR − A‖ ÷ ‖A‖error of xHouseholder's errorCholesky QR stopsthe solve reads R, and R is the residual'san orthogonal Q does not make R right
Fig. 3 Two passes of block classical Gram–Schmidt with Cholesky QR inside, ill-conditioning inside the blocks: the loss of orthogonality of Q, the relative residual of the factorisation, and the least-squares error, beside Householder’s.

At κ = 10⁶ the variant’s Q is orthogonal to 1.2·10⁻¹⁵ — as orthogonal as a Q can be in double precision. Its least-squares answer is wrong by 1.2·10⁻⁵, a hundred and thirty thousand times Householder’s 9.3·10⁻¹¹, and appending b as a block changes it by nothing. From κ = 10⁸ the Cholesky factorisation stops outright on at least one of three seeds, which is the breakdown the preceding essay measured.

The third line explains it. The factorisation residual, ‖QR − A‖ divided by ‖A‖, is 4.6·10⁻¹¹ at κ = 10⁶, where Householder’s is at rounding. Cholesky QR computes R as the Cholesky factor of the Gram matrix of an ill-conditioned block, and that Gram matrix has lost half its digits before the factorisation starts; the second pass reorthogonalises Q perfectly and carries R’s error forward, since it multiplies R by the second pass’s nearly-identity factor. A least-squares solve back-substitutes with R, and an R that reproduces A only to 4.6·10⁻¹¹ gives an x wrong by κ times that, about 10⁻⁵, which is what is measured.

It also failed earlier than the breakdown suggests. At κ = 10⁴, four orders of κ before Cholesky QR stops, the variant’s answer is already 3,400 times Householder’s, and at 10² it is forty-five times. The preceding essay’s orthogonality curve for this variant is flat at rounding up to the breakdown and then ends; a solve that trusted that curve would have been wrong by three orders of magnitude on a matrix whose condition number is ten thousand.

Block Gram–Schmidt, blocks of 4: ill-conditioning inside blocks, none betweenLoss of orthogonality ‖QᵀQ − I‖ against κ(A) for four block Gram–Schmidt variants on 64×16 matrices in blocks of 4, with ill-conditioning inside blocks, none between. At κ = 10⁸: classical once, Householder inside 1.49·10⁻⁸; modified once, Householder inside 1.13·10⁻⁸; classical twice, Householder inside 3.29·10⁻¹⁵; classical twice, Cholesky QR inside breaks down. Cholesky QR inside the blocks stops at κ = 10⁸, on both passes. Classical twice with Householder inside stays at rounding level throughout.10²10⁴10⁶10⁸10¹⁰10¹²10¹⁴10⁻¹⁷10⁻¹⁴10⁻¹¹10⁻⁸10⁻⁵10⁻²10¹condition number κ(A)‖QᵀQ − I‖classical once, Householdermodified once, Householderclassical twice, Householderclassical twice, Cholesky QRκ²uκuCholesky QR stopsat κ = 10⁸classical once, Householder1.5·10⁻⁸modified once, Householder1.1·10⁻⁸classical twice, Householder3.3·10⁻¹⁵Cholesky QR stops at κ10⁸64×16 in blocks of 4, three seedsa second pass cannot undo a breakdown
Fig. 4 The preceding essay’s measurement of the same four variants on the same matrices with the ill-conditioning inside the blocks: loss of orthogonality only, where two-pass Cholesky QR is at rounding until it stops.

Set beside the solve figure, the orthogonality curve is right about everything it measures and silent on the one thing a least-squares code needs. Its two-pass Cholesky line is flat at 10⁻¹⁵ until κ = 10⁸ and absent after, and the only warning it gives is the absence. The solve’s error had meanwhile been growing as κ(A)²: 2.7·10⁻¹³, 2.3·10⁻⁹ and 1.2·10⁻⁵ at κ = 10², 10⁴ and 10⁶, eight and then five thousand times per hundredfold step, where Householder’s grows a hundredfold. That is the signature of a Gram matrix formed and factorised — a κ2\kappa^2 that never appears in Q, because the second pass removes it from Q and leaves it in R.

So an orthogonal Q is half of a factorisation. The preceding essay drew orthogonality curves, and on them this variant looked like one of the two safe ones until it broke down. As a solver it had stopped being safe three orders of κ earlier.

Orthogonality is not the axis

Loss of orthogonality against least-squares error, every block variant, placement and condition numberEach dot is one block Gram–Schmidt variant on one placement of the ill-conditioning at one κ from 10² to 10¹², median over three seeds: its the departure of Q from orthogonality across, and up, the smaller of its two least-squares routes' forward errors divided by Householder's on the same problems, so that one means as good as Householder. Two-pass Cholesky QR inside at κ = 10⁶ has orthogonality 1.22·10⁻¹⁵ and is 1.33·10⁵ times Householder's error; block MGS with b as a block at κ = 10¹² has orthogonality 6.34·10⁻⁵ and is 1.1 times it.10⁻¹⁶10⁻¹³10⁻¹⁰10⁻⁷10⁻⁴10⁻¹10⁻²110²10⁴10⁶10⁸10¹⁰10¹²10¹⁴‖QᵀQ − I‖best error ÷ Householder'sblock CGSblock MGStwice, Householdertwice, Cholesky QRleft is more orthogonal; on the dashed line, as accurate as Householderthe two are not the same axis
Fig. 5 Every variant, placement and κ: loss of orthogonality across, and up, the better of its two routes’ least-squares error divided by Householder’s on the same problem.

Drawn together, the two quantities are unrelated in the way that matters. Block modified Gram–Schmidt’s dots run across ten decades of orthogonality, from rounding to 10⁻⁴, and sit on the line of Householder’s accuracy the whole way, because its appended block reads the right thing out of an imperfect Q. Block classical Gram–Schmidt’s dots rise with its lost orthogonality, because it has no route that avoids multiplying by its imperfect Q. And the two-pass Cholesky variant’s dots sit at the far left, orthogonal to rounding, with the three from the inside placement at forty-five, 3,400 and 130,000 times Householder’s error.

The measure that would have separated them is the factorisation residual together with the route. A block QR is fit for least squares when QR reproduces A to rounding and the right-hand side is taken through the factorisation’s own sequential projections, or when Q is orthogonal and QR reproduces A. Orthogonality alone is neither condition.

What it costs, and which to choose

One pass of block modified Gram–Schmidt with b appended is the cheapest variant that solves every problem here as well as Householder. It costs one between-block pass and one Householder factorisation per block, where the two-pass Householder variant, which also solves everything, costs two of each. What it gives up is communication: a modified outer loop projects against the finished blocks one at a time, a synchronisation per block, where a classical loop does it in one matrix product. How wide the block should be and an orthogonalisation nobody calls one are the essays where that trade is priced; a code that is bound by synchronisations will prefer the classical loop twice, and a code that is bound by arithmetic will prefer the modified loop once.

In arithmetic, for m rows and n columns in blocks of p, one pass of the between-block projection costs about 2mn² and the Householder factorisations inside the blocks about 2mnp more; the second pass of the two-pass variants doubles the first term. At the sizes here that is roughly 33,000 against 66,000 multiply-adds for the projections, a factor that grows toward two as the blocks narrow relative to the matrix. Appending b adds one column’s worth of projection, about 2mn, to either.

The preceding essay’s rule was to decide which level the ill-conditioning is at and pay for stability there. For a least-squares solve there is a cheaper rule and a sharper warning. The cheaper rule: if b is appended as a block and the outer loop is modified, the level does not matter, because the appended block reads the answer out of the factorisation at Householder’s accuracy wherever the ill-conditioning sits. The warning: doing it twice restores the orthogonality of Cholesky QR’s Q and does not restore its R, and a solve needs R.

The placement that breaks the Cholesky variant is not an exotic one. The preceding essay pointed out that a block Krylov method builds its blocks from consecutive powers of the operator applied to a starting block, and consecutive Krylov vectors are nearly parallel by construction — which is ill-conditioning inside the blocks, arriving through the ordering of the columns. That is exactly where a cheap inner factorisation is most tempting, since the blocks are small and a Gram matrix is one matrix product, and exactly where this measurement says it turns an orthogonal basis into a wrong answer. A code that orthogonalises a Krylov block with Cholesky QR twice, and then solves a small least-squares problem with the R it accumulated, is solving with the factor that carries the κ2\kappa^2.

The modified variant with the appended block has no such hazard, because its inner factorisation is Householder and its right-hand side reads the answer out sequentially. Its hazard is the one already named: synchronisations. Neither the orthogonality measurement nor this one says which of those costs a given machine will feel more.

What this does not settle

Consistent problems only. The right-hand side as one more column found that a residual puts even the stable routes on a κ2\kappa^2 law, because the least-squares problem’s own conditioning contains κ2\kappa^2 times the residual; the block routes will meet the same law, and whether the appended block keeps its margin over QTbQ^{\mathsf T}b there is unmeasured.

One size, one block width, three seeds a point. The block width matters to the between-block loss — with two blocks there is one projection and classical and modified coincide — so the rescue’s size at other widths is a measurement, not an inference.

The account of why the appended block works for the modified loop is Björck and Paige’s argument lifted a level, and it is an argument. A block form of their padded-matrix equivalence, checked numerically as the column essay checked the original, would make it a measurement.

Still open: a residual, and the tree

An inconsistent right-hand side. Adding a component of b outside the range of A brings in the κ2\kappa^2 term that no route avoids. Whether the appended block and QTbQ^{\mathsf T}b then converge to the same error, as the column routes did, and at what size of residual the appended block stops being worth its synchronisations, is the measurement a least-squares code actually faces.

A tree instead of a sequence. A reduction that changes the order measured a tall-skinny QR done as a tree of small factorisations, which is how a distributed code orthogonalises a block. A tree has no sequential projection of b at all, and whether appending b to the tree’s leaves inherits Householder’s stability — each leaf’s factorisation is Householder — or loses it in the combining steps is the block question asked one level lower.

Shares its objects with

Essays that name at least two of the same things, and that neither author linked.

Named objects

A flat tag is an object no other essay names yet.

Backward stabilityBlock methodsCholesky QRCondition numberExact ground truthGram–SchmidtHouseholder reflectionLeast-squaresLoss of orthogonalityReorthogonalisation