Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Convergence of Algorithms

Open in Colab

Many numerical algorithms are iterative: instead of computing the answer directly, they produce a sequence of approximations x0,x1,x2,…x_0, x_1, x_2, \dots that get closer and closer to the true solution. Examples include Newton’s method for finding roots, gradient descent for optimization, and iterative solvers for linear systems.

We’ll let x∗x_\ast denote the true solution, and xkx_k denote the kkth iterate of an algorithm. The error at iteration kk is

ϵk=∣xk−x∗∣\epsilon_k = |x_k - x_\ast|

(if the xkx_k are vectors, we use a norm instead: ϵk=∥xk−x∗∥\epsilon_k = \|x_k - x_\ast\|). An algorithm converges if

lim⁡k→∞ϵk=0\lim_{k\to\infty} \epsilon_k = 0

Knowing that an algorithm converges is not enough to make it useful. An algorithm that needs 5 iterations to get 15 correct digits is very different from one that needs 1030 iterations. In this section, we’ll make “how fast” precise, look at concrete algorithms that converge at different speeds, and see how to measure the speed from experimental data.

Monitoring Convergence in Practice

In practice, we typically don’t know the value of x∗x_\ast (otherwise we wouldn’t need the algorithm). There are two common substitutes for the error:

  1. Run the algorithm for NN iterations and treat the last iterate as the true solution, i.e. estimate ϵ~k=∣xk−xN∣\tilde{\epsilon}_k = |x_k - x_N|. This is reasonable for kk much smaller than NN.

  2. Monitor the difference between consecutive iterates, δk=∣xk−xk−1∣\delta_k = |x_k - x_{k-1}|. If the algorithm is converging, then δk→0\delta_k \to 0 as well. A typical stopping criterion is to stop as soon as δk<tol\delta_k < \mathrm{tol} (absolute tolerance) or δk<tol⋅∣xk∣\delta_k < \mathrm{tol}\cdot|x_k| (relative tolerance).

In this class, we aren’t going to worry too much about proving that algorithms converge. However, we do want to be able to verify that an algorithm is converging, measure the rate of convergence, and compare two algorithms using experimental convergence data.

Rate of Convergence

There are a variety of ways to define the rate of convergence. The most common one compares the error at iteration k+1k+1 to the error at iteration kk. We say that ϵk→0\epsilon_k \to 0 with order q≥1q \ge 1 and rate μ\mu if

lim⁡k→∞ϵk+1ϵkq=μ,0<μ<∞\lim_{k\to \infty} \frac{\epsilon_{k+1}}{\epsilon_k^q} = \mu, \qquad 0 < \mu < \infty

In words: once kk is large enough, each iteration does roughly ϵk+1≈μ ϵkq\epsilon_{k+1} \approx \mu\, \epsilon_k^q. The constant μ\mu is also called the asymptotic error constant.

The most important cases have names:

NameDefinitionWhat happens to the error
linearq=1q = 1 and 0<μ<10 < \mu < 1multiplied by μ\mu each iteration, so ϵk≈μkϵ0\epsilon_k \approx \mu^k \epsilon_0
superlinearϵk+1/ϵk→0\epsilon_{k+1}/\epsilon_k \to 0faster than linear with any rate μ\mu; this includes every order q>1q > 1
quadraticq=2q = 2ϵk+1≈μ ϵk2\epsilon_{k+1} \approx \mu\, \epsilon_k^2
cubicq=3q = 3ϵk+1≈μ ϵk3\epsilon_{k+1} \approx \mu\, \epsilon_k^3
sublinearq=1q = 1 and μ=1\mu = 1slower than linear, e.g. ϵk=1/k\epsilon_k = 1/k

Larger values of qq indicate faster convergence. For the same qq, a smaller μ\mu is faster.

A few remarks:

  • If q=1q = 1 and μ>1\mu > 1, the error grows. An order q<1q < 1 is also impossible for a sequence that converges to 0.

  • For q>1q > 1, any μ>0\mu > 0 is allowed, even μ>1\mu > 1, because ϵk+1/ϵk≈μ ϵkq−1→0\epsilon_{k+1}/\epsilon_k \approx \mu\, \epsilon_k^{q-1} \to 0.

  • The order and rate are asymptotic properties. They say nothing about the first few iterations, and it can take many iterations before an algorithm settles into its asymptotic behavior.

  • For some algorithms, the ratio ϵk+1/ϵk\epsilon_{k+1}/\epsilon_k has no limit, so they don’t fit the definition exactly. If the error is bounded by a sequence that converges linearly, e.g. ϵk≤C 2−k\epsilon_k \le C\, 2^{-k}, we still say the algorithm converges linearly. Bisection is an example (see below).

Counting Correct Digits

The easiest way to understand the order qq is to count digits. The quantity dk=−log⁡10ϵkd_k = -\log_{10} \epsilon_k is roughly the number of correct decimal digits in xkx_k: for example, ϵk=10−6\epsilon_k = 10^{-6} means about 6 correct digits. Taking −log⁡10-\log_{10} of ϵk+1≈μ ϵkq\epsilon_{k+1} \approx \mu\, \epsilon_k^q gives

dk+1≈q dk+log⁡10(1/μ)d_{k+1} \approx q\, d_k + \log_{10}(1/\mu)
  • Linear (q=1q = 1): dk+1≈dk+log⁡10(1/μ)d_{k+1} \approx d_k + \log_{10}(1/\mu). Each iteration adds a fixed number of correct digits. With μ=1/2\mu = 1/2 we gain log⁡102≈0.3\log_{10} 2 \approx 0.3 digits per iteration, so 16 digits (double precision) take about 16/0.3≈5316/0.3 \approx 53 iterations. With μ=0.1\mu = 0.1 we gain exactly one digit per iteration.

  • Quadratic (q=2q = 2): dk+1≈2dkd_{k+1} \approx 2 d_k. The number of correct digits roughly doubles each iteration: 1,2,4,8,161, 2, 4, 8, 16. Starting from one correct digit, we reach double precision in about 4 iterations.

  • Order qq: the number of correct digits is multiplied by about qq each iteration.

  • Sublinear: the number of digits gained per iteration goes to 0. For ϵk=1/k\epsilon_k = 1/k, getting 16 digits takes 1016 iterations.

