Optimization.MinBrent Method

Overload List

#SignatureDescription
1function MinBrent(ax: Double; bx: Double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; const Consts: TDoubleArray; const ObjConst: TObjectArray; out MinX: Double): Integer;Minimizes single variable function by using default settings and no log.
2function MinBrent(ax: Double; bx: Double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; const Consts: TDoubleArray; const ObjConst: TObjectArray; out MinX: Double; MaxIter: Integer; Accuracy: Double; const Verbose: TStrings): Integer;Minimizes single variable function.

Overload 1: function MinBrent(ax: Double; bx: Double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; const Consts: TDoubleArray; const ObjConst: TObjectArray; out MinX: Double): Integer;

Minimizes single variable function by using default settings and no log.

#NameTypeDescription
1axDoublescalar
2bxDoublescalar
3FuncTRealFunction
4FloatPrecisionTMtxFloatPrecision
5ConstsTDoubleArray
6ObjConstTObjectArray
7MinXDouble

Returns: Int32

Remarks:

Use this version if algorithm step logs are not needed.

Overload 2: function MinBrent(ax: Double; bx: Double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; const Consts: TDoubleArray; const ObjConst: TObjectArray; out MinX: Double; MaxIter: Integer; Accuracy: Double; const Verbose: TStrings): Integer;

Minimizes single variable function.

#NameDescription
1axDefines initial lower limit for minimum search.
2bxDefines initial upper limit for minimum search.
3FuncReal function of single variable (must be of TRealFunction type) to be minimized.
4ConstsAdditional Fun constant parameters (can be/is usually nil).
5ObjConstAdditional Fun constant parameters (can be/is usually nil).
6MinXReturns the position of function minimum.
7MaxIterMaximum allowed numer of minimum search iterations.
8AccuracyDesired minimum position tolerance.
9VerboseIf assigned, stores Func, evaluated at each iteration step. Optionally, you can also pass TOptControl object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring.
10FloatPrecisionSpecifies the floating point precision to be used by the routine.

Returns: Int32 - the number of iterations required to reach the solution(minimum) within given tolerance.

Remarks:

What it computes. Locates a local minimizer x^* of a
real function of one variable on the bracket [a_x,b_x] using Brent's method (golden-section search refined by parabolic interpolation; the modified algol-60 localmin). For the example objective

y(x) = sin(x) + (x+2)^2

Domain. a_x,b_x are finite reals; if b_x < a_x they
are swapped internally, so the order of the bracket does not matter. MaxIter > 0 caps the iterations; Accuracy ≥ 0 is the desired position tolerance.

Defined behaviour. Returns the iteration count and writes the
minimizer to MinX; it converges to a stationary point inside the bracket. MinBrent has no stop-reason output: if Func returns NaN the NaN propagates into MinX (and is reported in Verbose when assigned). The bracket is assumed to contain a minimum; for a monotone objective the result is the corresponding endpoint.

Minimizes the function of one variable. This routine uses slightly modified version of the algol 60 procedure localmin, introduced by Richard Brent.

Examples
Uses MtxVec, Math387, Optimization;
function Fun(const Pars: TVec: const Consts: TVec; const ObjConsts: Array of TObject): double;
begin
    Fun := Sin(Pars[0])+Sqr(Pars[0]+2);
    // note that Pars holds only one variable !
end;
procedure Example;
var Res,x : double;
begin
    // initial estimates for x1 and x2
    Res := MinBrent(-10,10,Fun,mvDouble,[],[],x,500,1e-8);
    // stop if Iters >500 or Tolerance < 1e-8
    // Returns Res = -1.8582461797
end;
See Also: TRealFunction