LOOS  v2.3.2
Simplex< T > Class Template Reference

Nelder-Meade Simplex Optimizer (based loosely on the NRC (1996) implementation) More...

#include <Simplex.hpp>

Public Member Functions

 Simplex (const int n)
void dim (const int n)
 Set the number of dimensions.
void seedLengths (const std::vector< T > &seeds)
 Initial guess.
void tolerance (const double d)
 Convergence criterion.
void maximumIterations (const int n)
 Limit on the number of function evaluations to perform.
int maximumIterations () const
int numberOfIterations () const
 Return the number of iterations that it actually went through.
std::vector< T > finalParameters (void) const
 Retrieve the final (best fit) parameters.
finalValue (void) const
 Final (best) value.
template<class C >
std::vector< T > optimize (std::vector< T > &f, C &ftor)
 Optimize via a functor.

Detailed Description

template<typename T = double>
class Simplex< T >

Nelder-Meade Simplex Optimizer (based loosely on the NRC (1996) implementation)

The Simplex class is templated so it can work with doubles, floats, etc. What is actually optimized is a functor that takes a vector containing the parameters.

For example, suppose you're trying to optimize the 2D Rosenbrock function, you could define a functor like,

struct Rosenbrock {
double operator()(const vector<double>& v) {
double x1 = 1.0 - v[0];
double x2 = v[1] - v[0] * v[0];
double x = x1 * x1 + 105.0 * x2 * x2;

Now to optimize this, create a Simplex instance with the same type, and appropriate number of dimensions,

This create a new 2-D Simplex optimizer. The optimizer needs to have a starting guess (seed) as well as an initial step size (length). For the Rosenbrock, let's make the initial guess (0,0) and length of 2 in both dimensions,

vector<double> seeds(2, 0.0);
vector<double> lengths(2, 2.0);
vector<double> final = opt.optimize(seeds, Rosenbrock());
double final_value = opt.finalValue();

Now final is a vector containing the best fit parameters and final_value is the value of the Rosenbrock function at that location.

Definition at line 58 of file Simplex.hpp.

The documentation for this class was generated from the following file: