TooN::DownhillSimplex< N > Class Template Reference
[Function optimization]

This is an implementation of the Downhill Simplex (Nelder & Mead, 1965) algorithm. More...

#include <downhill_simplex.h>

List of all members.

Public Member Functions

template<class Function>
 DownhillSimplex (const Function &func, const Vec &c, double spread=1)
const Simplex & get_simplex () const
const Valuesget_values () const
int get_best () const
int get_worst () const
template<class Function>
void iterate (const Function &func)


Detailed Description

template<int N = -1>
class TooN::DownhillSimplex< N >

This is an implementation of the Downhill Simplex (Nelder & Mead, 1965) algorithm.

This particular instance will minimize a given function.

The function maintains $N+1$ points for a $N$ dimensional function, $f$

At each iteration, the following algorithm is performed:

This implementation uses:

Example usage:

    #include <utility>
    #include <TooN/optimization/downhill_simplex.h>
    using namespace std;
    using namespace TooN;

    template<class C> double length(const C& v)
    {
        return sqrt(v*v);
    }

    template<class C> double simplex_size(const C& s)
    {
        return abs(length(s.get_simplex()[s.get_best()] - s.get_simplex()[s.get_worst()]) / length( s.get_simplex()[s.get_best()]));
    }

    double Rosenbrock(Vector<2>& v)
    {
            return sq(1 - v[0]) + 100 * sq(v[1] - sq(v[0]));
    }

    int main()
    {
            Vector<2> starting_point = (make_Vector, -1, 1);

            DownhillSimplex<2> dh_fixed(RosenbrockF, starting_point, 1);
            while(simplex_size(dh_fixed) > 0.0000001)
                    dh_fixed.iterate(RosenbrockF);

            cout << dh_fixed.get_simplex()[dh_fixed.get_best()] << endl;
    }

Parameters:
N The dimension of the function to optimize. As usual, the default value of N (-1) indicates that the class is sized at run-time.

Constructor & Destructor Documentation

template<int N = -1>
template<class Function>
TooN::DownhillSimplex< N >::DownhillSimplex ( const Function &  func,
const Vec c,
double  spread = 1 
)

Initialize the DownhillSimplex class.

The simplex is automatically generated. One point is at c, the remaining points are made by moving c by spread along each axis aligned unit vector.

Parameters:
func Functor to minimize.
c Origin of the initial simplex. The dimension of this vector is used to determine the dimension of the run-time sized version.
spread Size of the initial simplex.


Member Function Documentation

template<int N = -1>
const Simplex& TooN::DownhillSimplex< N >::get_simplex (  )  const

Return the simplex.

template<int N = -1>
const Values& TooN::DownhillSimplex< N >::get_values (  )  const

Return the score at the vertices.

template<int N = -1>
int TooN::DownhillSimplex< N >::get_best (  )  const

Get the index of the best vertex.

template<int N = -1>
int TooN::DownhillSimplex< N >::get_worst (  )  const

Get the index of the worst vertex.

template<int N = -1>
template<class Function>
void TooN::DownhillSimplex< N >::iterate ( const Function &  func  ) 

Perform one iteration of the downhill Simplex algorithm.

Parameters:
func Functor to minimize


Generated on Thu May 7 20:28:42 2009 for TooN by  doxygen 1.5.3