Iterating, instead of factorising

One sequence and two recurrences

CGLS and LSQR compute the same iterates — the minimiser over a space is unique, so there is nothing to choose between them in the algebra. At κ = 10⁶ they cost 42 steps and 47. At κ = 10¹⁰ they cost 110 and 209, across four seeds, and the quantity that separates them is the orthogonality of a basis neither of them keeps.

Worth reading first: The rate the condition number predicts · Orthogonal is a number · The road that squares the problem.

This site’s oldest argument is that two algorithms can be one derivation and two computations. Two Gram–Schmidts reorders the same projections and moves ‖QᵀQ − I‖ by fourteen orders of magnitude. The road that squares the problem forms AᵀA, which is algebraically harmless and numerically the end of the matter.

Here is the same shape in a pair nobody teaches as a pair.

Both CGLS and LSQR minimise ‖b − Ax‖ over the Krylov space generated by AᵀA from Aᵀb, at every step. The minimiser over a space is unique. So their iterates are equal, not similar, and nothing in the algebra can prefer one.

Steps to a relative error of 10⁻⁶, on one 60×12 problem at five condition numbersTwo curves against the condition number on a logarithmic horizontal axis, with four seeds drawn at each. The two recurrences compute the same iterates in exact arithmetic. At κ = 10² they cost 16 and 16 steps; at κ = 10¹⁰ they cost 110 and 209.10²10⁴10⁶10⁸10¹⁰0285684112140168196224condition numberstepsnormal equationsbidiagonalisationone sequence, two costssteps at κ = 10², both16at κ = 10⁶, ratio1.1at κ = 10¹⁰, ratio1.9the same iterates in the algebraand twice the work at κ = 10¹⁰
Fig. 1 Steps to a relative error of 10⁻⁶ on a 60×12 consistent least-squares problem, at five condition numbers, with four seeds drawn at each. The curves separate where the conditioning does.

What each recurrence keeps

CGLS is conjugate gradients applied to the normal equations without forming them. It carries a residual r, a normal residual s = Aᵀr, a search direction p, and the scalar γ = ‖s‖². Each step is one product with A, one with Aᵀ, and three vector updates.

LSQR carries the Golub–Kahan bidiagonalisation instead. The recurrence produces a lower bidiagonal matrix Bₖ one column at a time, and a plane rotation is applied to it as each column appears, so that the growing least-squares problem stays solved without ever being re-solved. What is stored is three vectors and two scalars, and the cost per step is the same: one product with A, one with Aᵀ.

Two implementations of one bidiagonalisation stand behind this collection — this one and the hybrid method’s, which keeps its bases because its subject is the projected matrix. The α and β they produce are asserted to agree, and do, to zero difference in every entry.

The measurement

A 60×12 matrix built to a prescribed condition number, a consistent right-hand side, and the question: how many steps to reach a relative error of 10⁻⁶?

κ(A) bidiagonalisation, four seeds normal equations, four seeds ratio
10⁶ 41 / 40 / 44 / 42 46 / 47 / 46 / 47 1.12×
10⁸ 63 / 66 / 65 / 65 88 / 87 / 85 / 84 1.33×
10¹⁰ 110 / 111 / 104 / 115 205 / 201 / 221 / 207 1.90×

Four seeds, no overlap between the two groups at any condition number, and a separation that grows monotonically with κ. That is not a matrix being unlucky.

Two things about this table are worth being explicit about, because both are limitations rather than findings.

The Krylov space is exhausted at twelve. A twelve-column matrix has a Krylov space of dimension at most twelve, so in exact arithmetic both methods terminate at step twelve with the exact answer. Every step in the table past the twelfth is a step neither method should be taking, and both take them, which is the CG is not a direct method finding this site has asserted since its foundation. This whole comparison lives in the region where the algebra has already finished.

And the target is chosen against a floor. The forward error cannot go below about κu, so at κ = 10¹⁰ the floor is 1.1·10⁻⁶ and the target of 10⁻⁶ is close to it. Asking for 10⁻⁸ would measure the floor rather than the methods — the assertion refuses to draw it — and that boundary belongs to the error field’s identity rather than to either recurrence.

