dlr::optimization::OptimizerNelderMead< Functor > Class Template Reference

OptimizerNelderMead implements the non-gradient based downhill simplex optimization method of Nelder and Mead, as described in [1] and [2]. More...

#include <optimizerNelderMead.h>

Inheritance diagram for dlr::optimization::OptimizerNelderMead< Functor >:

Inheritance graph
[legend]
Collaboration diagram for dlr::optimization::OptimizerNelderMead< Functor >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef Functor::argument_type argument_type
 This is the Type of the objective function argument.
typedef Functor::result_type result_type
 This is the Type of the objective function return value.

Public Member Functions

 OptimizerNelderMead ()
 Default constructor sets parameters to reasonable values for functions which take values and arguments in the "normal" range of 0 to 100 or so.
 OptimizerNelderMead (const Functor &functor)
 Constructor which specifies the specific Functor instance to use.
 OptimizerNelderMead (const OptimizerNelderMead &source)
 Copy constructor.
 ~OptimizerNelderMead ()
 Destructor.
virtual std::vector< size_t > getNumberOfFunctionCalls ()
 Queries the number of iterations required to complete the previous minimization.
void setDelta (const argument_type &delta)
 This method sets the spacing of the initial points used in the nonlinear optimization, without affecting any other optimization parameters.
void setNumberOfRestarts (size_t numberOfRestarts)
 Sets how many times the optimization will be restarted.
void setParameters (argument_type delta, size_t functionCallLimit=5000, size_t numberOfRestarts=1, double alpha=1.0, double beta=0.5, double gamma=2.0, double minimumSimplexValueSpan=0.0001, size_t verbosity=0)
 Sets minimization parameters.
virtual void setStartPoint (argument_type startPoint)
 Sets the initial conditions for the minimization.
virtual void setVerbosity (int verbosity)
 This function sets the level of text sent to standard output by the class.
OptimizerNelderMeadoperator= (const OptimizerNelderMead &source)
 Assignment operator.
Functor objectiveFunction ()
 This method returns a copy of the Functor instance used for optimization.
result_type optimalValue ()
 This method finds the optimum of the current Functor, if necessary, and returns the Functor value at that point.
argument_type optimum ()
 This method finds the optimum of the current Functor, if necessary, and returns the Functor argument which produces that optimum.
void setObjectiveFunction (const Functor &functor)
 This method specifies the Functor instance to use for the optimization.

Protected Member Functions

void computeAxisSums (const std::vector< argument_type > &currentPoints, argument_type &axisSums)
 This protected member function collapses a vector of points by summing the corresponding elements of each point (useful for averaging a bunch of locations in parameter space).
void doNelderMead (std::vector< argument_type > &currentPoints, std::vector< result_type > &currentValues, size_t &numberOfFunctionCalls)
 This protected member function runs the actual simplex search.
result_type evaluateMove (std::vector< argument_type > &currentPoints, std::vector< result_type > &currentValues, const argument_type &axisSums, double factor)
 This protected member function is used to decide whether a proposed step is in fact a good one, and also updates its arguments if the move is accepted.
std::pair< typename Functor::argument_type,
typename Functor::result_type > 
run ()
 This protected member function performs the minimization.
virtual void setOptimum (const typename Functor::argument_type &optimum, const typename Functor::result_type &optimalValue, bool needsFurtherOptimization)
 This protected member function provides a way for subclasses to communicate intermediate optimization results outside of the normal "return value of this->run()" method.

Protected Attributes

argument_type m_delta
size_t m_functionCallLimit
size_t m_numberOfRestarts
double m_alpha
double m_beta
double m_gamma
double m_minimumSimplexValueSpan
bool m_deltaValueHack
std::vector< size_t > m_functionCallCount
argument_type m_theta0
size_t m_verbosity
Functor m_functor
 m_functor->operator()() should compute the objective function.
bool m_needsOptimization
 Set to false if m_optimum contains a valid optimum, true otherwise.
argument_type m_optimum
 Caches the result of the most recent optimization.
result_type m_optimalValue
 Caches the result of the most recent optimization.

Detailed Description

