Search

Search papers and lessons

Preconditioning

Level 3 · 10 min read

Preconditioning rescales a linear system with a cheap approximate matrix so an iterative solver needs far fewer steps, while the answer stays the same.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Discrete math
  • Probability
  • Losses & regularization
  • Optimizers
  • ReadReady to readNot yet

TL;DR

Many large problems reduce to a system of linear equations Ax=bA\mathbf{x} = \mathbf{b}, solved by repeated steps rather than in one go. If AA is badly scaled, those steps crawl. Preconditioning multiplies the system by a cheap approximation of AA's inverse, so the steps converge in far fewer rounds, and the answer does not change.

Builds on: Gradient Descent, Matrix Inverse, Positive Definite Matrix · Leads to: Conjugate Gradient, Condition Number

Where it's used

Finite-element and finite-difference simulations. Heat flow, structural loads and electric fields are discretised with the finite-difference method or finite elements into millions of unknowns. The resulting matrix is sparse and symmetric, and at this size an iterative solver is the practical way to solve it. Most production solvers of this kind use a preconditioner.

Least-squares fitting at scale. Large regression problems and Gauss–Newton steps in nonlinear fitting reduce to solving a system with a symmetric positive definite matrix. Preconditioners keep the solve time manageable when the data columns are of very different sizes.

Training neural networks. Adaptive optimisers such as Adam, which scale each parameter by a running estimate of its gradient size, are preconditioned gradient methods with a diagonal preconditioner. Scaling each parameter by its own typical step size is the same idea in a different setting.

How it works

Solve one equation with one unknown, 4x=24x = 2, whose answer is x=0.5x = 0.5. Use the simplest iterative rule, a plain form of gradient descent: start from a guess, measure how far off the equation is, and step the guess to reduce that error.

  1. Plain iteration with step 1. The update is xnew=x−(4x−2)x_{\text{new}} = x - (4x - 2). Start at x=0x = 0. The first step gives x=0−(0−2)=2x = 0 - (0 - 2) = 2. Check: 4⋅2=84 \cdot 2 = 8, which is 6 too large.
  2. Next step. From x=2x = 2, the update gives x=2−(8−2)=−4x = 2 - (8 - 2) = -4. The guesses are growing, not closing in on 0.50.5. The step is too big for this matrix. Check: −4-4 is further from 0.50.5 than 22 is.
  3. Divide the step by a preconditioner. Pick m=5m = 5, a cheap approximation to a=4a = 4. The update becomes xnew=x−(4x−2)/5x_{\text{new}} = x - (4x - 2)/5. Start at x=0x = 0 again. The first step gives x=0+2/5=0.4x = 0 + 2/5 = 0.4. Check: the error is now 0.5−0.4=0.10.5 - 0.4 = 0.1, down from 0.50.5.
  4. Keep going. From 0.40.4: x=0.4−(1.6−2)/5=0.48x = 0.4 - (1.6 - 2)/5 = 0.48. From 0.480.48: x=0.48−(1.92−2)/5=0.496x = 0.48 - (1.92 - 2)/5 = 0.496. Check: the errors are 0.10.1, 0.020.02, 0.0040.004, so each step multiplies the error by 0.20.2.
  5. Read the rule. The error shrinks by the factor 1−4/5=0.21 - 4/5 = 0.2. A preconditioner close to aa makes that factor close to 0.
flowchart LR
  A[Current guess x] --> B[Residual b minus A x]
  B --> C[Apply cheap inverse of M]
  C --> D[Update x]
  D --> A

The math

Definition: Preconditioner

For a symmetric positive definite matrix AA, a preconditioner is a symmetric positive definite matrix MM such that M≈AM \approx A in some sense, and such that solving with MM is cheap. Preconditioning replaces Ax=bA\mathbf{x} = \mathbf{b} by the equivalent system M−1A x=M−1bM^{-1}A\,\mathbf{x} = M^{-1}\mathbf{b}.

Step 1 in symbols: the update

Let the residual be rk=b−Axk\mathbf{r}_k = \mathbf{b} - A\mathbf{x}_k, which measures how far the current guess is from solving the equation. A preconditioned step with step size α\alpha, which applies the inverse of MM, is

xk+1=xk+α M−1rk.\mathbf{x}_{k+1} = \mathbf{x}_k + \alpha\, M^{-1}\mathbf{r}_k.

In the 1D example, A=4A = 4, b=2\mathbf{b} = 2, M=5M = 5 and α=1\alpha = 1, which gives the update of step 3.

Step 2 in symbols: the error

Let ek=xk−x∗\mathbf{e}_k = \mathbf{x}_k - \mathbf{x}^{*}, the difference from the true solution. Since rk=−Aek\mathbf{r}_k = -A\mathbf{e}_k,