Conjugate gradients at κ = 106, against the bound κ permitsA semi-logarithmic plot of the relative A-norm error against iteration count. The measured curve falls below a smooth dashed curve showing the classical condition-number bound.0408012016020024010⁻¹⁶10⁻¹³10⁻¹⁰10⁻⁷10⁻⁴10⁻¹iteration‖e‖_A / ‖e₀‖_Ameasuredκ bound252 steps40×40, spectrum spread evenly in logbound permits 14163
Fig. 2 The behaviour underneath both curves. Conjugate gradients on a problem of κ = 10⁶ does not stop at the dimension of the space, and its rate is governed by the bound only asymptotically. Everything in this essay happens in the region to the right of where the algebra says the run is over.

What a step of each one is

The two recurrences are the same length and store the same amount, which is why the comparison is about arithmetic rather than about cost per step.

CGLS. Update the iterate along the search direction, update the residual by the same multiple of Ap, form the new normal residual Aᵀr, and take the ratio of two consecutive values of ‖Aᵀr‖² as the coefficient that makes the new direction conjugate to the old one. Two products with the matrix, three vector updates, and one scalar ratio that carries the whole conjugacy.

LSQR. Extend the bidiagonalisation by one column — a product with A, orthogonalise against the previous left vector, normalise; a product with Aᵀ, orthogonalise against the previous right vector, normalise. That produces one new α and one new β. Then apply a plane rotation chosen so that the new β is annihilated, which keeps the growing bidiagonal least-squares problem in solved form, and step the iterate along the rotated direction.

Neither keeps a basis. Both are short recurrences of fixed cost. The difference is which quantities the arithmetic is done on: LSQR’s α and β are norms of vectors the size of the problem’s own scale, and CGLS’s γ is a squared norm and its coefficients are ratios of squared norms.

One suspect can be eliminated straight away, and it is the usual one. The residual CGLS propagates — updated by a recurrence rather than recomputed from x — could drift away from the true residual, and on this problem it does not: at κ = 10¹⁰ the two agree to a part in forty at every step drawn, and the only place they part company is at the stagnation floor, where the propagated value reads 7.1·10⁻¹⁶ against a recomputed 1.1·10⁻¹⁵. That is a factor of 0.65 at the bottom of a run that has already finished, and it is not what costs a hundred steps.

Where the difference comes from

Both methods generate a basis for the same space and neither reorthogonalises. So the obvious place to look is the quantity this site measures more often than any other.

κ(A) ‖QᵀQ − I‖, bidiagonal basis ‖QᵀQ − I‖, normal-equation basis ratio
10⁴ 9.6·10⁻¹⁴ 5.4·10⁻¹³ 5.6×
10⁶ 2.6·10⁻¹¹ 4.4·10⁻¹¹ 1.7×
10⁸ 1.4·10⁻⁹ 7.9·10⁻⁹ 5.5×
10¹⁰ 3.2·10⁻⁷ 1.6·10⁻⁶ 5.0×

Measured over the first four vectors of each, and that restriction is the honest part: past twelve vectors both bases are made of rounding error and both orthogonality errors are of order one, so there is nothing to compare. Over the range where the comparison means anything the bidiagonal basis is the better one at every condition number, by a factor of about five.

A factor of five in a basis and a factor of two in a step count is not a derivation, and it is not offered as one. What it is, is the same quantity separating the two methods that separates every other pair on this site: orthogonal is a number, and the method whose number is smaller is the one that finishes first.

The residual basis of conjugate gradients, at κ = 106A semi-logarithmic plot against iteration count showing the loss of orthogonality among the residual vectors rising while the relative residual falls.05101520253010⁻¹⁷10⁻¹⁴10⁻¹¹10⁻⁸10⁻⁵10⁻²10¹iteration‖RᵀR − I‖ and ‖r‖/‖b‖step n‖RᵀR − I‖residual30×30, run for exactly n stepsexact arithmetic would end here
Fig. 3 The loss of orthogonality in a Krylov basis, from the iterative field. Neither method here keeps its basis, so neither pays for reorthogonalisation and both inherit this curve — the difference between them is where on it they sit.