template<class Functor>
class dlr::optimization::OptimizerNelderMead< Functor >

OptimizerNelderMead implements the non-gradient based downhill simplex optimization method of Nelder and Mead, as described in [1] and [2].

This algorithm seeks the parameter value which minimizes the objective function. The template parameter (Functor) defines the type to use as the objective function of the minimization.

[1] W. H. Press et al., Numerical Recipes in C The Art of Scientific Computing, Cambridge University Press, 1988.

[2] J.A. Nelder and R. Mead. A simplex method for function minimization. Computer Journal, 7:303--313, 1965.

Definition at line 42 of file optimizerNelderMead.h.


Member Typedef Documentation

template<class Functor>
typedef Functor::argument_type dlr::optimization::OptimizerNelderMead< Functor >::argument_type

This is the Type of the objective function argument.

Reimplemented from dlr::optimization::Optimizer< Functor >.

Definition at line 47 of file optimizerNelderMead.h.

template<class Functor>
typedef Functor::result_type dlr::optimization::OptimizerNelderMead< Functor >::result_type

This is the Type of the objective function return value.

Reimplemented from dlr::optimization::Optimizer< Functor >.

Definition at line 48 of file optimizerNelderMead.h.


Constructor & Destructor Documentation

template<class Functor>
dlr::optimization::OptimizerNelderMead< Functor >::OptimizerNelderMead (  )  [inline]

Default constructor sets parameters to reasonable values for functions which take values and arguments in the "normal" range of 0 to 100 or so.

Definition at line 404 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_deltaValueHack, and dlr::optimization::OptimizerNelderMead< Functor >::setParameters().

template<class Functor>
dlr::optimization::OptimizerNelderMead< Functor >::OptimizerNelderMead ( const Functor &  functor  )  [inline, explicit]

Constructor which specifies the specific Functor instance to use.

Using this constructor exclusively avoids the danger of calling optimalValue() or optimum() before a Functor instance has been specified.

Parameters:
functor A copy of this argument will be stored internally for use in optimization.

Definition at line 419 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_deltaValueHack, and dlr::optimization::OptimizerNelderMead< Functor >::setParameters().

template<class Functor>
dlr::optimization::OptimizerNelderMead< Functor >::OptimizerNelderMead ( const OptimizerNelderMead< Functor > &  source  )  [inline]

Copy constructor.

Parameters:
source The OptimizerNelderMead instance to be copied.

Definition at line 432 of file optimizerNelderMead.h.

References dlr::optimization::copyArgumentType(), and dlr::optimization::OptimizerNelderMead< Functor >::m_delta.

template<class Functor>
dlr::optimization::OptimizerNelderMead< Functor >::~OptimizerNelderMead (  )  [inline]

Destructor.

Definition at line 451 of file optimizerNelderMead.h.


Member Function Documentation

template<class Functor>
std::vector< size_t > dlr::optimization::OptimizerNelderMead< Functor >::getNumberOfFunctionCalls (  )  [inline, virtual]

Queries the number of iterations required to complete the previous minimization.

If the minimization parameter "restarts" is 0, there will be only one number to report. If restarts is greater than 0, the first element of the return value will reflect the number of iterations in the initial minimization, and subsequent numbers will reflect the number of iterations in the following restarted minimizations.

Returns:
a vector of iteration counts.

Definition at line 462 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_functionCallCount.

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::setDelta ( const argument_type delta  ) 

This method sets the spacing of the initial points used in the nonlinear optimization, without affecting any other optimization parameters.

Parameters:
delta The method of Nelder and Mead requires not only a point in parameter space at which to start the minimization, but also N additional initial points, where N is the dimensionality of the parameter space. These will be automatically generated according to: p[i+1] = p[0] + delta[i]*e[i] where e[i] is all zeros except for a one in the i(th) position.

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::setNumberOfRestarts ( size_t  numberOfRestarts  )  [inline]

Sets how many times the optimization will be restarted.

No smaller than 1 unless your objective function is very simple, since downhill simplex search often benefits from a restart or two.

Parameters:
numberOfRestarts 

