Solving a system can mean walking down to the bottom of a bowl. Watch the steepest path zig-zag, and a smarter one arrive in two steps.
Zig-zag or two steps
Two ways down the bowl ½ x^T A x, seen from above.
The bowl f = ½ x^T A x seen from above, A = [2 1.6; 1.6 2]: each ellipse is one height, the bottom at the origin. The start is (10, −8), height 36.
Describe this picture
A contour map of the bowl for , seen from above on a grid: long thin ellipses round the bottom, at the origin, each through one of the stops below. Steepest descent starts at and walks , then , and on, in zig-zag steps that alternate across and up, each cutting the height to 0.64 of what it was; it needs 31 steps to get within a millionth of the bottom. Then conjugate gradients starts from the same point, goes to and then straight to , and stops. Readouts count the steps of each method and give the height reached. One control after the clip: a slider for the off-diagonal entry , from 0 to 1.9 in steps of 0.1. At 0 the bowl is round and both methods need one step; towards 1.9 it stretches, while conjugate gradients still needs two.
Elimination on large sparse systems
Elimination solves exactly. For a simulation of heat in a metal plate, or air over a wing, there may be a million unknowns, and each equation involves only a few neighbours: most entries of are zero. Elimination fills those zeros in, and the work and memory explode. A matrix times a vector, though, costs only one product per nonzero entry. So large systems are solved by making a guess and improving it, again and again, with matrix-vector products only. I write the guess after steps as , with the step number in brackets so it never reads as a power.
Sweeps: Jacobi and Gauss–Seidel
Split into its diagonal, the part below it and the part above it: . Each equation can be solved for its own diagonal unknown, using the current guess for the others. Doing that for every equation at once is a Jacobi sweep:
Gauss–Seidel does the same, one equation at a time, using each new value as soon as it has it.
Do the sweeps converge? The error is multiplied by a fixed matrix each sweep, for Jacobi . After sweeps it is times the first error. By Diagonalisation and matrix powers, that dies away exactly when every eigenvalue of has size below 1. The largest size is the spectral radius, , with one argument; it is not the correlation of statistics. The sweeps converge when , and each sweep cuts the error by about that factor.
Sweeps
The largest error after each sweep, for Ax = (1, 0, 1) with A = [2 −1 0; −1 2 −1; 0 −1 2].
The largest error after each sweep, starting from x = 0, where every entry is 1 away from the answer (1, 1, 1).
Describe this picture
Two rows of bars for the system , whose answer is . Each bar is the largest error after one more sweep, for sweeps 1 to 6, starting from , and is labelled with its value. Jacobi’s row appears first: 1, 0.5, 0.5, 0.25, 0.25, 0.125, halving every two sweeps. Then Gauss–Seidel’s row: 0.75, 0.375, 0.1875, 0.0938, 0.0469, 0.0234, halving every sweep. There is no control.
For this matrix , with eigenvalues 0 and , so : two sweeps halve the error. For Gauss–Seidel , the square: one sweep halves it.
The catch is size. On the same pattern with 100 unknowns, , and cutting the error to takes more than 28 000 sweeps.
Down the bowl
There is a better way to think when is symmetric and positive definite. By Positive definite matrices, the function
is a bowl, and its lowest point is where the slope is zero: . Solving the system is finding the bottom. The residual is minus the slope, so it points downhill.
Steepest descent walks downhill along , as far as the ground keeps falling, then looks again. The best step length along is
and . Each new direction is at a right angle to the last, which is why it zig-zags. In a long thin bowl, downhill points mostly across the valley, not along it. The height is multiplied by at most the factor per step, where is the condition number of Conditioning: for the bowl in the picture, and the factor is .
Conjugate gradients
The trouble with steepest descent is that each step spoils some of the progress of the step before. Conjugate gradients chooses each new direction so that it doesn’t. It mixes the new downhill direction with the last direction:
and steps along by the best length. The directions are chosen so that each step finishes off its own direction for good. In dimensions there are only directions to finish, so, apart from rounding, it reaches the bottom in at most steps. Long before that, its error shrinks on average by at least per step, up to a factor of 2 overall: 0.5 for , against steepest descent’s 0.8.
In signal processing · adaptive filters
Adaptive filters: LMS, in the signal processing course, tunes a filter by steepest descent, one noisy step per sample, down the bowl of its mean squared error. Its speed depends on the condition number of the input’s correlation matrix, exactly as here.
Worked example
1. Jacobi, from on the tridiagonal system: , , , , . The largest error halves every two sweeps.
2. Gauss–Seidel, the same system: , , , . The largest error halves every sweep.
3. Steepest descent on with , from : and , so . Then , and . The height goes 36, 23.04, 14.7456: a factor of 0.64 each step, the worst case exactly. After 10 steps 0.0115 of it is left, and reaching takes 31 steps.
4. Conjugate gradients, same start. The first step is the same, to . Then and
With , the step length is , and
The bottom, exactly, in two steps.
Try these before you read the answers.
- How many conjugate-gradient steps can a system need? At most 2.
- Steepest descent’s factor per step at ? 0.8, so 0.64 for the height.
- Set the off-diagonal to 0 in the picture. How many steepest-descent steps? One: the bowl is round, and downhill points at the bottom.
Where you’ll meet this
Simulation. Heat, stress and flow simulations with millions of unknowns solve sparse, symmetric positive definite systems by conjugate gradients, usually with a cheap first guess at the inverse to make smaller.
Medical scanners. Building a picture from a scanner’s measurements is a huge least-squares problem, solved by iteration.
Learning machines. Training a model by small downhill steps on its error is steepest descent, and its slow zig-zag in long valleys is the problem this page shows.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Splitting | diagonal, below, above | |
| Jacobi | all at once | |
| Convergence | error shrinks by about per sweep | |
| Bowl | bottom at | |
| Residual | points downhill | |
| Steepest descent | factor per step | |
| Conjugate gradients | at most steps; factor |