Why the normal-equation recurrence is the one that suffers

The name is the clue, and it is worth stating carefully because the obvious version of the argument is wrong.

CGLS does not form AᵀA. That is the whole reason it is written the way it is, and this site has an essay about what forming it would cost: κ(AᵀA) = κ(A)², and below ε = √u the product is exactly singular. Nothing in CGLS is computed at κ².

What CGLS does do is monitor a squared quantity. Its recurrence coefficients are built from γ = ‖Aᵀr‖², and its conjugacy relations are relations in the AᵀA inner product. The vectors it generates are therefore conjugate with respect to a matrix whose condition number is κ², even though that matrix never exists — and conjugacy with respect to an operator is exactly the property that rounding error destroys in proportion to that operator’s conditioning.

The bidiagonalisation avoids that by keeping the two sides apart: its α come from Aᵀu and its β from Av, each of them a κ-level quantity, and the least-squares problem it solves at each step is bidiagonal rather than normal.

Least squares by QR and by the normal equations in binary32Relative error of the computed coefficients against epsilon, on log axes. The QR route is a flat line near the bottom; the normal-equations route climbs and then stops, at the epsilon where the cross-product matrix becomes exactly singular.10⁻⁸10⁻⁷10⁻⁶10⁻⁵10⁻⁴10⁻³10⁻²10⁻¹10⁻⁹10⁻⁷10⁻⁵10⁻³10⁻¹10¹ε in Läuchli's matrix (smaller ε, larger κ)relative error in the coefficientsAᵀA exactly singularnormal equationsQRκ from 1.7·10⁸ to 17the cliff is at √u = 2.4·10⁻⁴
Fig. 4 What forming the product costs when it is formed, from the least-squares field. CGLS does not pay this — but its conjugacy is with respect to the matrix on this figure’s axis, which is why the recurrence degrades where the figure does.

The precision does what the conditioning does

The separation is a property of the matrix and the arithmetic, and this site has a slider for the second of those. One matrix, one target, three precisions:

significand bits bidiagonalisation normal equations ratio
53 40 / 40 / 40 / 41 44 / 44 / 46 / 44 1.11×
32 105 / 102 / 104 / 104 139 / 149 / 151 / 165 1.46×
24 neither reaches the target

Twenty-one significand bits fewer, on the same κ = 10⁶ problem, and the separation widens from 11% to 46% — reproducing what raising κ by four decades did at double precision. At 24 bits the target of 10⁻⁴ is below the forward-error floor and neither method reaches it, which is the boundary again.

That immediately suggests a single governing parameter, and this site has one to hand: κu, the product that decides the mixed-precision field’s threshold and the interval field’s boundary. It is the natural guess and it is wrong.

bits κ κu ratio
53 10¹⁰ 1.1·10⁻⁶ 1.63×
32 10⁴ 2.3·10⁻⁶ 1.04×

The second case has the larger κu and much the smaller separation. A quantity that orders two measurements the wrong way round is not the quantity that governs them, and that is asserted here rather than being left as a sentence — the assertion states the counterexample and would fail if some later change made κu fit after all.

What it does not change

Three things, and they matter because a factor of two in an iteration count is easy to over-read.

The answers agree. At the step each reaches its own best, the two iterates differ by less than either differs from the truth. Neither method is returning a wrong answer; one is taking longer to arrive.

The floor is the same. Both bottom out at about κu, which is where the problem puts them. No recurrence can do better and neither does.

And at moderate conditioning there is nothing in it. At κ = 10² the two agree to 3.3·10⁻¹³ at step six and cost the same number of steps. A reader whose problems are well conditioned has been choosing between these two methods on documentation and taste for thirty years, and has been right to.

