minUnconGolden

Finds the minimum point of a nonsmooth function of a single variable using the golden section search method.

Synopsis

minUnconGolden (fcn, a, b)

Required Arguments

float fcn (x) (Input)
User-supplied function, f(x), to be minimized.
float a (Input)
The lower endpoint of the interval in which the minimum of f is to be located.
float b (Input)
The upper endpoint of the interval in which the minimum of f is to be located.

Return Value

The approximate minimum point of the function f on the original interval [a, b]. If no value can be computed, NaN is returned.

Optional Arguments

tolerance, float (Input)

The allowable length of the final subinterval containing the minimum point.

Default: tolerance = ε, where ɛ is the machine precision.

lowerEndpoint (Output)
The lower endpoint of the interval in which the minimum of f is located.
upperEndpoint (Output)
The upper endpoint of the interval in which the minimum of f is located.

Description

The function minUnconGolden uses the golden section search technique to compute to the desired accuracy the independent variable value that minimizes a function of one independent variable, where a known finite interval contains the minimum and where the function is unimodal in the same known finite interval.

Let τ =tolerance. The number of iterations required to compute the minimizing value to accuracy τ is the greatest integer less than or equal to

ln(τ/(ba))ln(1c)+1

where a and b define the interval and

c=(35)/2

The first two test points are v1 and v2 that are defined as

v1=a+c(ba), and v2=bc(ba)

If f(v1)<f(v2), then the minimizing value is in the interval (a,v2). In this case, bv2, v2v1, and v1a+c(ba). If f(v1)f(v2), the minimizing value is in (v1,b). In this case, av1, v1v2, and v2bc(ba).

The algorithm continues in an analogous manner where only one new test point is computed at each step. This process continues until the desired accuracy τ is achieved. The point, xmin, producing the minimum value for the current iteration is returned.

Mathematically, the algorithm always produces the minimizing value to the desired accuracy, however, numerical problems may be encountered. If f is too flat in part of the region of interest, the function may appear to be constant to the computer in that region. The user may rectify the problem by relaxing the requirement on τ, modifying (scaling, etc.) the form of f or executing the program in a higher precision.

Remarks

  1. On exit from minUnconGolden without any error messages, the following conditions hold:

    (upperEndpoint-lowerEndpoint)tolerance
    lowerEndpointxmin and xminupperEndpoint
    f(xmin)f(lowerEndpoint) and f(xmin)f(upperEndpoint)
  2. On exit from minUnconGolden with IMSL_NOT_UNIMODAL error, the following conditions hold:

    lowerEndpointxmin and xminupperEndpoint
    f(xmin)f(lowerEndpoint) and f(xmin)f(upperEndpoint) (only one equality can hold)

    Further analysis of the function f is necessary in order to determine whether it is not unimodal in the mathematical sense or whether it appears to be not unimodal to the routine due to rounding errors, in which case the lowerEndpoint, upperEndpoint, and xmin returned may be acceptable.

Example

A minimum point of 3x22x+4 is found.

from __future__ import print_function
from numpy import *
from pyimsl.math.minUnconGolden import minUnconGolden


def fcn(x):
    return 3.0 * (x**2) - 2 * x + 4


lower = []
upper = []
a = 0.0
b = 5.0
tol = 1.0e-3
xmin = minUnconGolden(fcn, a, b,
                      tolerance=tol,
                      lowerEndpoint=lower,
                      upperEndpoint=upper)
fx = fcn(xmin)
print("The minimum is at: %7.3f" % (xmin))
print("The function evaluated at the solution is: %8.3f" % (fx))
print("The final interval is: (%8.3f, %8.3f)" % (lower[0], upper[0]))

Output

The minimum is at:   0.333
The function evaluated at the solution is:    3.667
The final interval is: (   0.333,    0.334)

Warning Errors

IMSL_TOL_TOO_SMALL tolerance is too small to be satisfied..

Fatal Errors

IMSL_NOT_UNIMODAL Due to rounding errors, the function does not appear to be unimodal.
IMSL_STOP_USER_FCN

Request from user supplied function to stop algorithm.

User flag = “#”.