Optimization.MinBrent Method

Overload List

#SignatureDescription
1Int32 MinBrent(Double ax, Double bx, TRealFunction Func, TMtxFloatPrecision FloatPrecision, Double[] Consts, Object[] ObjConst, ref Double MinX)Minimizes single variable function by using default settings and no log.
2Int32 MinBrent(Double ax, Double bx, TRealFunction Func, TMtxFloatPrecision FloatPrecision, Double[] Consts, Object[] ObjConst, ref Double MinX, Int32 MaxIter, Double Accuracy, TStrings Verbose)Minimizes single variable function.

Overload 1: Int32 MinBrent(Double ax, Double bx, TRealFunction Func, TMtxFloatPrecision FloatPrecision, Double[] Consts, Object[] ObjConst, ref Double MinX)

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

#NameTypeDescription
1axDoublescalar
2bxDoublescalar
3FuncTRealFunction
4FloatPrecisionTMtxFloatPrecision
5ConstsDouble[]
6ObjConstObject[]
7MinXDouble (ref)output

Returns: Int32

Remarks:

Use this version if algorithm step logs are not needed.

Overload 2: Int32 MinBrent(Double ax, Double bx, TRealFunction Func, TMtxFloatPrecision FloatPrecision, Double[] Consts, Object[] ObjConst, ref Double MinX, Int32 MaxIter, Double Accuracy, TStrings Verbose)

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 Dew.Math.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 Dew.Math.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
private double Fun(TVec pars, TVec c, params object[] o)
{
    return Math.Sin(Pars[0])+Math387.IntPower(Pars[0]+2,2);
        // note that Pars holds only one variable !
}
private void Example()
{
    // initial estimates for x1 and x2
    double x;
    double res = Optimization.MinBrent(-10,10,Fun,TMtxFloatPrecsion.mvDouble,null,null,out x, 500,1e-8,null);
    // stop if Iters >500 or Tolerance < 1e-8
        // Returns res = -1.8582461797
}
See Also: TRealFunction