Cobyla Class 
Namespace: Accord.Math.Optimization
public class Cobyla : BaseOptimizationMethod, IOptimizationMethod, IOptimizationMethod<double[], double>, IOptimizationMethod<CobylaStatus>, IOptimizationMethod<double[], double, CobylaStatus>
The Cobyla type exposes the following members.
Name  Description  

Cobyla(Int32) 
Creates a new instance of the Cobyla optimization algorithm.
 
Cobyla(NonlinearObjectiveFunction) 
Creates a new instance of the Cobyla optimization algorithm.
 
Cobyla(Int32, FuncDouble, Double) 
Creates a new instance of the Cobyla optimization algorithm.
 
Cobyla(NonlinearObjectiveFunction, NonlinearConstraint) 
Creates a new instance of the Cobyla optimization algorithm.
 
Cobyla(NonlinearObjectiveFunction, IEnumerableNonlinearConstraint) 
Creates a new instance of the Cobyla optimization algorithm.

Name  Description  

Function 
Gets or sets the function to be optimized.
(Inherited from BaseOptimizationMethod.)  
Iterations 
Gets the number of iterations performed in the last
call to Minimize.
 
MaxIterations 
Gets or sets the maximum number of iterations
to be performed during optimization. Default
is 0 (iterate until convergence).
 
NumberOfVariables 
Gets the number of variables (free parameters)
in the optimization problem.
(Inherited from BaseOptimizationMethod.)  
Solution 
Gets the current solution found, the values of
the parameters which optimizes the function.
(Inherited from BaseOptimizationMethod.)  
Status  
Token 
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
(Inherited from BaseOptimizationMethod.)  
Value 
Gets the output of the function at the current Solution.
(Inherited from BaseOptimizationMethod.) 
Name  Description  

Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Maximize 
Finds the maximum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
Maximize(Double) 
Finds the maximum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
Minimize 
Finds the minimum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
Minimize(Double) 
Finds the minimum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
OnNumberOfVariablesChanged 
Called when the NumberOfVariables property has changed.
(Inherited from BaseOptimizationMethod.)  
Optimize 
Implements the actual optimization algorithm. This
method should try to minimize the objective function.
(Overrides BaseOptimizationMethodOptimize.)  
ToString  Returns a string that represents the current object. (Inherited from Object.) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
IsEqual  Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.)  
ToT 
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.) 
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 nonsmooth NLP problems with a moderate number of variables (about 100), with inequality constraints only.
References:
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 2variable 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)]