Definition at line 124 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_numberOfRestarts.

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::setParameters ( argument_type  delta,
size_t  functionCallLimit = 5000,
size_t  numberOfRestarts = 1,
double  alpha = 1.0,
double  beta = 0.5,
double  gamma = 2.0,
double  minimumSimplexValueSpan = 0.0001,
size_t  verbosity = 0 
)

Sets minimization parameters.

Default values are reasonable for functions which take values and arguments in the "normal" range of 0 to 100 or so.

Since it is difficult to provide a default value for the template parameter type Functory::argument_type, no default is provided. If a default were provided, it would be a vector of all ones, with length equal to the dimensionality of the space over which the optimization is to be performed.

Parameters:
delta The method of Nelder and Mead requires not only a point in parameter space at which to start the minimization, but also N additional initial points, where N is the dimensionality of the parameter space. These will be automatically generated according to: p[i+1] = p[0] + delta[i]*e[i] where e[i] is all zeros except for a one in the i(th) position.
functionCallLimit Each minimization will terminate after this many iterations, even if a minimum has not been found.
numberOfRestarts Following successful termination, the minimization will be re-run this many times to refine the result accuracy. Generally you should set this to at least one for this algorithm, since restarting the algorithm frequently leads to significantly better final results.
alpha Specifies the size of the initial reflection step.
beta Specifies the size of the second reflection step.
gamma Specifies the "shrink" factor if neither reflection step is successful.
minimumSimplexValueSpan Terminate if, among the N + 1 current points,
(2*(abs(f(pMax) - f(pMin)) / (abs(f(pMax)) + abs(f(pMin))))) < minSimplexValueSpan

where pMax is the point generating the biggest value, and pMin is the point generating the smallest value.

Parameters:
verbosity Specifies how much standard output should be generated. Higher numbers mean more output.

Referenced by dlr::optimization::OptimizerNelderMead< Functor >::OptimizerNelderMead().

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::setStartPoint ( argument_type  startPoint  )  [inline, virtual]

Sets the initial conditions for the minimization.

Gradient based search will start at this location in parameter space.

Parameters:
startPoint Indicates a point in the parameter space of the objective function.

Definition at line 513 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_theta0.

template<class Functor>
virtual void dlr::optimization::OptimizerNelderMead< Functor >::setVerbosity ( int  verbosity  )  [inline, virtual]

This function sets the level of text sent to standard output by the class.

Parameters:
verbosity This argument specifies how verbose to be. 0 means no output, 3 means lots.

Definition at line 204 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_verbosity.

template<class Functor>
OptimizerNelderMead< Functor > & dlr::optimization::OptimizerNelderMead< Functor >::operator= ( const OptimizerNelderMead< Functor > &  source  )  [inline]

Assignment operator.

Parameters:
source The OptimizerNelderMead instance to be copied.
Returns:
Reference to *this.

Definition at line 526 of file optimizerNelderMead.h.

References dlr::optimization::OptimizerNelderMead< Functor >::m_alpha, dlr::optimization::OptimizerNelderMead< Functor >::m_beta, dlr::optimization::OptimizerNelderMead< Functor >::m_delta, dlr::optimization::OptimizerNelderMead< Functor >::m_deltaValueHack, dlr::optimization::OptimizerNelderMead< Functor >::m_functionCallCount, dlr::optimization::OptimizerNelderMead< Functor >::m_functionCallLimit, dlr::optimization::OptimizerNelderMead< Functor >::m_gamma, dlr::optimization::OptimizerNelderMead< Functor >::m_minimumSimplexValueSpan, and dlr::optimization::OptimizerNelderMead< Functor >::m_numberOfRestarts.

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::computeAxisSums ( const std::vector< argument_type > &  currentPoints,
argument_type axisSums 
) [protected]

This protected member function collapses a vector of points by summing the corresponding elements of each point (useful for averaging a bunch of locations in parameter space).

Parameters:
currentPoints This argument specifies the points to sum.
axisSums This argument is used to return the result.

template<class Functor>
void dlr::optimization::OptimizerNelderMead< Functor >::doNelderMead ( std::vector< argument_type > &  currentPoints,
std::vector< result_type > &  currentValues,
size_t &  numberOfFunctionCalls 
) [protected]