Backward and forward error against the condition numberA log–log plot over twelve decades of condition number. The backward error is a flat line at ten to the minus sixteen; the forward error rises in proportion to the condition number.110²10⁴10⁶10⁸10¹⁰10¹²10¹⁴10⁻¹⁷10⁻¹⁴10⁻¹¹10⁻⁸10⁻⁵10⁻²10¹condition number κ(A)relative errorforward errorbackward errorpredicted: κ · u8×8, 20 seeds per κ; dashed is the worstthe problem worsens, not the method
Fig. 5 The identity that puts the floor there. The backward error stays at the level of rounding across twelve decades of conditioning; the forward error climbs with κ. Both methods here are backward-stable and both inherit the same forward error, which is why the comparison has to be about cost rather than accuracy.

Where the difference does not appear at all

The two methods that this essay separates are the two methods the regularisation field uses, and on that field’s own problem the separation is invisible.

On the 64-point deconvolution at 1% noise both reach their best error at step 20, and both reach 0.142587. Their iterates agree to 5.3·10⁻¹⁶ at step five, 9.2·10⁻¹⁶ at step ten, and only 7.9·10⁻⁶ at step twenty — by which point the run is over, because the error has turned and everything after it is worse.

The reason is worth stating because it is the practical answer to which should be used. Semi- convergence stops an ill-posed run after a couple of dozen steps, and a couple of dozen steps is before either recurrence has degraded. The comparison in this essay needs a hundred steps to become visible, and no ill-posed problem gets a hundred useful steps.

So the pair separates on consistent, ill-conditioned problems run to convergence, and not on ill-posed ones stopped early. Those are different jobs, and the difference between the two recurrences matters for exactly one of them.

Conjugate gradients on an ill-posed problem at 0.10% noiseTwo curves against the step count on a logarithmic vertical axis. The relative residual falls at every one of the 120 steps without exception. The error against the true signal falls to 0.1050 at step 44 and then climbs, reaching 0.56 by the end — 5.3 times its best value.015304560759010512010⁻³10⁻²10⁻¹1steprelative sizeleast error: 44discrepancy stop: 27errorresidualthe knob is an integerleast error, at step44error there0.11error at step 1200.56the residual falls at every stepthe error turns and keeps rising
Fig. 6 Why the ill-posed problem never reaches the region where the two methods differ. The run is over at step twenty; the separation in the table above needs a hundred steps of a problem that has an answer at the end of them.

And what it says about a rule this site keeps finding

The pattern is now familiar enough to be worth naming. Classical against modified Gram–Schmidt. The normal equations against a QR factorisation. Elimination with and without a row interchange. A reduction tree against a Householder sweep. And now two recurrences for one sequence of iterates.

In every one of those pairs the algebra is silent and the arithmetic is not, and in every one of them the difference is invisible until the conditioning is bad enough. That is what makes the class dangerous rather than merely interesting: a method chosen on well-conditioned test problems, where every member of the pair agrees to twelve digits, carries a factor that only appears on the problems that were hard enough to need a numerical method in the first place.

Loss of orthogonality against condition number, in binary64A log–log plot of the norm of Q-transpose-Q minus the identity against condition number. Classical Gram–Schmidt rises steeply, modified Gram–Schmidt rises gently, and Householder is flat.110²10⁴10⁶10⁸10¹⁰10¹²10⁻¹⁷10⁻¹⁴10⁻¹¹10⁻⁸10⁻⁵10⁻²10¹condition number κ(A)‖QᵀQ − I‖classicalmodifiedHouseholderκ²uκu8×8, eight seeds per κ, binary64all three reconstruct A
Fig. 7 The oldest instance of the pattern on this site: two orthogonalisations of the same matrix, the same algebra in a different order, and ‖QᵀQ − I‖ fourteen orders of magnitude apart. The pair in this essay is the same shape with a much smaller separation, which is why it took a table of four seeds to see it.

Which one to write, then

The answer this measurement supports is narrower than a recommendation, and it is worth stating in the narrow form.

