Optimization.Simplex Method

Overload List

#SignatureDescription
1Int32 Simplex(TRealFunction Func, ref Double Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance)Minimizes function of several variables by using Simplex optimization method with no algorithm step log.
2Int32 Simplex(TRealFunction Func, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance, TStrings Verbose)Minimizes the function of several variables by using the Nelder-Mead (Simplex) optimization method.
3Int32 Simplex(TRealFunction Func, ref Double[] Pars, Double[] Consts, Object[] ObjConst, Double[] LB, Double[] UB, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance, TStrings Verbose)Minimize function of several variables by using Simplex method with lower and/or upper bounds for parameters.

Overload 1: Int32 Simplex(TRealFunction Func, ref Double Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance)

Minimizes function of several variables by using Simplex optimization method with no algorithm step log.

#NameTypeDescription
1FuncTRealFunction
2ParsDouble (ref)output
3ConstsDouble[]
4ObjConstObject[]
5FMinDouble (ref)output
6StopReasonTOptStopReason (ref)
7FloatPrecisionTMtxFloatPrecision
8MaxIterInt32
9ToleranceDoublescalar

Returns: Int32

Overload 2: Int32 Simplex(TRealFunction Func, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance, TStrings Verbose)

Minimizes the function of several variables by using the Nelder-Mead (Simplex) optimization method.

#NameDescription
1FuncReal function (must be of Dew.Math.TRealFunction type) to be minimized.
2ParsStores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position).
3ConstsAdditional Fun constant parameteres (can be/is usually nil).
4ObjConstAdditional Fun constant parameteres (can be/is usually nil).
5FMinReturns function value at minimum.
6StopReasonReturns reason why minimum search stopped (see Dew.Math.TOptStopReason).
7MaxIterMaximum allowed numer of minimum search iterations.
8ToleranceDesired Pars - minimum position tolerance.
9FloatPrecisionSpecifies the floating point precision to be used by the routine.
10VerboseIf assigned, stores Fun, 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.

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

Remarks:

What it computes. Minimizes a real function of several
variables with the gradient-free Nelder-Mead (downhill simplex) method - reflection, expansion, contraction and shrink steps on a simplex of n+1 vertices. No gradient or Hessian is required. The standard test ('Banana'/Rosenbrock) objective is

f(x_0,x_1) = 100 (x_1 - x_0^2)^2 + (1 - x_0)^2

with the global minimum f=0 at (x_0,x_1)=(1,1).

Domain. Pars holds the n starting coordinates (any
finite reals); MaxIter > 0; Tolerance ≥ 0 is the simplex-size convergence threshold.

Defined behaviour. On return Pars holds the best vertex,
FMin its objective value, and StopReason is Dew.Math.TOptStopReason.OptResConverged when the simplex shrank below Tolerance, Dew.Math.TOptStopReason.OptResMaxIter when the iteration cap was hit, or Dew.Math.TOptStopReason.optNANValue if the objective returned NaN. The bounded overload (with LB/UB) maps each parameter through a smooth transform so the returned point always satisfies LB_i <= Pars_i <= UB_i; use +/-inf for a one-sided or absent bound.

Minimizes the function of several variables by using the Nelder-Mead (Simplex) optimization method. The advantage of Simplex method is it does not require gradient or Hessian.

Examples
private double Banana(TVec x, TVec c, params object[] o)
{
    return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1 - x[0],2);
}
private void Example()
{
    double[2] x;
    double fmin;
    TOptStopReason StopReason;
    // initial estimates for x1 and x2
    x[0] = 0;
    x[1] = 0;
    int iters = Simplex(Banana,x,null,null,out fmin,out StopReason, TMtxFloatPrecision.mvDouble, 1000,1.0E-8,null);
    // stop if Iters >1000 or Tolerance < 1e-8
    // Returns x = [1,1] and FMin = 0, meaning x1=1, x2=1 and minimum value is 0
}
See Also: TRealFunction

Overload 3: Int32 Simplex(TRealFunction Func, ref Double[] Pars, Double[] Consts, Object[] ObjConst, Double[] LB, Double[] UB, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Int32 MaxIter, Double Tolerance, TStrings Verbose)

Minimize function of several variables by using Simplex method with lower and/or upper bounds for parameters.

#NameTypeDescription
1FuncTRealFunction
2ParsDouble[] (ref)
3ConstsDouble[]
4ObjConstObject[]
5LBDouble[]
6UBDouble[]
7FMinDouble (ref)output
8StopReasonTOptStopReason (ref)
9FloatPrecisionTMtxFloatPrecision
10MaxIterInt32
11ToleranceDoublescalar
12VerboseTStrings

Returns: Int32

Remarks:

This version supports lower and upper bound(s) for function parameters Pars. Lower and upper bounds are defined in LB and UP arrays respectively. Depending on lower and/or upper bound for parameter, there are several possibilities for LB and UB:

  • Lower and upper bound: For each parameter both LB and UB should be set to specific value.
  • Upper bound only: In this case, LB is set to -INF, UB to specific value.
  • Lower bound only: In this case, LB should be set to specific value, UB to +INF.
  • No bounds: In this case, use non-bounded Simplex version or set LB and UB to -INF and +INF respecively.
Examples
private double Banana(TVec x, TVec c, object[] o)
{
    return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1 - x[0],2);
}

private void Example()
{
    double[2] x;
    double fmin;
    TOptStopReason StopReason;
    // initial estimates for x1 and x2
    x[0] = 0;
    x[1] = 0;
    int iters = Simplex(Banana,x,null,null,
        new double[] {0,-INF}, new double[] {0.5, 0.7},
        out fmin,out StopReason, TMtxFloatPrecision.mvDouble,1000,1.0E-8,null);
    // stop if Iters >1000 or Tolerance < 1e-8
}