This protected member function runs the actual simplex search.

It modifies all arguments.

Parameters:
currentPoints This argument specifies the initial set of points, and is used to return the final set of points.
currentValues This argument specifies the initial set of function values, and is used to return the final set of function values.
numberOfFunctionCalls This argument returns the total number of function calls required by the minimization.

Referenced by dlr::optimization::OptimizerNelderMead< Functor >::run().

template<class Functor>
OptimizerNelderMead< Functor >::result_type dlr::optimization::OptimizerNelderMead< Functor >::evaluateMove ( std::vector< argument_type > &  currentPoints,
std::vector< result_type > &  currentValues,
const argument_type axisSums,
double  factor 
) [inline, protected]

This protected member function is used to decide whether a proposed step is in fact a good one, and also updates its arguments if the move is accepted.

Parameters:
currentPoints This argument specifies the current set of points in parameter space.
currentValues This argument specifies the function value at each of the points in currentPoints.
axisSums This argument passes in the sums of the elements of currentPoints. See protected member function computeAxisSums().
factor This argument specifies the size of the step.
Returns:
This function returns the objective function value at the evaluated point.

Definition at line 653 of file optimizerNelderMead.h.

References dlr::optimization::Optimizer< Functor >::m_functor.

template<class Functor>
std::pair< typename Functor::argument_type, typename Functor::result_type > dlr::optimization::OptimizerNelderMead< Functor >::run (  )  [inline, protected, virtual]

This protected member function performs the minimization.

Returns:
A std::pair of the vector parameter which brings the specified Functor to a minimum, and the corresponding Functor value.

Implements dlr::optimization::Optimizer< Functor >.

Definition at line 677 of file optimizerNelderMead.h.

References dlr::optimization::copyArgumentType(), DLR_THROW, dlr::optimization::OptimizerNelderMead< Functor >::doNelderMead(), dlr::optimization::OptimizerNelderMead< Functor >::m_delta, dlr::optimization::OptimizerNelderMead< Functor >::m_deltaValueHack, dlr::optimization::OptimizerNelderMead< Functor >::m_functionCallCount, dlr::optimization::Optimizer< Functor >::m_functor, dlr::optimization::OptimizerNelderMead< Functor >::m_numberOfRestarts, and dlr::optimization::OptimizerNelderMead< Functor >::m_theta0.

template<class Functor>
Functor dlr::optimization::Optimizer< Functor >::objectiveFunction (  )  [inline, inherited]

This method returns a copy of the Functor instance used for optimization.

Returns:
A Functor instance.

Definition at line 91 of file optimizer.h.

References dlr::optimization::Optimizer< Functor >::m_functor.

template<class Functor>
Optimizer< Functor >::result_type dlr::optimization::Optimizer< Functor >::optimalValue (  )  [inline, inherited]

This method finds the optimum of the current Functor, if necessary, and returns the Functor value at that point.

Note that you must have specified an objective function (Functor) before calling this method.

Returns:
The Functor value at it's optimum.

Definition at line 282 of file optimizer.h.

References dlr::optimization::Optimizer< Functor >::m_needsOptimization, dlr::optimization::Optimizer< Functor >::m_optimalValue, dlr::optimization::Optimizer< Functor >::run(), and dlr::optimization::Optimizer< Functor >::setOptimum().

template<class Functor>
Optimizer< Functor >::argument_type dlr::optimization::Optimizer< Functor >::optimum (  )  [inline, inherited]

This method finds the optimum of the current Functor, if necessary, and returns the Functor argument which produces that optimum.

Note that you must have specified an objective function (Functor) before calling this method.

Returns:
The Functor arguments which produce the optimal value.

Definition at line 297 of file optimizer.h.

References dlr::optimization::Optimizer< Functor >::m_needsOptimization, dlr::optimization::Optimizer< Functor >::m_optimum, dlr::optimization::Optimizer< Functor >::run(), and dlr::optimization::Optimizer< Functor >::setOptimum().

template<class Functor>
void dlr::optimization::Optimizer< Functor >::setObjectiveFunction ( const Functor &  functor  )  [inline, inherited]

