NelderMead Class |
Namespace: Accord.Math.Optimization
public class NelderMead : BaseOptimizationMethod, IOptimizationMethod<NelderMeadStatus>, IOptimizationMethod, IOptimizationMethod<double[], double>, IOptimizationMethod<double[], double, NelderMeadStatus>
The NelderMead type exposes the following members.
Name | Description | |
---|---|---|
NelderMead(Int32) |
Creates a new NelderMead non-linear optimization algorithm.
| |
NelderMead(NonlinearObjectiveFunction) |
Creates a new NelderMead non-linear optimization algorithm.
| |
NelderMead(Int32, FuncDouble, Double) |
Creates a new NelderMead non-linear optimization algorithm.
|
Name | Description | |
---|---|---|
Capacity |
Gets the maximum number of
variables that can be optimized by this instance.
This is the initial value that has been passed to this
class constructor at the time the algorithm was created.
| |
Convergence |
Gets or sets multiple convergence options to
determine when the optimization can terminate.
| |
DiameterTolerance |
Gets or sets the by how much the simplex diameter |xl - xh| must be
reduced before the algorithm can be terminated. Setting this value
to a value higher than zero causes the algorithm to replace the
standard Convergence criteria with this condition.
Default is zero.
| |
Difference |
The difference between the high and low function
values of the last simplex in the previous call
to the optimization function.
| |
Function |
Gets or sets the function to be optimized.
(Inherited from BaseOptimizationMethod.) | |
LowerBounds |
Gets the lower bounds that should be respected in this
optimization problem. Default is to initialize this vector
with NegativeInfinity.
| |
MaximumValue |
Gets or sets the maximum value that the objective
function could produce before the algorithm could
be terminated as if the solution was good enough.
| |
NumberOfVariables |
Gets or sets the number of variables (free parameters) in the
optimization problem. This number can be decreased after the
algorithm has been created so it can operate on subspaces.
(Overrides BaseOptimizationMethodNumberOfVariables.) | |
Solution |
Gets the current solution found, the values of
the parameters which optimizes the function.
(Inherited from BaseOptimizationMethod.) | |
Status | ||
StepSize |
Gets the step sizes to be used by the optimization
algorithm. Default is to initialize each with 1e-5.
| |
Token |
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
(Inherited from BaseOptimizationMethod.) | |
UpperBounds |
Gets the upper bounds that should be respected in this
optimization problem. Default is to initialize this vector
with PositiveInfinity.
| |
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.) | |
Minimize(Double) |
Finds the minimum value of a function, using the function output at
the current value, if already known. This overload can be used when
embedding Nelder-Mead in other algorithms to avoid initial checks.
| |
OnNumberOfVariablesChanged |
Called when the NumberOfVariables property has changed.
(Overrides BaseOptimizationMethodOnNumberOfVariablesChanged(Int32).) | |
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.) | |
To(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.) | |
ToT | 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.) |
The Nelder–Mead method or downhill simplex method or amoeba method is a commonly used nonlinear optimization technique, which is a well-defined numerical method for problems for which derivatives may not be known. However, the Nelder–Mead technique is a heuristic search method that can converge to non-stationary points on problems that can be solved by alternative methods.
The Nelder–Mead technique was proposed by John Nelder and Roger Mead (1965) and is a technique for minimizing an objective function in a many-dimensional space.
The source code presented in this file has been adapted from the Sbplx method (based on Nelder-Mead's Simplex) given in the NLopt Numerical Optimization Library, created by Steven G. Johnson.
References:
// Let's say we would like to find the minimum // of the function "f(x) = 10 * (x+1)^2 + y^2". // In code, this means we would like to minimize: Func<double[], double> function = (double[] x) => 10.0 * Math.Pow(x[0] + 1.0, 2.0) + Math.Pow(x[1], 2.0); // We can do so using the NelderMead class: var solver = new NelderMead(numberOfVariables: 2) { Function = function // f(x) = 10 * (x+1)^2 + y^2 }; // Now, we can minimize it with: bool success = solver.Minimize(); // And get the solution vector using double[] solution = solver.Solution; // should be (-1, 1) // The minimum at this location would be: double minimum = solver.Value; // should be 0 // Which can be double-checked against Wolfram Alpha if there is need: // https://www.wolframalpha.com/input/?i=min+10+*+(x%2B1)%5E2+%2B+y%5E2