{Optimization utilities
author: Nikolai V. Shokhirev http://www.shokhirev.com/nikolai.html
created: 2003.06.06
last modified: 2004.12.23
ŠNikolai V. Shokhirev, 2001-2003 }
unit uOptimUtils;
interface
uses
uMatTypes;
{
PURPOSE:
Bracketing the minimum of a function within given limits
INPUT:
f(x) - function
xmin, xmax - search limits
x0 - start ( xmin < x0 < xmax )
tol - accuracy
step - initial step
OUTPUT
step - final step
x1, x2 - brackets
ErrCode = -5 - small interval: |xmax - xmin| < |tol|
ErrCode = 5 - xmin > xmax
ErrCode = -4 - x0 < xmin
ErrCode = 4 - x0 > xmax
ErrCode = -3 - flat function: |f(x)-f(x+step)| < dfmin
ErrCode = 3 -
ErrCode = -2 - x0 = xmin and f(x0) < f(x0+|step|)
ErrCode = 2 - x0 = xmax and f(x0) < f(x0-|step|)
ErrCode = -1 - minimum at x = xmin
ErrCode = 1 - minimum at x = xmax
ErrCode = 0 - OK }
procedure Bracketing(f: FloatFunc1D; x0, tol: TFloat;
var step, x1, x2: TFloat; var ErrCode: TInt; xmin, xmax: TFloat);
{
PURPOSE:
Bracketing the minimum of a function in the positive semi-axis
INPUT:
f(x) - function
xmax - search limit ( < MaxFloat )
tol - accuracy
step - initial step
OUTPUT
step - final step
x1, x2 - brackets
ErrCode = -5 - small interval: |xmax - xmin| < |tol|
ErrCode = -3 - flat function: |f(x)-f(x+step)| < dfmin
ErrCode = -2 - x0 = xmin and f(x0) < f(x0+|step|)
ErrCode = 1 - minimum at x = xmax
ErrCode = 0 - OK }
procedure Bracketing0(f: FloatFunc1D; tol: TFloat; var step, x1, x2: TFloat;
var ErrCode: TInt; xmax: TFloat);
{Pascal translation of the minimization FORTRAN routine from
"Computer Methods for Mathematical Computations", by George E. Forsythe,
Michael A. Malcolm, and Cleve B. Moler. Prentice-Hall, 1977.
An approximation x to the point where f attains a minimum on
the interval (ax,bx) is determined.
INPUT:
ax left endpoint of initial interval
bx right endpoint of initial interval
f function subprogram which evaluates f(x) for any x in the interval (ax,bx)
tol desired length of the interval of uncertainty of the final result (.ge. 0.0)
OUTPUT:
fmin abcissa approximating the point where f attains a minimum
The method used is a combination of golden section search and successive
parabolic interpolation. Convergence is never much slower than that for
a fibonacci search. If f has a continuous second derivative which is positive
at the minimum (which is not at ax or bx), then convergence is superlinear,
and usually of the order of about 1.324....
The function f is never evaluated at two points closer together than
eps*abs(fmin) + (tol/3), where eps is approximately the square root of
the relative machine precision. if f is a unimodal function and the computed
values of f are always unimodal when separated by at least
eps*abs(x) + (tol/3), then fmin approximates the abscissa of the global minimum
of f on the interval ax,bx with an error less than 3*eps*abs(fmin) + tol.
If f is not unimodal, then fmin may approximate a local, but perhaps
non-global, minimum to the same accuracy.
This function subprogram is a slightly modified version of the algol 60
procedure localmin given in Richard Brent, algorithms for minimization without
derivatives, prentice - hall, inc. (1973). }
function fmin(ax, bx: TFloat; f: FloatFunc1D; tol: TFloat): TFloat;
implementation
uses
math;
end.
Generated by Lore's Source to HTML Converter(http://www.newty.de/lsc/index.html)