Golden-Section Search

A more elegant technique for root finding

MATH 301 Final Presentation

by Chazz Noble

Like bisection, but better

Finds the minimum or maximum of a function by narrowing in on it

 

Distance of points forms golden ratio

 

Related to Fibonacci Search

(Jack Kiefer discovered both)

 

 

How does it work?

Using the upper and lower bounds and a point called x1, we are able to figure out the distances between the lower bound and x1 (a), the upper bound and x1 (b), and the distance between the upper and lower bounds (a+b). b/a will always equal 0.618, the golden ratio. Knowing this, we are able to solve for the other parts of the equation, and use this information to plug in and narrow the search (much like bisection). 

Questions?

For a ridiculously long (~1hr 15 mins) and in depth explanation, watch the 6 videos posted by CivilEngineeringProf on YouTube.

(I would be more than happy to provide the link if you are interested)

function [z, fz]= Golden_Search(f, a, b, c, tol, kmax)
    
    ya = f(a);  yb = f(b);  yc = f(c);
    
    if (ya < yc) | (yc > yb) 
        error('(a,c,b) does not bracket the min')
    end
    
    disp('   step   a   t1   t2   b   y1   y2   ');
    
    r = 0.5*(3-sqrt(5));
    
    if abs(c-a) < abs(b-c)             //initialize so that a < t1 < t2 < b
        t1 = c;  t2 = c+r*(b-c);       //(c, b) is longer subinterval
    else 
        t2 = c;  t1 = c-r*(c-a);       //(a, c) is longer subinterval
    end
    
    y1 = f(t1);  y2=f(t2);
    
    out = [0, a, t1, t2, b, y1, y2];
    disp(out);
    
    for k = 1:kmax
        if y1 < y2                          //(a, t1, t2) brackets the min
            b = t2;  t2 = t1;               //rename as (a, .., t2, b)
            t1 = t2-r*(t2-a)                //(a, t2) is longer subinterval
            y2 = y1;  y1= f(t1);
        else                                //(t1, t2, b) brackets the min
            a = t1;  t1 = t2;               //rename as (a, t1, .., b)
            t2 = t1+r*(b-t1);               //(t1, b) is longer subinterval
            y1 = y2;  y2 = f(t2);       
        end
    
        out = [k, a, t1, t2, b, y1, y2];
        disp(out);
    
        if abs(b-a) < tol 
            disp(' golden section search has converged'); break;
        end
    end
    
    if y2 < y1 
        z = t2;  fz = y2;
        else z = t1;  fz = y1;
    end

MATLAB

Code Example

from textbook

# python program for golden section search
gr=0.618
def gss(f,a,b,tol=1e-5):
    '''golden section search
to find the minimum of f on [a,b]
f: a strictly unimodal function on [a,b]
 
example:
>>> f=lambda x:(x-2)**2
>>> x=gss(f,1,5)
>>> x
1.9999905526669604
'''
    x=b-gr*(b-a)
    y=a+gr*(b-a)
    while abs(x-y)>tol:       
        fx=f(x);fy=f(y)
        if fx<fy:
            b=y
            y=x  #fy=fx;fx=f(x)
            x=b-gr*(b-a)
        else:
            a=x
            x=y  #fx=fy;fy=f(y)
            y=a+gr*(b-a)
    return (b+a)/2

Python

Code Example

from Wikipedia

G

By Chazz Noble