Go::FunctionMinimizer< Functor > Class Template Reference
['utils' - a collection of useful math and programming tools]

This is the FunctionMinimizer class that can be used ex. More...

#include <GeneralFunctionMinimizer.h>

List of all members.

Public Member Functions

 FunctionMinimizer (int num_param, const Functor &fun, const double *const seed, double tol=std::sqrt(std::numeric_limits< double >::epsilon()))
 Constructor.
 ~FunctionMinimizer ()
double minimize (const Point &dir, bool &hit_domain_edge)
 Move the current parameter point in order to minimize the function along an unoriented line.
double linminBrent (const Point &dir, const double *bracket, const double *fval_brak)
 Move the current parameter point in order to minimize the function along a ray.
double fval () const
 evaluating distance function at the current point of evaluation
double fval (const Point &param) const
 evaluating the distance function for an arbitrary parameter value (not the parameter pair).
void grad (Point &result) const
 evaluate the gradient (2 components) of the distance function at the currently set parameter pair of evaluation.
void grad (const Point &param, Point &result) const
 evaluate the gradient (2 components) of the distance function for an arbitrary parameter value (not the current parameter pair).
void moveUV (const Point &dir, double multiplier)
 movie the current parameter pair a certain distance ('multiplier') in a certain direction ('dir', which has 2 components)
bool atMin (int param_ix) const
 Returns 'true' if the current parameter for the first/second curve is equal to the start/end-parameter for the curve.
bool atMax (int param_ix) const
double getPar (int param_ix) const
 Get the current value for parameter nb. 'param_ix'.
const double * getPar () const
 Get a pointer to the array containing the current values of the parameters.
int numPars () const
 Get the number of function parameters.


Detailed Description

template<class Functor>
class Go::FunctionMinimizer< Functor >

This is the FunctionMinimizer class that can be used ex.

with minimise_conjugated_gradient. Together, they provide functionality for minimizing a function with an arbitrary number of parameters, using linear minimization along a set of directions which is chosen by the conjugated gradient algorithm, although the FunctionMinimizer can also be used independently for minimizing a function along any user-defined direction. The function to minimize must be presented in the form of a Functor, which has the following member functions:

/// double operator()(const double* arg) const; // to evaluate the function at the parameters
///                                             // pointed to by 'arg'.
/// void grad(const double* arg, double* grad) const; // to evaluate the function
///                                                   // gradient at the parameters
///                                                   // pointed to by 'arg'.  The resulting
///                                                   // vector will be written to 'grad'.
/// double minPar(int n) const; // return the lower bound of the n'th function parameter.
/// double maxPar(int n) const; // return the upper bound of the n'th function parameter.
/// 

Minimizing a function whose domain is R^n is a two-fold problem. One is of linear minimization along a specified direction. Another is to choose a set of directions to minimize along. The first problem is taken care of by the class FunctionMinimizer, which wraps around the user-defined function and contains information about the current point of evaluation and minimizing along a given direction. The second problem can be taken care of by the supplied function 'minimise_conjugated_gradient', or the user can use FunctionMinimizer in combination with his or her own direction-choosing algorithm.

The user first should wrap his or hers Functor into a FunctionMinimizer, where the starting seed and tolerances should also be specified. The FunctionMinimizer can be used separately to minimize along directions that the user specify (using the 'minimize' member function), or alternatively can be given to the supplied nonmember function 'minimise_conjugated_gradient', which will try to find a local minimum starting from the supplied seed.

Example: Let us assume that the user has a function taking four arguments. He defines the functor MyFunction containing the required member functions, and instanciates it:

/// MyFunction f(...constructor arguments...)
/// 
He now wraps it in a FunctionMinimizer, giving the seed where he wants to start the search:
/// FunctionMinimizer<MyFunction> fmini(4, f, seed_p, 1.0e-8);
/// 
This function minimizer can now be used with the 'minimise_conjugated_gradient'-algorithm in order to search for a (local) minimum:
/// minimise_conjugated_gradient(fmini, 5);
/// 
The obtained 4-tuple of parameters corresponding to the found minimum can be obtained by:
/// const double* par_ptr = fmini.getPar();
/// 

Definition at line 111 of file GeneralFunctionMinimizer.h.


The documentation for this class was generated from the following files:
Generated on Mon Jun 11 14:48:18 2007 for GoTools Core Library by  doxygen 1.5.1