This method specifies the Functor instance to use for the optimization.

If this function is overridden by the base class, it should normally either call Optimizer::setObjectiveFunction(), or explicitly set the member variable m_needsOptimization to true.

Parameters:
functor A copy of this argument will be stored internally for use in optimization.

Definition at line 311 of file optimizer.h.

References dlr::optimization::Optimizer< Functor >::m_functor, and dlr::optimization::Optimizer< Functor >::m_needsOptimization.

template<class Functor>
virtual void dlr::optimization::Optimizer< Functor >::setOptimum ( const typename Functor::argument_type &  optimum,
const typename Functor::result_type &  optimalValue,
bool  needsFurtherOptimization 
) [inline, protected, virtual, inherited]

This protected member function provides a way for subclasses to communicate intermediate optimization results outside of the normal "return value of this->run()" method.

Parameters:
optimum This argument will be saved as the current optimum.
optimalValue This argument will be saved as the function value a the current optimum.
needsFurtherOptimization This argument indicates whether or not further refinement is necessary.

Definition at line 172 of file optimizer.h.

References dlr::optimization::Optimizer< Functor >::m_needsOptimization, dlr::optimization::Optimizer< Functor >::m_optimalValue, and dlr::optimization::Optimizer< Functor >::m_optimum.

Referenced by dlr::optimization::Optimizer< Functor >::optimalValue(), and dlr::optimization::Optimizer< Functor >::optimum().


Member Data Documentation

template<class Functor>
Functor dlr::optimization::Optimizer< Functor >::m_functor [protected, inherited]

m_functor->operator()() should compute the objective function.

Definition at line 182 of file optimizer.h.

Referenced by dlr::optimization::OptimizerBFGS< Functor >::doBfgs(), dlr::optimization::OptimizerNelderMead< Functor >::evaluateMove(), dlr::optimization::Optimizer< Functor >::objectiveFunction(), dlr::optimization::Optimizer< Functor >::operator=(), dlr::optimization::OptimizerNelderMead< Functor >::run(), dlr::optimization::OptimizerLM< Functor >::run(), dlr::optimization::OptimizerLineSearch< Functor >::run(), dlr::optimization::OptimizerBFGS< Functor >::run(), dlr::optimization::Optimizer< Functor >::setObjectiveFunction(), and dlr::optimization::OptimizerLineSearch< Functor >::setStartPoint().

template<class Functor>
bool dlr::optimization::Optimizer< Functor >::m_needsOptimization [protected, inherited]

Set to false if m_optimum contains a valid optimum, true otherwise.

Definition at line 185 of file optimizer.h.

Referenced by dlr::optimization::Optimizer< Functor >::operator=(), dlr::optimization::Optimizer< Functor >::optimalValue(), dlr::optimization::Optimizer< Functor >::optimum(), dlr::optimization::OptimizerLineSearch< Functor >::setInitialStep(), dlr::optimization::Optimizer< Functor >::setObjectiveFunction(), dlr::optimization::Optimizer< Functor >::setOptimum(), dlr::optimization::OptimizerLineSearch< Functor >::setParameters(), and dlr::optimization::OptimizerLineSearch< Functor >::setStartPoint().

template<class Functor>
argument_type dlr::optimization::Optimizer< Functor >::m_optimum [protected, inherited]

Caches the result of the most recent optimization.

Definition at line 188 of file optimizer.h.

Referenced by dlr::optimization::Optimizer< Functor >::operator=(), dlr::optimization::Optimizer< Functor >::Optimizer(), dlr::optimization::Optimizer< Functor >::optimum(), and dlr::optimization::Optimizer< Functor >::setOptimum().

template<class Functor>
result_type dlr::optimization::Optimizer< Functor >::m_optimalValue [protected, inherited]

Caches the result of the most recent optimization.

Definition at line 191 of file optimizer.h.

Referenced by dlr::optimization::Optimizer< Functor >::optimalValue(), and dlr::optimization::Optimizer< Functor >::setOptimum().


The documentation for this class was generated from the following file:
Generated on Mon Jul 9 20:34:22 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2