SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
Public Member Functions | Public Attributes | Private Types | Private Attributes | Static Private Attributes | List of all members
TooN::DownhillSimplex< N, Precision > Class Template Reference

#include <downhill_simplex.h>

Public Member Functions

template<class Function >
 DownhillSimplex (const Function &func, const Vector< N > &c, Precision spread=1)
 
template<class Function >
void restart (const Function &func, const Vector< N > &c, Precision spread)
 
bool finished ()
 
template<class Function >
void restart (const Function &func, Precision spread)
 
const Simplexget_simplex () const
 Return the simplex. More...
 
const Valuesget_values () const
 Return the score at the vertices. More...
 
int get_best () const
 Get the index of the best vertex. More...
 
int get_worst () const
 Get the index of the worst vertex. More...
 
template<class Function >
void find_next_point (const Function &func)
 
template<class Function >
bool iterate (const Function &func)
 

Public Attributes

Precision alpha
 Reflected size. Defaults to 1. More...
 
Precision rho
 Expansion ratio. Defaults to 2. More...
 
Precision gamma
 Contraction ratio. Defaults to .5. More...
 
Precision sigma
 Shrink ratio. Defaults to .5. More...
 
Precision epsilon
 Tolerance used to determine if the optimization is complete. Defaults to square root of machine precision. More...
 
Precision zero_epsilon
 Additive term in tolerance to prevent excessive iterations if $x_\mathrm{optimal} = 0$. Known as ZEPS in numerical recipies. Defaults to 1e-20. More...
 

Private Types

typedef Matrix< Vertices, N, Precision > Simplex
 
typedef Vector< Vertices, Precision > Values
 

Private Attributes

Simplex simplex
 
Values values
 

Static Private Attributes

static const int Vertices = (N==-1?-1:N+1)
 

Detailed Description

template<int N = -1, typename Precision = double>
class TooN::DownhillSimplex< N, Precision >

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 "optimization/downhill_simplex.h"
using namespace std;
using namespace TooN;
double sq(double x)
{
return x*x;
}
double Rosenbrock(const Vector<2>& v)
{
return sq(1 - v[0]) + 100 * sq(v[1] - sq(v[0]));
}
int main()
{
Vector<2> starting_point = makeVector( -1, 1);
DownhillSimplex<2> dh_fixed(Rosenbrock, starting_point, 1);
while(dh_fixed.iterate(Rosenbrock))
{
cout << dh.get_values()[dh.get_best()] << endl;
}
cout << dh_fixed.get_simplex()[dh_fixed.get_best()] << endl;
}
@param   N The dimension of the function to optimize. As usual, the default value of <i>N</i> (-1) indicates
         that the class is sized at run-time.

Definition at line 77 of file downhill_simplex.h.

Member Typedef Documentation

template<int N = -1, typename Precision = double>
typedef Matrix<Vertices, N, Precision> TooN::DownhillSimplex< N, Precision >::Simplex
private

Definition at line 80 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
typedef Vector<Vertices, Precision> TooN::DownhillSimplex< N, Precision >::Values
private

Definition at line 81 of file downhill_simplex.h.

Constructor & Destructor Documentation

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

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
funcFunctor to minimize.
cOrigin of the initial simplex. The dimension of this vector is used to determine the dimension of the run-time sized version.
spreadSize of the initial simplex.

Definition at line 92 of file downhill_simplex.h.

Member Function Documentation

template<int N = -1, typename Precision = double>
template<class Function >
void TooN::DownhillSimplex< N, Precision >::find_next_point ( const Function &  func)
inline

Perform one iteration of the downhill Simplex algorithm

Parameters
funcFunctor to minimize

Definition at line 175 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
bool TooN::DownhillSimplex< N, Precision >::finished ( )
inline

Check to see it iteration should stop. You probably do not want to use this function. See iterate() instead. This function updates nothing. The termination criterion is that the simplex span (distancve between the best and worst vertices) is small compared to the scale or small overall.

Definition at line 129 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
int TooN::DownhillSimplex< N, Precision >::get_best ( ) const
inline

Get the index of the best vertex.

Definition at line 162 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
const Simplex& TooN::DownhillSimplex< N, Precision >::get_simplex ( ) const
inline

Return the simplex.

Definition at line 150 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
const Values& TooN::DownhillSimplex< N, Precision >::get_values ( ) const
inline

Return the score at the vertices.

Definition at line 156 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
int TooN::DownhillSimplex< N, Precision >::get_worst ( ) const
inline

Get the index of the worst vertex.

Definition at line 168 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
template<class Function >
bool TooN::DownhillSimplex< N, Precision >::iterate ( const Function &  func)
inline

Perform one iteration of the downhill Simplex algorithm, and return the result of not DownhillSimplex::finished.

Parameters
funcFunctor to minimize

Definition at line 273 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
template<class Function >
void TooN::DownhillSimplex< N, Precision >::restart ( const Function &  func,
const Vector< N > &  c,
Precision  spread 
)
inline

This function sets up the simplex around, with one point at c and the remaining points are made by moving by spread along each axis aligned unit vector.

Parameters
funcFunctor to minimize.
cc corner point of the simplex
spreadspread simplex size

Definition at line 112 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
template<class Function >
void TooN::DownhillSimplex< N, Precision >::restart ( const Function &  func,
Precision  spread 
)
inline

This function resets the simplex around the best current point.

Parameters
funcFunctor to minimize.
spreadsimplex size

Definition at line 144 of file downhill_simplex.h.

Member Data Documentation

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::alpha

Reflected size. Defaults to 1.

Definition at line 279 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::epsilon

Tolerance used to determine if the optimization is complete. Defaults to square root of machine precision.

Definition at line 283 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::gamma

Contraction ratio. Defaults to .5.

Definition at line 281 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::rho

Expansion ratio. Defaults to 2.

Definition at line 280 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::sigma

Shrink ratio. Defaults to .5.

Definition at line 282 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Simplex TooN::DownhillSimplex< N, Precision >::simplex
private

Definition at line 289 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Values TooN::DownhillSimplex< N, Precision >::values
private

Definition at line 292 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
const int TooN::DownhillSimplex< N, Precision >::Vertices = (N==-1?-1:N+1)
staticprivate

Definition at line 79 of file downhill_simplex.h.

template<int N = -1, typename Precision = double>
Precision TooN::DownhillSimplex< N, Precision >::zero_epsilon

Additive term in tolerance to prevent excessive iterations if $x_\mathrm{optimal} = 0$. Known as ZEPS in numerical recipies. Defaults to 1e-20.

Definition at line 284 of file downhill_simplex.h.


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