ek+1=(I−αM−1A) ek.\mathbf{e}_{k+1} = (I - \alpha M^{-1}A)\,\mathbf{e}_k.

The matrix G=I−αM−1AG = I - \alpha M^{-1}A decides everything. In 1D, G=1−4/5=0.2G = 1 - 4/5 = 0.2, which is step 4's factor.

Step 3 in symbols: the eigenvalues

The eigenvalues of M−1AM^{-1}A are λmin⁡≤⋯≤λmax⁡\lambda_{\min} \le \dots \le \lambda_{\max}, and the condition number of the preconditioned problem is

κ(M−1A)=λmax⁡λmin⁡.\kappa(M^{-1}A) = \frac{\lambda_{\max}}{\lambda_{\min}}.

This is the ratio of largest to smallest eigenvalue, the condition number. A large value means some directions are stretched much more than others, so the solver zig-zags. Choosing α=1/λmax⁡\alpha = 1/\lambda_{\max} makes every error direction shrink by at least the factor 1−λmin⁡/λmax⁡=1−1/κ1 - \lambda_{\min}/\lambda_{\max} = 1 - 1/\kappa per step. Thus the number of steps grows with κ\kappa, and a preconditioner that drives κ\kappa toward 1 makes the solver fast.

In practice the preconditioner is used inside the preconditioned conjugate gradient method, which needs only products with AA and solves with MM, never the inverse itself.

Worked examples

Example
1. A preconditioner that is too rough

Solve 3x=63x = 6, whose answer is x=2x = 2, with A=3A = 3 and M=1M = 1, then with M=4M = 4.

  1. The rule is xnew=x−(3x−6)/Mx_{\text{new}} = x - (3x - 6)/M. Start at x=0x = 0.
  2. With M=1M = 1 the first step is x=0−(0−6)=6x = 0 - (0 - 6) = 6. The error is 44.
  3. With M=1M = 1 the second step is x=6−(18−6)=−6x = 6 - (18 - 6) = -6. The error is −8-8, larger than before, so this diverges.
  4. With M=4M = 4 the first step is x=0+6/4=1.5x = 0 + 6/4 = 1.5. The error is −0.5-0.5.
  5. The second step is x=1.5−(4.5−6)/4=1.5+0.375=1.875x = 1.5 - (4.5 - 6)/4 = 1.5 + 0.375 = 1.875. The error is −0.125-0.125.
  6. The error factor is 1−3/4=0.251 - 3/4 = 0.25, and 0.5⋅0.25=0.1250.5 \cdot 0.25 = 0.125, so the error keeps shrinking.

Interpretation: the factor is 1−A/M1 - A/M, which has size below 1 only when 0<A/M<20 \lt A/M \lt 2. With A=3A = 3, M=1M = 1 fails that test and M=4M = 4 passes it, so MM must be close enough to AA.

Try it: Solve 3x=63x = 6 with M=2M = 2. Find the error factor and whether the method converges. Answer: 1−3/2=−0.51 - 3/2 = -0.5, so the factor has size 0.50.5 and the sign flips each step. It converges, with the error halving and alternating in sign.

Example
2. Two directions with very different stiffness

Let A=diag(1,100)A = \mathrm{diag}(1, 100), a diagonal matrix, and b=(1,100)\mathbf{b} = (1, 100), whose exact solution is x∗=(1,1)\mathbf{x}^{*} = (1, 1). The condition number is κ=100/1=100\kappa = 100/1 = 100.

  1. Plain gradient descent uses step α=1/λmax⁡=0.01\alpha = 1/\lambda_{\max} = 0.01. Start at x0=(0,0)\mathbf{x}_0 = (0, 0).
  2. The residual is r0=b−Ax0=(1,100)\mathbf{r}_0 = \mathbf{b} - A\mathbf{x}_0 = (1, 100). One step gives x1=(0,0)+0.01 (1,100)=(0.01,1)\mathbf{x}_1 = (0, 0) + 0.01\,(1, 100) = (0.01, 1).
  3. The second coordinate is now exactly 11. The first coordinate has error 1−0.01=0.991 - 0.01 = 0.99.
  4. Each step multiplies the first error by 1−λmin⁡/λmax⁡=0.991 - \lambda_{\min}/\lambda_{\max} = 0.99. Reaching an error of 0.010.01 requires 0.99k≤0.010.99^k \le 0.01, which takes k=459k = 459 steps.
  5. Now precondition with M=diag(1,100)M = \mathrm{diag}(1, 100), which equals AA here. Then M−1A=IM^{-1}A = I and M−1b=(1,1)M^{-1}\mathbf{b} = (1, 1).
  6. One step gives x1=(1,1)\mathbf{x}_1 = (1, 1) exactly.

Interpretation: the condition number 100 costs about 459 steps in the plain method and one step with the preconditioner.

Example
3. The one-dimensional Poisson problem

