🔁Linear Systems: Iterative Methods
Conjugate Gradient and Krylov Methods
Energy minimisation, steepest descent, conjugate directions, √κ convergence and GMRES
Los Angeles, 1952
The Institute for Numerical Analysis, a unit of the US National Bureau of Standards housed at UCLA, has one of the first electronic computers on the West Coast, the SWAC, and a remarkable group of mathematicians around it.
Two of them, Magnus Hestenes and Eduard Stiefel (visiting from ETH Zürich), have found the same method independently and decide to write it up together. Methods of Conjugate Gradients for Solving Linear Systems appears in the Journal of Research of the National Bureau of Standards in 1952. For a symmetric positive definite matrix it builds the solution step by step, each step optimal given everything before it, and — in exact arithmetic — it is finished after steps.
Readers saw a direct method: steps, each a matrix–vector product, about as costly as elimination and more sensitive to rounding. It lost that comparison, and for nearly twenty years conjugate gradients was a curiosity.
Then, in 1971, John Reid pointed out what everyone had missed. For the large sparse systems from PDEs, CG gives an excellent answer long before step — sometimes after a few dozen steps for a million unknowns.
Start from a different point of view. For a symmetric positive definite , define the energy
Its gradient is , so its unique minimum is exactly the solution of . For a structure, is the total potential energy, and the principle of minimum potential energy is this statement. Solving the linear system and minimising the energy are the same problem. The contours of are ellipsoids whose axes are the eigenvectors of , with lengths proportional to ; their elongation is .
Derivation
Why minimising the energy solves
Expand at for any step . Because is symmetric, , and the two cross terms combine:
The term linear in shows the gradient: . Now take to be the solution , so :
because is positive definite. Every move away from raises the energy: the solution is the unique minimum. The extra energy is half the square of the energy norm of the error, — the measure in which CG's convergence is stated below.
💡Steepest descent and its zig-zag
The obvious minimiser: go downhill. The steepest direction is the residual ; the best step along it is . Each new residual is orthogonal to the last, so in a long narrow valley the method zig-zags across it, making little progress along it. Its error in the energy norm shrinks by at most
per step.
For that is 0.98: a 2-D problem that needs 328 steps to reach .
Derivation
The best step along a line, and the zig-zag
Move from a distance along a direction . By the expansion above with , the energy along the line is a parabola in :
Setting its derivative to zero gives the exact line-search step
For steepest descent , which gives . The new residual is , and
Each new direction is exactly perpendicular to the last. In a long, narrow valley that forces the path to cross and recross the valley floor — the zig-zag — instead of running along it. (The factor per step is the worst case of this geometry, a result due to Kantorovich, quoted here without proof.)
Conjugate directions. The trouble with steepest descent is that a new step can undo what an earlier one achieved. Choose instead search directions that are A-conjugate: for . Minimising exactly along each such direction never spoils the minimisation along the previous ones, so after directions the minimum is reached. CG builds each new direction from the current residual and the previous direction — just one extra vector of memory:
The conjugate gradient method. One matrix–vector product, two inner products and three vector updates per iteration; storage for four vectors.
Derivation
Why conjugate directions never undo each other
Write any candidate point as the start plus a combination of directions, . Put it into the energy expansion with :
If the directions are -conjugate, every cross term with vanishes and the double sum keeps only . The energy becomes a sum of separate parabolas, one in each . Minimising over cannot change what is best for ; each direction can be dealt with once, in any order, and after all the minimum is reached exactly. With ordinary orthogonal directions the cross terms would not vanish, and that coupling is what makes steepest descent zig-zag.
Derivation
Where CG's and come from
CG builds the conjugate directions as it goes: , and each new direction is the new residual corrected by a multiple of the previous direction, .
The step is the exact line search above, . The exact search along left perpendicular to , so . That gives the formula used:
The residual update follows from : — no second matrix–vector product needed.
The coefficient is chosen to make the new direction conjugate to the old one, :
Simplify with two facts. From the residual update, ; and CG's residuals are mutually orthogonal, (a property proved by induction, which we take on trust here). Then , while the formula for gives . The cancels:
The remarkable fact — also proved by induction — is that conjugacy to the previous direction is enough: the new direction is automatically conjugate to all the earlier ones too. That is why CG needs to remember only one old vector.
💡Krylov subspaces and the √κ bound
After steps, lies in the Krylov subspace , and CG chooses the point in it with the smallest energy-norm error — no method using the same information can do better. A bound on that error comes from polynomial approximation with the Chebyshev polynomials we will meet in lesson 7-2; we quote it without the proof, which the further reading below gives:
The iteration count grows like , not . For the 2-D Poisson matrix , so CG needs iterations — like optimal SOR, but with no parameter to tune. And if the eigenvalues fall into a few clusters, CG converges in about as many steps as there are clusters.
📐CG on the heated plate
For on grids, CG to a relative residual of :
- : 256 unknowns, , 28 iterations;
- : 1,024 unknowns, , 59 iterations;
- : 4,096 unknowns, , 119 iterations;
- : 16,384 unknowns, , 239 iterations.
scipy.sparse.linalg.cg gives the same 119 iterations at .A large part of mathematics which becomes useful developed with absolutely no desire to be useful, and in a situation where nobody could possibly know in what area it would become useful; and there were no general indications that it ever would be so.
Nonsymmetric systems: GMRES. CG needs symmetric positive definite — the energy must be a bowl. Convection, rotation and many coupled problems give nonsymmetric matrices, and CG applied to them simply fails. GMRES (Saad and Schultz, 1986) keeps the Krylov idea but chooses to minimise the residual norm. The price: it must store an orthonormal basis of the whole Krylov subspace, one vector per iteration, so in practice it is restarted every steps — GMRES() — which can slow it down. BiCGSTAB trades optimality for short recurrences. On a convection-dominated test problem with 200 unknowns, full GMRES converges in 200 iterations, GMRES(10) in 359, and CG diverges.
⚠Rounding changes the story
In floating point the directions slowly lose their conjugacy and CG does not terminate after steps — which is precisely why it was judged a failure as a direct method. As an iterative method this hardly matters: convergence is monitored by the residual and stops long before . But it does mean the residual CG computes by recurrence can drift from the true ; check the true residual at the end.
💡Where you will use this
Structures: large 3-D solid models are solved by preconditioned CG when sparse Cholesky runs out of memory. CFD: the pressure Poisson equation by CG, momentum equations by GMRES or BiCGSTAB. Spacecraft Attitude Control and Optimal Guidance: CG minimises quadratic cost functions in model-predictive control and trajectory optimisation. Geophysics and GNSS: huge least-squares problems are solved by CG on the normal equations (CGLS/LSQR).
📚Further reading
- Jonathan Shewchuk, An Introduction to the Conjugate Gradient Method Without the Agonizing Pain (1994) — free, with pictures; it proves the residual orthogonality and the √κ bound used here.
- Lloyd N. Trefethen and David Bau, Numerical Linear Algebra (SIAM, 1997), Lectures 35 and 38, 'GMRES' and 'Conjugate Gradients'.
- Magnus Hestenes and Eduard Stiefel, 'Methods of conjugate gradients for solving linear systems', Journal of Research of the National Bureau of Standards 49(6), 409–436 (1952).
↓But there is a problem
CG needs about iterations, and is set by the problem: by the mesh (refine and grows as ), by materials (rock beside clay), by units (metres beside micrometres). We cannot change the physics.
But we can change the system. If we had a matrix that roughly resembles yet is cheap to solve with, we could hand CG the problem — same answer, perhaps a far smaller condition number.
In 1977 two Dutch researchers, J. A. Meijerink and Henk van der Vorst, showed that a deliberately sloppy Cholesky factorisation makes a superb . It turned CG into the workhorse of large-scale simulation.