Quadratic Interpolative Search

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

Quadratic interpolative search finds the minimum of a unimodal function \(f\) on an interval \([a, b]\) by fitting a parabola through three function values and moving to the parabola’s lowest point. The version on this page is the one in Mathews’ module and Mathematica subroutine, which uses three equally spaced points \(p_0\), \(p_1 = p_0 + h\), \(p_2 = p_0 + 2h\). It starts from \(p_0 = a\) with \(h = (b - a)/2\) and steps to the right when \(f'(p_0) < 0\), to the left when \(f'(p_0) > 0\). It then halves \(h\) while \(f(p_0) \le f(p_1)\) and doubles it while \(f(p_2) < f(p_1)\), until the middle value is the lowest, \(f(p_0) > f(p_1) \le f(p_2)\). With \(y_i = f(p_i)\), the vertex of the interpolating quadratic is

\[ p_{\min} = p_0 + h_{\min}, \qquad h_{\min} = \frac{h\,(4y_1 - 3y_0 - y_2)}{2\,(2y_1 - y_0 - y_2)}. \]

The search restarts from \(p_0 = p_{\min}\), with \(h\) equal to the distance from \(p_{\min}\) to the nearest of the three old points. It stops when one of \(y_0, y_1, y_2\) agrees with \(f(p_{\min})\) to within a tolerance \(\varepsilon\).

