Optimization.ConjGrad Method

Overload List

#SignatureDescription
1Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo)Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.
2Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch)Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.
3Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch, Int32 MaxIter, Double Tol, Double GradTol)Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.
4Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)Minimizes the function of several variables by using the Conjugate gradient optimization algorithm.

Overload 1: Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo)

Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.

#NameTypeDescription
1FunTRealFunction
2GradTGrad
3ParsDouble[] (ref)
4ConstsDouble[]
5ObjConstObject[]
6FMinDouble (ref)output
7FloatPrecisionTMtxFloatPrecision
8FletcherAlgoBoolean

Returns: Int32

Overload 2: Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch)

Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.

#NameTypeDescription
1FunTRealFunction
2GradTGrad
3ParsDouble[] (ref)
4ConstsDouble[]
5ObjConstObject[]
6FMinDouble (ref)output
7StopReasonTOptStopReason (ref)
8FloatPrecisionTMtxFloatPrecision
9FletcherAlgoBoolean
10SoftLineSearchBoolean

Returns: Int32

Overload 3: Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch, Int32 MaxIter, Double Tol, Double GradTol)

Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.

#NameTypeDescription
1FunTRealFunction
2GradTGrad
3ParsDouble[] (ref)
4ConstsDouble[]
5ObjConstObject[]
6FMinDouble (ref)output
7StopReasonTOptStopReason (ref)
8FloatPrecisionTMtxFloatPrecision
9FletcherAlgoBoolean
10SoftLineSearchBoolean
11MaxIterInt32
12TolDoublescalar
13GradTolDoublescalar

Returns: Int32

Overload 4: Int32 ConjGrad(TRealFunction Fun, TGrad Grad, ref Double[] Pars, Double[] Consts, Object[] ObjConst, ref Double FMin, ref TOptStopReason StopReason, TMtxFloatPrecision FloatPrecision, Boolean FletcherAlgo, Boolean SoftLineSearch, Int32 MaxIter, Double Tol, Double GradTol, TStrings Verbose)

Minimizes the function of several variables by using the Conjugate gradient optimization algorithm.

#NameDescription
1FunReal function (must be of Dew.Math.TRealFunction type) to be minimized.
2GradThe gradient and Hessian procedure (must be of Dew.Math.TGrad type), used for calculating the gradient.
3ParsStores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position).
4ConstsAdditional Fun constant parameteres (can be/is usually nil).
5FloatPrecisionSpecifies the floating point precision to be used by the routine.
6ObjConstAdditional Fun constant parameteres (can be/is usually nil).
7FMinReturns function value at minimum.
8StopReasonReturns reason why minimum search stopped (see Dew.Math.TOptStopReason).
9FletcherAlgoIf True, ConjGrad procedure will use Fletcher-Reeves method. If false, ConjGrad procedure will use Polak-Ribiere method.
10SoftLineSearchSelects the line-search acceptance rule used along each conjugate direction. It is a true/false parameter and does not turn the gradient on or off - both modes are gradient based (the line search evaluates the gradient at each trial step). True (soft / inexact, the default) accepts the first step satisfying the Armijo sufficient-decrease condition f(x+alpha d) <= f(x) + rho alpha grad f^T d and is the robust choice for a NUMERICAL (finite-difference) gradient
11False (exact / Wolfe) additionally enforces the curvature condition |grad f(x+alpha d)^T d| <= beta |grad f^T d| and should be used only with an exact gradient. "Soft off" is still a gradient-based search, just a stricter one. See also the same parameter on [seeDew.Math.Units.Optimization.BFGS].
12MaxIterMaximum allowed numer of minimum search iterations.
13TolDesired Pars - minimum position tolerance.
14GradTolMinimum allowed gradient C-Norm.
15VerboseIf 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 smooth real function of several
variables with the nonlinear conjugate-gradient method, generating search directions that are conjugate with respect to the local curvature (Fletcher-Reeves when FletcherAlgo=True, Polak-Ribiere when False) and a line search along each. The standard test 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 (1,1)(1,1) and gradient

(d f)/(d x_0) = -400 (x_1 - x_0^2) x_0 - 2 (1 - x_0), (d f)/(d x_1) = 200 (x_1 - x_0^2)

Domain. Pars holds the n starting coordinates;
Grad returns the gradient (exact, or numerical with SoftLineSearch=True); MaxIter > 0; Tol,GradTol ≥ 0.

Defined behaviour. Returns the iteration count; Pars
holds the minimizer and FMin the minimum value. StopReason is an optimality cause (Dew.Math.TOptStopReason.OptResConverged, Dew.Math.TOptStopReason.OptResSmallGrad or

Dew.Math.TOptStopReason.OptResSmallStep) or a non-convergence cause such as
Dew.Math.TOptStopReason.OptResMaxIter. A NaN from the objective propagates

into FMin.

Examples
// Objective function
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] Pars;
    double fmin;
    TOptStopReason StopReason;
    // initial estimates for x1 and x2
    Pars[0] = 0;
    Pars[1] = 0;
    int iters = Optimization.ConjGrad(Banana, MtxIntDiff.NumericGradRichardson, Pars, null, null, out fmin, out StopReason,
        mvDouble, true, false, 1000, 1.0e-8, 1.0e-8, null);
    // stop if Iters >1000 or Tolerance < 1e-8
}
See Also: TGrad, TRealFunction, MtxIntDiff.NumericGradDifference, MtxIntDiff.NumericGradRichardson