Model Sequences

Let’s generate some model error sequences by running the recursion ϵk+1=μ ϵkq\epsilon_{k+1} = \mu\, \epsilon_k^q directly.

  • A semilogy plot (log scale on the yy-axis only) shows log⁡ϵk\log \epsilon_k against kk. Linear convergence ϵk≈μkϵ0\epsilon_k \approx \mu^k \epsilon_0 gives log⁡ϵk≈klog⁡μ+log⁡ϵ0\log \epsilon_k \approx k \log\mu + \log \epsilon_0, which is a straight line with slope log⁡μ\log\mu. Superlinear convergence bends downward (it gets steeper and steeper), and sublinear convergence flattens out.

  • If a sublinear sequence behaves like ϵk≈Ck−p\epsilon_k \approx C k^{-p} for some power p>0p > 0. Then log⁡ϵk≈log⁡C−plog⁡k\log \epsilon_k \approx \log C - p \log k, which is a straight line with slope −p-p on a loglog plot. Here ϵk=1/k\epsilon_k = 1/k, so p=1p = 1.

Estimating the Order of Convergence

Now suppose we have a sequence of errors ϵk\epsilon_k from an experiment, but we don’t know the theory. How can we measure qq?

Local Estimates

If ϵk+1≈μ ϵkq\epsilon_{k+1} \approx \mu\, \epsilon_k^q, then taking logarithms gives

log⁡ϵk+1≈qlog⁡ϵk+log⁡μ\log \epsilon_{k+1} \approx q \log \epsilon_k + \log \mu

Subtracting the same relation one step earlier (log⁡ϵk≈qlog⁡ϵk−1+log⁡μ\log \epsilon_k \approx q \log\epsilon_{k-1} + \log\mu) eliminates the unknown μ\mu:

log⁡ϵk+1−log⁡ϵk≈q (log⁡ϵk−log⁡ϵk−1)⟹q≈qk=log⁡(ϵk+1/ϵk)log⁡(ϵk/ϵk−1)\log\epsilon_{k+1} - \log\epsilon_k \approx q\,(\log\epsilon_k - \log\epsilon_{k-1}) \qquad\Longrightarrow\qquad q \approx q_k = \frac{\log(\epsilon_{k+1}/\epsilon_k)}{\log(\epsilon_k/\epsilon_{k-1})}

Each qkq_k uses three consecutive errors, so we get one estimate per iteration, and we can watch the estimates settle down as kk grows.

Fitting a Line

Let rk=log⁡ϵk+1−log⁡ϵkr_k = \log\epsilon_{k+1} - \log\epsilon_k. The relation above says rk≈q rk−1r_k \approx q\, r_{k-1}, so ∣rk∣≈∣r0∣ qk|r_k| \approx |r_0|\, q^k grows (or shrinks) geometrically, and

log⁡∣rk∣≈log⁡∣r0∣+klog⁡q\log|r_k| \approx \log|r_0| + k \log q

So if we plot log⁡∣rk∣\log|r_k| against kk, we should see a straight line with slope log⁡q\log q. The function below fits a line to these points using np.polyfit, and returns q=eslopeq = e^{\text{slope}}.

For the model sequences, log⁡ϵk+1=qlog⁡ϵk+log⁡μ\log \epsilon_{k+1} = q\log\epsilon_k + \log\mu holds exactly, so we recover q=1q = 1 and q=2q = 2 exactly. For ϵk=1/k\epsilon_k = 1/k, the estimate is a bit below 1; we’ll come back to this in the exercises.

Practical Tips

  1. Discard the pre-asymptotic phase. The order describes the behavior as k→∞k \to \infty. The first few iterates may behave differently (e.g. the error of the secant method increased in the first step).

  2. Discard iterates at machine precision. In double precision, the error can’t get much below 10−16∣x∗∣10^{-16}|x_\ast|. Once it gets there, round-off error dominates and the ratios are meaningless.

  3. Look at the plot first. A semilogy plot of ϵk\epsilon_k (or δk\delta_k) against kk tells you a lot at a glance: a straight line means linear, bending down means superlinear, and flattening out means sublinear (in which case try a loglog plot).

  4. q≈1q \approx 1 is ambiguous. Check the rate μ\mu to tell linear (μ<1\mu < 1) from sublinear (μ→1\mu \to 1) convergence.

Exercises

  1. Generate a converging sequence with q=1.5q = 1.5, and estimate qq using the above methods.

  2. Generate sublinear sequences with ϵk=1/k\epsilon_k = 1/k (as above) for lengths 50, 100, 500, 1000, 5000, and 10000. How does our estimate of qq change with the length of the sequence?

Solutions

Exercise 1.

Exercise 2.

The estimate approaches 1 as the sequence gets longer, but slowly. For ϵk=1/k\epsilon_k = 1/k, we have rk=log⁡kk+1≈−1/kr_k = \log\frac{k}{k+1} \approx -1/k, so log⁡∣rk∣≈−log⁡k\log|r_k| \approx -\log k. This is not a straight line in kk, so fitting a line gives a slope slightly below 0 (i.e. qq slightly below 1). The slope of −log⁡k-\log k flattens out as kk grows, so the fitted slope gets closer to 0 for longer sequences. This is another reason to use a loglog plot for sublinear sequences.