Discretise a heat-flow problem on a line with the finite-difference method, using 100 interior points. The matrix is tridiagonal with 2 on the diagonal and −1-1 beside it. Its condition number is about 4(n+1)2/π24(n+1)^2/\pi^2 with n=100n = 100.

  1. Compute n+1=101n + 1 = 101.
  2. Square it: 1012=10201101^2 = 10201.
  3. Multiply by 4: 4080440804.
  4. Divide by π2≈9.8696\pi^2 \approx 9.8696: 40804/9.8696≈413440804 / 9.8696 \approx 4134. The condition number is about 4,130.
  5. Because every diagonal entry is 2, a diagonal preconditioner M=diag(A)=2IM = \mathrm{diag}(A) = 2I scales the matrix by a constant, so κ\kappa does not change.
  6. The usual conjugate gradient bound on the number of steps is proportional to the square root of κ\kappa, here 4134≈64\sqrt{4134} \approx 64 times a logarithmic factor set by the accuracy wanted. A better preconditioner, such as incomplete Cholesky or multigrid, is needed for a large gain.

Interpretation: the condition number grows with the square of the grid size, so refining the grid makes plain solvers much slower.

Try it: Use the same formula with 50 interior points. Find the condition number and its square root. Answer: 4⋅512/π2=10404/9.8696≈10544 \cdot 51^2 / \pi^2 = 10404 / 9.8696 \approx 1054, and 1054≈32.5\sqrt{1054} \approx 32.5.

Common mistakes and tradeoffs

It is tempting to think the best preconditioner is M=AM = A, because it makes M−1A=IM^{-1}A = I. In fact applying M−1M^{-1} means solving a system with AA, which is the original problem. A good preconditioner is cheap to apply and still close enough to AA that κ(M−1A)\kappa(M^{-1}A) is small.

It is tempting to think diagonal (Jacobi) preconditioning always helps. In fact it only helps when the diagonal entries differ in size, as in example 2. When they are all equal, as in example 3, scaling by the diagonal does nothing.

It is tempting to think preconditioning changes the answer. In fact the solution is the same. Only the path to it and the number of steps change, because the work per step rises with the cost of applying M−1M^{-1}.

When to use it: large, sparse, symmetric positive definite systems where an iterative method converges slowly, and where a cheap preconditioner gives a large drop in κ\kappa.

When not to use it: small or dense systems, where a direct factorisation such as Cholesky is cheaper; and systems whose condition number is already close to 1.

Alternatives: direct factorisation such as Cholesky for small problems, multigrid for elliptic equations, and simpler iterative methods for well-conditioned matrices.

History

Magnus Hestenes and Eduard Stiefel described the conjugate gradient method in 1952 as a direct method that also worked as an iteration. For large sparse problems it was mostly ignored for two decades, because rounding errors seemed to destroy its exact-arithmetic guarantee. Interest returned in the 1970s, when people found that with a good preconditioner it converged quickly enough to be practical. In 1977 Jan Meijerink and Henk van der Vorst published an incomplete Cholesky preconditioner that is still a standard choice for sparse symmetric problems.

Recap

  • A preconditioner MM is a cheap approximation to AA, and the solver works on M−1A x=M−1bM^{-1}A\,\mathbf{x} = M^{-1}\mathbf{b}.
  • The error shrinks by a factor set by I−αM−1AI - \alpha M^{-1}A; for well-chosen steps, the number of rounds grows with the condition number.
  • A good preconditioner brings the condition number near 1 while staying cheap to apply, which is why it is combined with conjugate gradient in practice.
  • Read next: Conjugate Gradient for the solver that uses it, and Condition Number for the measure it improves.

Check yourself

QuestionWhat is the condition number of a symmetric positive definite matrix?Show answer

It is the ratio λmax⁡/λmin⁡\lambda_{\max}/\lambda_{\min} of its largest to smallest eigenvalue. Large values mean the problem is badly scaled and iterative methods need many steps.

QuestionWhat is the condition number of A=(5000.5)A = \begin{pmatrix} 5 & 0 \\ 0 & 0.5 \end{pmatrix}?Show answer

The eigenvalues are 5 and 0.5, so κ=5/0.5=10\kappa = 5 / 0.5 = 10.

QuestionWhy is the ideal preconditioner M=AM = A not used in practice?Show answer

Applying M−1M^{-1} means solving with AA, which is the original hard problem. The preconditioner must be cheap to apply, so it is only an approximation to AA.

QuestionA problem has condition number 10610^6 and plain conjugate gradient needs about 1000 steps. A preconditioner lowers the condition number to 100. Using the rule that steps grow with the square root of the condition number, roughly how many steps are needed now?Show answer

The square root drops from 10001000 to 1010, so about 10 steps are needed under that rule. The rule is an upper bound, so the real count may be lower.

Sources