gsl_mmin_simp Class Template Reference

Multidimensional minimization by the Simplex method (GSL). More...

#include <gsl_mmin_simp.h>

Inheritance diagram for gsl_mmin_simp:

multi_min

Detailed Description

template<class param_t, class func_t = multi_funct<param_t>, class vec_t = ovector_base, class alloc_vec_t = ovector, class alloc_t = ovector_alloc>
class gsl_mmin_simp< param_t, func_t, vec_t, alloc_vec_t, alloc_t >

Multidimensional minimization by the Simplex method (GSL).

This class minimizes a function using Nelder and Mead's Simplex algorithm. A simplex in a N-dimensional space is definted as a set of N+1 points which describe an N-dimensional volume surrounding the minimum. The algorithm proceeds by shifting the simplex points until the simplex is sufficiently small and thus the minimum is known with sufficient accuracy.

For a slightly improved method, see gsl_mmin_simp2 .

This class has a high-level interface using mmin(), mmin_twovec() or mmin_simplex() which automatically performs the memory allocation and minimization, or a GSL-like interface using allocate(), free(), interate() and set() or set_simplex().

The simplex can be completely specified by the user (see mmin_simplex() and set_simplex()). Alternatively, the simplex is automatically specified given initial guess $ x_j $ and a step size vector $ s_k $ for $ 0\leq k<n_s $. The simplex $ p_{ij} $ with $ 0\leq i\leq n $ and $ 0\leq j<n $ is chosen with $ p_{0j} = x_j $ and

\begin{eqnarray*} p_{i+1,j} &=& x_j\quad\mathrm{for}\quad i\neq j \\ p_{i+1,j} &=& x_j+s_{j~\mathrm{mod}~n_s}\quad\mathrm{for}\quad i=j \end{eqnarray*}

for $ 0<i<n $. The step size vector $ s $ is set by the set_step() member function. The prsence of $ \mathrm{mod} $ in the recipe above just indicates that elements of the step size vector are automatically re-used if there are less step sizes than dimensions in the minimization problem.

Based on Nelder65 .

Definition at line 93 of file gsl_mmin_simp.h.


Public Member Functions

template<class vec2_t >
int set_step (size_t nv, vec2_t &step)
 Set the step sizes for each independent variable.
virtual int mmin (size_t nn, vec_t &xx, double &fmin, param_t &pa, func_t &ufunc)
 Calculate the minimum min of func w.r.t the array x of size nvar.
virtual int mmin_twovec (size_t nn, vec_t &xx, vec_t &xx2, double &fmin, param_t &pa, func_t &ufunc)
 Calculate the minimum min of func w.r.t the array x of size nvar, using xx and xx2 to specify the simplex.
template<class mat_t >
int mmin_simplex (size_t nn, mat_t &sx, double &fmin, param_t &pa, func_t &ufunc)
 Calculate the minimum min of func w.r.t the array x of size nvar, given an initial simplex.
virtual int allocate (size_t n)
 Allocate the memory.
virtual int free ()
 Free the allocated memory.
virtual int set (func_t &ufunc, param_t &pa, size_t n, vec_t &ax, vec_t &step_size)
 Set the function and initial guess.
template<class mat_t >
int set_simplex (func_t &ufunc, param_t &pa, mat_t &sx)
 Set the function and initial simplex.
virtual int iterate ()
 Perform an iteration.
virtual int print_iter (size_t nv, vec_t &xx, alloc_vec_t *simp, double y, int iter, double value, double limit, std::string comment)
 Print out iteration information.
virtual const char * type ()
 Return string denoting type("gsl_mmin_simp").

Data Fields

double size
 Size of current simplex computed by iterate().
alloc_vec_t x
 Present minimum vector computed by iterate().
double fval
 Function value at minimum computed by iterate().
int print_simplex
 Print simplex information in print_iter() (default 0).

Protected Member Functions

int nmsimplex_calc_center (vec_t &mp)
 Compute the center of the simplex and store in mp.
double nmsimplex_size ()
 Compute the size of the simplex.
virtual int move_corner_err (const double coeff, size_t corner, vec_t &xc, func_t &f, size_t nvar, param_t &pa, double &newval)
 Move a corner of a simplex.
virtual int contract_by_best (size_t best, vec_t &xc, func_t &f, size_t nvar, param_t &pa)
 Contract the simplex towards the best point.

Protected Attributes

alloc_vec_t * x1
 An array of n+1 vectors containing the simplex.
ovector y1
 The n+1 function values at the simplex points.
alloc_vec_t ws1
 Workspace vector 1.
alloc_vec_t ws2
 Workspace vector 2.
alloc_vec_t ws3
 Workspace vector 3.
size_t dim
 Number of variables to be minimized over.
func_t * func
 Function.
param_t * params
 Parameters.
bool set_called
 True if set() has been called.
ovector step_vec
 Vector of step sizes.
alloc_t ao
 Vector allocator.
bool avoid_nonzero
 If true, try to automatically avoid regions where the function returns a non-zero value (default false).

Member Function Documentation

virtual int contract_by_best ( size_t  best,
vec_t &  xc,
func_t &  f,
size_t  nvar,
param_t &  pa 
) [inline, protected, virtual]

Contract the simplex towards the best point.

Function contracts the simplex in respect to best valued corner. All corners besides the best corner are moved.

The vector, xc, is used as work space.

Definition at line 201 of file gsl_mmin_simp.h.

virtual int move_corner_err ( const double  coeff,
size_t  corner,
vec_t &  xc,
func_t &  f,
size_t  nvar,
param_t &  pa,
double &  newval 
) [inline, protected, virtual]

Move a corner of a simplex.

Moves a simplex corner scaled by coeff (negative value represents mirroring by the middle point of the "other" corner points) and gives new corner in xc and function value at xc in newval.

Definition at line 172 of file gsl_mmin_simp.h.

double nmsimplex_size (  )  [inline, protected]

Compute the size of the simplex.

Calculates simplex size as average sum of length of vectors from simplex center to corner points:

$ (1/n) \sum || y - y_{\mathrm{middlepoint}} || $

Definition at line 150 of file gsl_mmin_simp.h.

virtual int print_iter ( size_t  nv,
vec_t &  xx,
alloc_vec_t *  simp,
double  y,
int  iter,
double  value,
double  limit,
std::string  comment 
) [inline, virtual]

Print out iteration information.

Depending on the value of the variable verbose, this prints out the iteration information. If verbose=0, then no information is printed, while if verbose>1, then after each iteration, the present values of x and y are output to std::cout along with the iteration number. If verbose>=2 then each iteration waits for a character.

Definition at line 756 of file gsl_mmin_simp.h.


Field Documentation

bool avoid_nonzero [protected]

If true, try to automatically avoid regions where the function returns a non-zero value (default false).

Note:
This option doesn't work yet, so I've made the variable protected to prevent the user from changing it.

Definition at line 279 of file gsl_mmin_simp.h.

Print simplex information in print_iter() (default 0).

If this is 1 and verbose is greater than 0, then print_iter() will print the function values at all the simplex points. If this is 2 and verbose is greater than 0, then print_iter() will print the simplex coordinates in addition to the function values.

Definition at line 326 of file gsl_mmin_simp.h.


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

Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page