If the problem is well conditioned, the two methods are the same method and the choice is documentation. If it is ill-posed and stopped early, the two are the same method for the length of the run that matters. If it is consistent, ill-conditioned, and run to convergence — a least-squares fit with a nearly rank-deficient design, solved iteratively because the matrix is too large to factorise — the bidiagonal recurrence costs half as many products with A, at four seeds and at every condition number above 10⁶.

That third case is the one the method was published for, and it is also the case where the alternative was already available and already looks fine on any test problem short of it. Which is the shape of every entry in this class: the pair agrees exactly where a comparison is easy to run, and separates exactly where running it is expensive.

Classical and modified Gram–Schmidt: the same subtraction, in a different orderTwo panels of pseudocode differing in one argument, with the resulting pairwise dot products of the computed columns listed beneath each.for each previous column i, subtract the projection of column j onto qᵢclassicalr[i][j] = qᵢ · a[j] ↑ the ORIGINAL columnv = v − r[i][j] · qᵢthe three worst |qᵢ · qⱼ|:columns 7 and 8: 1columns 6 and 8: 0.13columns 6 and 7: 0.13modifiedr[i][j] = qᵢ · v ↑ what is LEFT of itv = v − r[i][j] · qᵢthe three worst |qᵢ · qⱼ|:columns 1 and 8: 4.4·10⁻⁷columns 2 and 8: 2.7·10⁻⁷columns 3 and 8: 2.4·10⁻⁸The two R factors agree to 1.2·10⁻⁶ relative. The two Q factors do not.the 8×8 Hilbert matrixone word, eight orders
Fig. 8 The oldest pair on this site: the same projections in a different order, and ‖QᵀQ − I‖ fourteen orders of magnitude apart. The pair in this essay is the same shape with a smaller separation.
Fitting the same degree-11 polynomial in two basesOn the left, the data and two fitted curves that lie on top of each other. On the right, the condition numbers of the two design matrices, ten orders of magnitude apart.00.10.20.30.40.50.60.70.80.910.20.40.60.81xyboth fits, drawn on top of one anothercondition number of the design matrixmonomial1.2·10⁸Chebyshev2.5largest fitted coefficientmonomial113Chebyshev0.51rms residual: 3.9·10⁻⁶ and 2.9·10⁻⁷ — the data is fitted either way.30 points, degree 11, single precisionthe basis is part of the problem
Fig. 9 What a basis’s conditioning does to what is built on it. Neither recurrence here reorthogonalises, so both inherit this curve and the difference between them is where on it they sit.
Forward error of a 8×8 Hilbert solve at eight precisionsA bar for each significand width from 12 to 53 bits showing the relative error in the computed solution, with the condition number times the unit roundoff marked as a prediction.κ = 1.5·10¹⁰ · the exact answer is (1, 2, …, 8)12 bits4.116 bits1.620 bits1024 bits0.530 bits0.5636 bits0.005943 bits5.5·10⁻⁶53 bits3.2·10⁻⁸dashed: κ · unit roundoffone matrix, eight arithmeticsmeasured against a known answer
Fig. 10 Precision as the knob, on a problem with an exact answer. Lowering it reproduces what raising κ does to the pair in this essay — and κu, the obvious governing product, does not order the two.

What the drag does

The slider is the accuracy asked for. A tighter target costs both methods more steps and costs the normal-equation recurrence proportionally more of them: at 10⁻³ the ratio at κ = 10¹⁰ is smaller than at 10⁻⁶, because the early steps of the two runs are nearly identical and the divergence accumulates.

The slider stops at 10⁻⁶ and the reason is the floor. At κ = 10¹⁰ the forward error cannot reliably go below 1.1·10⁻⁶ whatever either method does, so a target of 10⁻⁷ is a target neither reaches and the figure would be drawing a boundary of the problem rather than a difference between two methods. The generator refuses it, which is the assertion doing what the site’s assertions are for.

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.

CglsForward errorGolub kahan bidiagonalisationKrylov subspaceLsqrNormal equationsOrthogonality lossPlane rotationShort recurrenceUnit roundoff