Home > Algorithms, Analysis, Calculus of Variations, Numerical Analysis, Optimization, Programming > Optimizing a 1D function – trisection algorithm

Optimizing a 1D function – trisection algorithm


Optimization problems take the classical form

\displaystyle \min_{x \in K} f(x).

Not all such problems have explicit solution, therefore numerical algorithms may help approximate potential solutions.

Numerical algorithms generally produce a sequence which approximates the minimizer. Information regarding function values and its derivatives are used to generate such an approximation.

The easiest context is one dimensional optimization. The basic intuition regarding optimization algorithms starts by understanding the 1D case. Not all problems are easy to handle for a numerical optimization algorithm. Take a look at the picture below:

photo from Ziv Bar-Joseph

For simplicity, let us assume that {f : [a,b] \rightarrow \Bbb{R}} is a unimodal function: there exists {x^*\in [a,b]} such that {f} is decreasing on {[a,x^*]} and increasing on {[x^*,b]}.

Furthermore, suppose that we can only compute values {f(x)} (not derivatives). This is true for various practical applications:

  • the function value might come from an experiment.
  • the value might be related to a solution of a mathematical model which is hard to differentiate
  • the function may simply come from a black box device. We have a way to obtain values, but not derivatives.

For such a function (assuming it is unimodal, it has a unique local minimum) it is possible to devise a bracketing algorithm for finding the minimizer {x^*}. Take a moment to think how many function evaluations for points in {[a,b]} are needed to find a tighter enclosure for {x^*}?

A quick inspection shows that one function evaluation does not give enough information. Suppose that

\displaystyle x^-, x_+ \in [a,b], x^-<x^+.

Then:

  • if {f(x^-)\leq f(x^+)} the minimizer cannot lie in {[x^+,b]}. Therefore {[a,x^+]} is a guaranteed inclusion for {x^*}.
  • if {f(x^-)\geq f(x^+)} the minimizer cannot lie in {[a,x^-]}. Therefore {[x^-,b]} is a guaranteed inclusion for {x^*}.

This gives rise to a straightforward iterative algorithm. All we need is a systematic way of choosing {x^-, x^+} in {[a,b]} and iterate such that the length of the bracketing interval converges to {0}.

The simplest idea is to use the trisection algorithm where {x^-,x^+} divide {[a,b]} into three equal parts. At every iteration the length of the bracketing interval is multipled by {2/3}, therefore a satisfying error will be attained after a reasonable number of iterations. A simple Python implementation is given below:

def Trisection(fun,A,B,tol=1e-6,ubFeval=10):
    nfeval = 0
    lbhist = []
    ubhist = []
    x1hist = []
    x2hist = []
    lb = A
    ub = B
    lbhist.append(lb)
    ubhist.append(ub)
    while ub-lb>tol:
        x1 = 2/3*lb+1/3*ub
        x2 = 1/3*lb+2/3*ub
        v1 = fun(x1)
        nfeval = nfeval+1
        if nfeval>=ubFeval:
            break
        v2 = fun(x2)
        nfeval = nfeval+1
        if v1<=v2:
            ub=x2
        else:
            lb=x1
        x1hist.append(x1)
        x2hist.append(x2)
        lbhist.append(lb)
        ubhist.append(ub)
        if nfeval>=ubFeval:
            break
    return np.array(lbhist),np.array(ubhist),np.array(x1hist),np.array(x2hist),nfeval

Since the error estimate {e_n}, equal to the distance from {x^*} to the midpoint of {[a_n,b_n]}, for example, verifies an inequality of the form

\displaystyle e_{n+1}\leq \frac{2}{3} e_n

we say that this algorithm converges linearly.

One drawback of trisection algorithm is that two function evaluations are made at every iteration. This can be improved with a slight modification which we’ll cover soon.

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment