Click or drag to resize
Accord.NET (logo)

Cobyla Class

Constrained optimization by linear approximation.
Inheritance Hierarchy
SystemObject
  Accord.Math.OptimizationBaseOptimizationMethod
    Accord.Math.OptimizationCobyla

Namespace:  Accord.Math.Optimization
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public class Cobyla : BaseOptimizationMethod, IOptimizationMethod, 
	IOptimizationMethod<double[], double>, IOptimizationMethod<CobylaStatus>, 
	IOptimizationMethod<double[], double, CobylaStatus>
Request Example View Source

The Cobyla type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyFunction
Gets or sets the function to be optimized.
(Inherited from BaseOptimizationMethod.)
Public propertyIterations
Gets the number of iterations performed in the last call to Minimize.
Public propertyMaxIterations
Gets or sets the maximum number of iterations to be performed during optimization. Default is 0 (iterate until convergence).
Public propertyNumberOfVariables
Gets the number of variables (free parameters) in the optimization problem.
(Inherited from BaseOptimizationMethod.)
Public propertySolution
Gets the current solution found, the values of the parameters which optimizes the function.
(Inherited from BaseOptimizationMethod.)
Public propertyStatus
Public propertyToken
Gets or sets a cancellation token that can be used to stop the learning algorithm while it is running.
(Inherited from BaseOptimizationMethod.)
Public propertyValue
Gets the output of the function at the current Solution.
(Inherited from BaseOptimizationMethod.)
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodMaximize
Finds the maximum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Public methodMaximize(Double)
Finds the maximum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMinimize
Finds the minimum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Public methodMinimize(Double)
Finds the minimum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Protected methodOnNumberOfVariablesChanged
Called when the NumberOfVariables property has changed.
(Inherited from BaseOptimizationMethod.)
Protected methodOptimize
Implements the actual optimization algorithm. This method should try to minimize the objective function.
(Overrides BaseOptimizationMethodOptimize.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

Constrained optimization by linear approximation (COBYLA) is a numerical optimization method for constrained problems where the derivative of the objective function is not known, invented by Michael J. D. Powell.

COBYLA2 is an implementation of Powell’s nonlinear derivative–free constrained optimization that uses a linear approximation approach. The algorithm is a sequential trust–region algorithm that employs linear approximations to the objective and constraint functions, where the approximations are formed by linear interpolation at n + 1 points in the space of the variables and tries to maintain a regular–shaped simplex over iterations.

This algorithm is able to solve non-smooth NLP problems with a moderate number of variables (about 100), with inequality constraints only.

References:

Examples

Let's say we would like to optimize a function whose gradient we do not know or would is too difficult to compute. All we have to do is to specify the function, pass it to Cobyla and call its Minimize() method:

// We would like to find the minimum of min f(x) = 10 * (x+1)^2 + y^2
Func<double[], double> function = x => 10 * Math.Pow(x[0] + 1, 2) + Math.Pow(x[1], 2);

// Create a cobyla method for 2 variables
Cobyla cobyla = new Cobyla(2, function);

bool success = cobyla.Minimize();

double minimum = minimum = cobyla.Value; // Minimum should be 0.
double[] solution = cobyla.Solution;     // Vector should be (-1, 0)

Cobyla can be used even when we have constraints in our optimization problem. The following example can be found in Fletcher's book Practical Methods of Optimization, under the equation number (9.1.15).

// We will optimize the 2-variable function f(x, y) = -x -y
var f = new NonlinearObjectiveFunction(2, x => -x[0] - x[1]);

// Under the following constraints
var constraints = new[]
{
    new NonlinearConstraint(2, x =>             x[1] - x[0] * x[0] >= 0),
    new NonlinearConstraint(2, x =>  1 - x[0] * x[0] - x[1] * x[1] >= 0),
};

// Create a Cobyla algorithm for the problem
var cobyla = new Cobyla(function, constraints);

// Optimize it
bool success = cobyla.Minimize();
double minimum = cobyla.Value;        // Minimum should be -2 * sqrt(0.5)
double[] solution = cobyla.Solution;  // Vector should be [sqrt(0.5), sqrt(0.5)]
See Also