#include <GeneralFunctionMinimizer.h>
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 ¶m) 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 ¶m, 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. |
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...) ///
/// FunctionMinimizer<MyFunction> fmini(4, f, seed_p, 1.0e-8); ///
/// minimise_conjugated_gradient(fmini, 5); ///
/// const double* par_ptr = fmini.getPar(); ///
Definition at line 111 of file GeneralFunctionMinimizer.h.