A13 · Lesson 28 · Conjugate gradients
Going downhill without zigzagging
For a symmetric positive definite matrix (a resistor network's nodal matrix, a stiffness matrix, a discretized Laplacian), solving is the same as finding the bottom of a bowl, . Rolling straight downhill, steepest descent, zigzags across a long narrow valley and takes forever. The conjugate gradient method picks each new direction so it doesn't undo the progress of the earlier ones. It needs no tuning parameter, costs one matrix-vector product per step, and converges in about steps instead of κ. With a good preconditioner it's the standard solver for large sparse symmetric systems.
- The contours are a bowl whose valley is κ times steeper across than along. Both methods start at the same point.
- Steepest descent (orange) goes straight downhill each time, overshoots the valley floor, and zigzags; each step shrinks the error only by .
- Conjugate gradients (dashed) takes the same first step, then turns into a direction that's "conjugate" to it and lands exactly on the minimum. In n dimensions it needs at most n steps, in exact arithmetic.
Predict
A system has . Steepest descent needs about 690 steps to gain 6 digits. About how many does CG's bound allow?
About 72: CG's error bound shrinks by per step against steepest descent's , so it scales with instead of κ = 100.
Name it
The quadratic picture
For symmetric positive definite A, the gradient of is , the negative of the residual, so the minimum of φ is the solution of .
- Steepest descent moves along r, as far as φ keeps falling. Its error (in the A-norm) shrinks by per step at worst.
- Conjugate gradients moves along directions that are A-conjugate, for , so a step along one never spoils the minimization along the earlier ones.
The algorithm
Start with , , . Repeat:
One product and a few vector operations per step; only four vectors stored.
Convergence
so reaching a relative accuracy ε takes about steps. For the model problem , giving about steps, like optimal SOR, with no ω to choose.
Preconditioning
Apply CG to a system with the same solution but a smaller κ, using a matrix M that approximates A and is cheap to solve with: diagonal (Jacobi) scaling, incomplete Cholesky, or a multigrid cycle. For nonsymmetric matrices (circuits with dependent sources) use GMRES or BiCGSTAB, built on the same ideas.
Worked example
Run CG on from zero.
Show the solution
- First step. and : so and .
- New direction. so .
- Second step. , and exact in two steps, with .
Answer , reached exactly in two steps.
Worked example
Compare steepest descent and CG for κ = 100 and 6 digits.
Show the solution
- Steepest descent. steps.
- CG, by the bound. steps.
- In practice. CG often needs fewer, because the bound assumes the worst spread of eigenvalues.
Answer about 690 steps for steepest descent against at most 72 for CG.
Worked example
A = diag(1, 1, 2, 2, 5). In how many steps does conjugate gradients solve Ax = b exactly, in exact arithmetic?
Show the solution
- What CG minimizes over. CG's k-th iterate minimizes the error over polynomials of degree k in A.
- A polynomial that removes the error. A has only three distinct eigenvalues, 1, 2 and 5, so the cubic is zero on all of them and equals 1 at λ = 0. That polynomial wipes out the error completely.
- The count. So CG finishes in three steps, though the matrix is 5 × 5.
- In general. CG converges fast when the eigenvalues come in a few tight clusters, which is what a good preconditioner arranges.
Answer three steps.
Check
A system has κ = 100. By what factor does steepest descent shrink its error per step, at worst?
Check
And CG's convergence factor for κ = 10000?
Check
Using , about how many CG steps does κ = 10000 need for ?
Check
For the model problem on a 100 × 100 grid, about how many CG steps for ? (Use .)
Check
For from , what's CG's first step length ?
Check
Which systems can plain conjugate gradients solve reliably?
Check
The model problem on a 100 × 100 grid.
(a)
About what is its condition number?
(b)
About how many CG steps reach , by ?
Check
Take one CG step on from zero.
Step 1
What is the step length ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is the first component of the new residual, ?
Explain why
Why does steepest descent zigzag in a long narrow valley, and how do conjugate directions avoid it?
In a narrow valley the downhill direction points mostly across the valley, toward the nearest wall, rather than along its floor toward the minimum. Steepest descent follows it to the lowest point on that line, which is on the far side of the floor, and the next downhill direction points back across, so the path zigzags while creeping along the valley. Each step also partly undoes the minimization done by the previous ones. Conjugate gradients chooses directions that are conjugate with respect to A, so that minimizing along a new direction leaves the earlier directions still minimized. Progress is never undone, the method reaches the exact minimum in at most n steps, and its convergence depends on instead of κ.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.