o2scl::mmin_simp2< func_t, vec_t > Class Template Reference

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

#include <mmin_simp2.h>

Inheritance diagram for o2scl::mmin_simp2< func_t, vec_t >:

## Public Types

typedef boost::numeric::ublas::vector< double > ubvector

## 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, 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, 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, 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 set (func_t &ufunc, 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, 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, vec_t *simp, double y, int iter, double value, double limit, std::string comment)
Print out iteration information. More...

virtual const char * type ()
Return string denoting type("mmin_simp2")

Public Member Functions inherited from o2scl::mmin_base< func_t, func_t, vec_t >
mmin_base (const mmin_base< func_t, func_t, vec_t > &mb)
Copy constructor.

int set_verbose_stream (std::ostream &out, std::istream &in)
Set streams for verbose I/O. More...

virtual int mmin_de (size_t nvar, vec_t &x, double &fmin, func_t &func, func_t &dfunc)
Calculate the minimum min of func w.r.t. the array x of size nvar with gradient dfunc.

int print_iter (size_t nv, vec2_t &x, double y, int iter, double value, double limit, std::string comment)
Print out iteration information. More...

const char * type ()
Return string denoting type ("mmin_base")

mmin_base< func_t, func_t, vec_t > & operator= (const mmin_base< func_t, func_t, vec_t > &mb)
Copy constructor from operator=.

## Public Attributes

double size
Size of current simplex computed by iterate()

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) More...

Public Attributes inherited from o2scl::mmin_base< func_t, func_t, vec_t >
int verbose
Output control.

int ntrial
Maximum number of iterations.

double tol_rel
Function value tolerance.

double tol_abs
The independent variable tolerance.

int last_ntrial
The number of iterations for in the most recent minimization.

bool err_nonconv
If true, call the error handler if the routine does not "converge".

## Protected Member Functions

int compute_center ()
Compute the center of the simplex.

double compute_size ()
Compute the size of the simplex. More...

virtual int try_corner_move (const double coeff, size_t corner, vec_t &xc, func_t &f, size_t nvar, double &newval)
Move a corner of a simplex. More...

virtual int update_point (size_t i, vec_t &xx, double val)
Update point i in the simplex with values xx.

virtual int contract_by_best (size_t best, func_t &f, size_t nvar)
Contract the simplex towards the best point. More...

## Protected Attributes

vec_t * x1
An array of n+1 vectors containing the simplex.

ubvector y1
The n+1 function values at the simplex points. More...

vec_t ws1
Workspace vector 1.

vec_t ws2
Workspace vector 2.

vec_t ws3
Workspace vector 3.

vec_t center
Center of simplex.

vec_t delta
Desc.

vec_t xmc
Distance of vector from center.

double S2
Squared simplex size.

size_t dim
Number of variables to be mind over.

func_t * func
Function.

bool set_called
True if set() has been called.

ubvector step_vec
Vector of step sizes.

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

Protected Attributes inherited from o2scl::mmin_base< func_t, func_t, vec_t >
std::ostream * outs
Stream for verbose output.

std::istream * ins
Stream for verbose input.

## Private Member Functions

mmin_simp2 (const mmin_simp2< func_t, vec_t > &)

mmin_simp2< func_t, vec_t > & operator= (const mmin_simp2< func_t, vec_t > &)

## Detailed Description

### template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>> class o2scl::mmin_simp2< func_t, vec_t >

This class mins a function using Nelder and Mead's Simplex algorithm. A simplex in a N-dimensional space is defined 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.

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 and a step size vector for . The simplex with and is chosen with and

for . The step size vector is set by the set_step() member function. The prsence of 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.

Note
It is important that the initial simplex contains sufficient variation in every direction of the parameter space over which one is minimizing. For example, if all three points in a simplex for minimizing over a two-dimensional space contain nearly the same value for the second parameter, then the minimizer may only minimize the function with respect to the first parameter.
The algorithm used to estimate the simplex size does not work well any of the parameters in the minimization problem has a scale which is not close to 1.

See an example for the usage of this class in Multidimensional minimizer example .

Default template arguments

Based on Nelder65 .

A variable count originally defined in the GSL simplex state is not present here, because it was unused.

Idea for Future:
Double check that the updates in gsl-1.13 are included here, and also add support for the nmsimplex2rand algorithm in GSL.

Definition at line 123 of file mmin_simp2.h.

## ◆ compute_size()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 double o2scl::mmin_simp2< func_t, vec_t >::compute_size ( )
inlineprotected

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

Definition at line 183 of file mmin_simp2.h.

## ◆ contract_by_best()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 virtual int o2scl::mmin_simp2< func_t, vec_t >::contract_by_best ( size_t best, func_t & f, size_t nvar )
inlineprotectedvirtual

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

Definition at line 280 of file mmin_simp2.h.

## ◆ print_iter()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 virtual int o2scl::mmin_simp2< func_t, vec_t >::print_iter ( size_t nv, vec_t & xx, vec_t * simp, double y, int iter, double value, double limit, std::string comment )
inlinevirtual

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 798 of file mmin_simp2.h.

## ◆ try_corner_move()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 virtual int o2scl::mmin_simp2< func_t, vec_t >::try_corner_move ( const double coeff, size_t corner, vec_t & xc, func_t & f, size_t nvar, double & newval )
inlineprotectedvirtual

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 207 of file mmin_simp2.h.

## ◆ avoid_nonzero

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 bool o2scl::mmin_simp2< func_t, vec_t >::avoid_nonzero
protected
Note
This option doesn't work yet, so I've made the variable protected to prevent the casual user from changing it.

Definition at line 362 of file mmin_simp2.h.

## ◆ print_simplex

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 int o2scl::mmin_simp2< func_t, vec_t >::print_simplex

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 405 of file mmin_simp2.h.

## ◆ y1

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>>
 ubvector o2scl::mmin_simp2< func_t, vec_t >::y1
protected

Definition at line 143 of file mmin_simp2.h.

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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).