The module also covers cubic interpolative search, which uses derivative values explicitly. It fits a cubic \(P\) to the values of \(f\) and \(f'\) at two points \(p_0\) and \(p_1 = p_0 + h\), and moves to the local minimum of the cubic, \(p_2 = p_0 + \gamma h\), where

\[ \gamma = \frac{-2h f'(p_0)}{(G - 3\alpha) + \sqrt{(G - 3\alpha)^2 - 12 h \alpha f'(p_0)}}, \qquad F = f(p_1) - f(p_0), \quad G = h\bigl(f'(p_1) - f'(p_0)\bigr), \quad \alpha = G - 2\bigl(F - h f'(p_0)\bigr). \]

Then \((p_0, p_1)\) is replaced by \((p_1, p_2)\) and the step repeats. The cubic search does not keep a bracket: in both of Mathews’ examples its first point \(p_1\) lies outside \([a, b]\). The examples below keep Mathews’ numbers. Examples 1 and 3 use the quadratic search and Examples 2 and 4 the cubic search. Examples 1 and 2 minimise the same function, and so do Examples 3 and 4.

Unimodal Functions and the Derivative Test

NoteDefinition — Unimodal function

The function \(f\) is unimodal on \(I = [a, b]\) if there is a unique number \(p \in I\) such that \(f\) is decreasing on \([a, p]\) and increasing on \([p, b]\).

Bracketing searches such as the golden ratio and Fibonacci searches need only this condition. The two methods on this page also use the derivative. Suppose \(f\) is unimodal on \([a, b]\) with minimum at \(p\), \(f'\) exists on \((a, b)\), and \(p_0 \in (a, b)\). If \(f'(p_0) < 0\) the minimum lies to the right of \(p_0\), and if \(f'(p_0) > 0\) it lies to the left.

Both of Mathews’ functions are unimodal on \([0, 1]\):

  • \(f(x) = x^2 - \sin x\) has \(f''(x) = 2 + \sin x \ge 2 > 0\) on \([0, 1]\), \(f'(0) = -1 < 0\) and \(f'(1) = 2 - \cos 1 = 1.4597 > 0\). The minimiser is the root of \(2x = \cos x\), \(p = 0.4501836113\), with \(f(p) = -0.2324655752\).
  • \(f(x) = \tfrac12 + x^5 - \tfrac45 x\) has \(f''(x) = 20x^3 > 0\) on \((0, 1]\), \(f'(0) = -0.8\) and \(f'(1) = 4.2\). The minimiser is exact: \(5p^4 = \tfrac45\) gives \(p = (4/25)^{1/4} = \sqrt{10}/5 = 0.6324555320\), with \(f(p) = 0.0952284595\).

Comparing the Two Searches

Examples 1 and 2 minimise the same function, so the methods can be compared directly.

Method (on \(x^2 - \sin x\)) Information used Steps Error of the result
Quadratic search (Example 1) 20 calls of \(f\), sign of \(f'\) at 3 points 3 vertex steps \(2.0 \times 10^{-11}\)
Cubic search (Example 2) \(f\) and \(f'\) at the iterates \(p_3\) after 2 cubic steps, \(p_4\) after 3 \(3.5 \times 10^{-7}\), then \(1.1 \times 10^{-15}\)
Secant method on \(f'\) \(f'\) only \(p_6\) after 5 secant steps \(1.1 \times 10^{-13}\)

To see the rate of convergence without the limit of double precision, the three iterations were repeated in 400-digit arithmetic. The ratio \(\log e_{k+1} / \log e_k\) of successive errors measures the order:

  • Cubic search: the ratios settle near \(2\). The last ratios before the 400-digit limit are \(2.10\), \(1.98\), \(2.02\) in Example 2 and \(2.09\), \(1.95\), \(2.02\) in Example 4. This is consistent with the order \(2\) of cubic interpolation using function and derivative values (a general result).
  • Secant method on \(f'\): the ratios fall to \(1.62\), the golden ratio \((1 + \sqrt5)/2 \approx 1.618\) that is the general order of the secant method.
  • Mathews’ quadratic search: each outer step roughly squares the error. The ratios are \(2.61\), \(2.22\), \(2.11\), \(2.05\), \(2.02\), \(2.01\) in Example 1 and \(2.08\), \(2.06\), \(2.00\), \(2.02\), \(2.00\), \(2.00\), \(2.00\), \(2.00\) in Example 3. But the bracketing loops of the successive outer steps need more and more halvings or doublings: \(2, 6, 19, 34, 76, 156\) in Example 1 and \(2, 0, 5, 8, 13, 39, 82, 164\) in Example 3. In the last three steps of each run that is \(1.4\) to \(1.7\) passes, each costing one evaluation of \(f\), per decimal digit gained. Counted per function evaluation, the quadratic search therefore converges far more slowly than the squaring per step suggests.

This variant is not the textbook successive parabolic interpolation, which keeps the three most recent points, unequally spaced, and needs no bracketing loop.

Implementation Notes

  • Quadratic search, direction. The subroutine evaluates \(f'(p_0)\) once per outer step and uses only its sign. A version without derivatives must choose the direction from function values instead.
  • Quadratic search, step rule. Rule (7) gives the distance from \(p_{\min}\) to the nearest old point only when \(h > 0\), because the subroutine replaces \(h\) by \(|h|\) first. Every outer step in Examples 1 and 3 has \(f'(p_0) < 0\) and therefore \(h > 0\).
  • Quadratic search, bracketing. Check that the triple really is bracketed before using (5). The loop can also end because \(|h| \le \delta\), and the vertex of an unbracketed or collinear triple is meaningless or undefined.
  • Quadratic search, stopping. \(\mathrm{Err}\) compares function values, which agree to about the square of the distance to \(p\) (Example 3: \(8.1 \times 10^{-13}\) in \(f\) against \(5.7 \times 10^{-7}\) in \(x\)). A tolerance \(\varepsilon\) on \(f\) therefore corresponds to a distance of roughly \(\sqrt{2\varepsilon / f''(p)}\) (general).
  • Cubic search, starting step. Formula (8) needs \(f'(a) \ne 0\), and with \(f(b) > f(a)\) it sends \(p_1\) outside \([a, b]\) (both examples). The method does not keep a bracket, and \(p_1\) can land where \(f\) is not convex, as in Example 4.
  • Cubic search, stopping. Use a test such as \(|f'(p_k)| < \varepsilon\) rather than a fixed number of steps. Once the iterates agree to rounding, \(F\), \(G\) and \(\alpha\) are pure rounding noise. Continued in double precision, both examples eventually reach \(0/0\) in (14): Example 2 at \(p_9\), after \(p_7 = p_8\) exactly, and Example 4 also at \(p_9\), where \(f'(p_7) = 0\) exactly. Mathews’ runs stop before this.
  • Unimodality. Neither method can tell a local minimum from the global one. If \(f\) has several minima in \([a, b]\), the result depends on the start.

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.