ILNumerics Ultimate VS

Optimizationfmin Method

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Find minimum of a constrained multivariable optimization problem

[ILNumerics Optimization Toolbox]

Namespace:  ILNumerics.Toolboxes
Assembly:  ILNumerics.Toolboxes.Optimization (in ILNumerics.Toolboxes.Optimization.dll) Version: 5.5.0.0 (5.5.7503.3146)
Syntax

public static RetArray<double> fmin(
	OptimizationObjectiveFunction<double> objfunc,
	InArray<double> x0,
	InArray<double> lowerBound = null,
	InArray<double> upperBound = null,
	OptimizationObjectiveFunction<double> InequalityConstraint = null,
	OptimizationObjectiveFunction<double> EqualityConstraint = null,
	HessianUpdateMethod hessUpdates = HessianUpdateMethod.BFGS,
	int maxIter = 500,
	Nullable<double> tol = null,
	Nullable<double> tolX = null,
	OutArray<double> gradientNorm = null,
	OutArray<double> iterations = null,
	OptimizationFminIterationCallback<double> callback = null
)

Parameters

objfunc
Type: ILNumerics.ToolboxesOptimizationObjectiveFunctionDouble
Cost function to be minimized, defined from Rn to R
x0
Type: ILNumericsInArrayDouble
Initial solution guess, lenght: (Rn). Specifies the starting point for the search.
lowerBound (Optional)
Type: ILNumericsInArrayDouble
Lower bound constraint, vector of length n. Default: double.MinValue (no lower bound)
upperBound (Optional)
Type: ILNumericsInArrayDouble
Upper bound constraint, vector of length n. Default: double.MaxValue (no upper bound)
InequalityConstraint (Optional)
Type: ILNumerics.ToolboxesOptimizationObjectiveFunctionDouble
Function defining the inequality constraints. Default : null (no inequality constraints)
EqualityConstraint (Optional)
Type: ILNumerics.ToolboxesOptimizationObjectiveFunctionDouble
Function defining the equality constraints. Default : null (no equality constraints)
hessUpdates (Optional)
Type: ILNumerics.ToolboxesHessianUpdateMethod
[optional] Optimization method to be used to minimize the lagrangian. Default: Bfgs
maxIter (Optional)
Type: SystemInt32
[optional] Maximal number of iterations allowed. Default: 500
tol (Optional)
Type: SystemNullableDouble
[optional] Tolerance on the quality of the solution for the subproblems, measured by the norm of the gradient. Default: 1e-8
tolX (Optional)
Type: SystemNullableDouble
[optional] Exit condition on the difference between subsequent intermediate solutions. Default: DefaultTolerance
gradientNorm (Optional)
Type: ILNumericsOutArrayDouble
[optional] Output: Request the gradient norms of the Lagrangian at each iteration. Default: null (do not compute)
iterations (Optional)
Type: ILNumericsOutArrayDouble
[optional] Output array of intermediate positions at each iteration. Default: null (not provided)
callback (Optional)
Type: ILNumerics.ToolboxesOptimizationFminIterationCallbackDouble
Callback function to be called in each iteration. See: FminCallbackInfoT

Return Value

Type: RetArrayDouble
Minimizer of the cost function subject to constraints
Exceptions

ExceptionCondition
ArgumentNullException If x0 is null
ArgumentOutOfRangeException If an component of x0, lowerBound, and upperBound is no-a-number (NaN) or if a component of x0 is infinity
Remarks

fmin finds the minimum of a scalar function of several variables, starting at an initial guess and subject to constraints if provided.

The minimization problem can be written in the following form:

min objfunc(x)

subject to InequalityConstraint(x) < 0, EqualityConstraint(x)=0, lowerBound <= x <= upperBound.

The returned value will be of the same size as the initial guess x0 provided by the user.

On empty initial guess input, an empty array will be returned.

Lower and upper bounds which are not provided are taken as double.MinValue and double.MaxValue respectively.

This is generally referred to as constrained nonlinear optimization

  • fmin(objfunc,x0) gives a local minimizer of the objective function using the bfgs algorithm. objfunc reaches a minimum at a minimizer.
    Examples

    Array<double> x0 = -8 *ILMath.ones(4, 1); // initial guess for the computation 
    Array<double> Mini = Optimization.fmin(Optimization.Rosenbrock, x0); // minimizer of the Rosembrock function in dimension 4;
  • fmin(objfunc,x0,InequalityConstraint) gives a local minimizer of the objective function using the bfgs algorithm subject to inequality constraints.
    Examples

     //Sample function definition
     public static RetArray<double> SampleFunction(InArray<double> xp)
    {
        using (Scope.Enter(xp))
        {
            double val = (double)(2 * x[ 0] * x[ 0] + x[ 0] * x[ 1] + 2 * x[ 1] * x[ 1] - 6 * x[ 0] - 6 * x[ 1] + 15);
            return val;
        }
    }
     public static RetArray<double> InequalityConstrainedSampleFunction(InArray<double> x)
    {
     using (Scope.Enter(x))
     {
     double val1 = (double)(x[0] + 2 * x[1]);
     double val2 = (double)(4 * x[0]);
     double val3 = (double)(x[1]);
     double val4 = (double)(-2 * x[0] + 2 * x[1]);
     return array<double>(new double[] { val1, val2, val3, val4 }, 1, 4).T;
     }
     }
     Array<double> x0 = ILMath.ones(2, 1); // initial guess for the computation 
     Array<double> x = Optimization.fmin(SampleFunction, x0, InequalityConstraint: InequalityConstrainedSampleFunction); // minimizer of the Rosembrock function in dimension 4;
  • Optimization.fmin(objfunc,x0,EqualityConstraint) gives a local minimizer of the objective function using the bfgs algorithm subject to an equality constraints.
    Examples

    public static RetArray<double> EqualityConstrainedSampleFunction(InArray<double> x)
    {
    using (Scope.Enter(x))
    {
    double val = (double)(-2 * x[0] + 2 * x[1] + 1);
    return val;
    }
    }
    Array<double> x0 = 6 * ones<double>(2, 1); // initial guess for the computation 
    Array<double> Mini = Array<double> x = Optimization.fmin(SampleFunction, x0, EqualityConstraint: EqualityConstrainedSampleFunction); // minimizer of the Sample function in dimension 2 with equality constraint;
  • Optimization.fmin(objfunc,x0,inequalityConstraint, EqualityConstraint) gives a local minimizer of the objective function using the bfgs algorithm subject to inequality and equality constraints.
    Examples

    Array<double> x0 = 2e+20 * ones<double>(2, 1); // initial guess for the computation 
    Array<double> x = Optimization.fmin(SampleFunction, x0, InequalityConstraint: InequalityConstrainedSampleFunction, EqualityConstraint: EqualityConstrainedSampleFunction); // minimizer of the Sample function in dimension 2 with equality constraint only;
  • Optimization.fmin(objfunc,x0,inequalityConstraint, EqualityConstraint,lowerBound, upperBound) gives a local minimizer of the objective function using the bfgs algorithm subject to inequality, equality, and bounded constraints.
    Examples

    Array<double> x0 = 4e+20 * ones<double>(2, 1); // initial guess for the computation 
    Array<double> x = Optimization.fmin(SampleFunction, x0, InequalityConstraint: InequalityConstrainedSampleFunction, EqualityConstraint: EqualityConstrainedSampleFunction); // minimizer of the toy function in dimension 2 with equality constraint only;
  • All other combinations of input parameters are - of course - allowed also.

[ILNumerics Optimization Toolbox]

See Also

Reference

Other Resources