Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
o2scl::diff_evo< func_t, vec_t, init_funct_t > Class Template Reference

Multidimensional minimization by the differential evolution method. More...

#include <diff_evo.h>

Inheritance diagram for o2scl::diff_evo< func_t, vec_t, init_funct_t >:
o2scl::mmin_base< func_t, func_t, vec_t > o2scl::diff_evo_adapt< func_t, vec_t, init_funct_t >

Public Types

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

Public Member Functions

virtual void set_init_function (init_funct_t &function)
 Set the function that is used to produce random init variables. More...
 
virtual int mmin (size_t nvar, vec_t &x0, double &fmin, func_t &func)
 Calculate the minimum fmin of func w.r.t the array x of size nvar. More...
 
virtual void print_iter (size_t nvar, double fmin, int iter, vec_t &best_fit)
 Print out iteration information. More...
 
- 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

size_t pop_size
 Population size (default 0) More...
 
size_t nconv
 The number of generations without a better fit before we assume that the algorithm has converged (default 25)
 
double f
 Differential weight (default 0.75) More...
 
double cr
 Crossover probability (default 0.8) 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

virtual int initialize_population (size_t nvar, vec_t &x0)
 Initialize a population of random agents.
 
virtual std::vector< int > pick_unique_agents (int nr, size_t x)
 Pick number of unique agent id's. More...
 

Protected Attributes

vec_t population
 Vector containing the population. More...
 
ubvector fmins
 Vector that keeps track of fmins values.
 
init_funct_t * rand_init_funct
 Function that is used to produce random init variables. More...
 
rng_gsl gr
 Random number generator.
 
- 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

 diff_evo (const diff_evo< func_t, vec_t, init_funct_t > &)
 
diff_evo< func_t, vec_t, init_funct_t > & operator= (const diff_evo< func_t, vec_t, init_funct_t > &)
 

Detailed Description

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
class o2scl::diff_evo< func_t, vec_t, init_funct_t >

This class minimizes a function using differential evolution. This method is a genetic algorithm and as such works well for non continuous problems, since it does not rely on a gradient of the function that is being mind.

The method starts by initializing a random population of candidate parameters. To do this the user needs to define a function to create these random parameters, which can be provided using set_init_function().

After the initial population is created the algorithm will repeat a number of standard steps until a solution is found or the maximum number of iterations is reached. Based on Storn97.

Note
The constructor sets o2scl::mmin_base::ntrial to 1000 .

If the population converges prematurely, then diff_evo::f and pop_size should be increased.

Definition at line 66 of file diff_evo.h.

Member Function Documentation

◆ mmin()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
virtual int o2scl::diff_evo< func_t, vec_t, init_funct_t >::mmin ( size_t  nvar,
vec_t &  x0,
double &  fmin,
func_t &  func 
)
inlinevirtual

Initialize all agents x with random positions in the search-space. Until a termination criterion is met (e.g. number of iterations performed, or adequate fitness reached), repeat the following: For each agent x in the population do: Pick three agents a, b, and c from the population at random, they must be distinct from each other as well as from agent x Pick a random index {1, ..., n}, where the highest possible value n is the dimensionality of the problem to be optimized. Compute the agent's potentially new position y = [y1, ..., yn] by iterating over each i {1, ..., n} as follows: Pick ri~U(0,1) uniformly from the open range (0,1) If (i=R) or (ri<CR) let yi = ai + F(bi - ci), otherwise let yi = xi If (f(y) < f(x)) then replace the agent in the population with the improved candidate solution, that is, set x = y in the population.

Pick the agent from the population that has the lowest fmin and return it as the best found candidate solution.

Implements o2scl::mmin_base< func_t, func_t, vec_t >.

Reimplemented in o2scl::diff_evo_adapt< func_t, vec_t, init_funct_t >.

Definition at line 151 of file diff_evo.h.

◆ pick_unique_agents()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
virtual std::vector<int> o2scl::diff_evo< func_t, vec_t, init_funct_t >::pick_unique_agents ( int  nr,
size_t  x 
)
inlineprotectedvirtual

Unique from x and each other

Uses the Fisher-Yates algorithm.

Definition at line 343 of file diff_evo.h.

◆ print_iter()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
virtual void o2scl::diff_evo< func_t, vec_t, init_funct_t >::print_iter ( size_t  nvar,
double  fmin,
int  iter,
vec_t &  best_fit 
)
inlinevirtual

Reimplemented in o2scl::diff_evo_adapt< func_t, vec_t, init_funct_t >.

Definition at line 275 of file diff_evo.h.

◆ set_init_function()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
virtual void o2scl::diff_evo< func_t, vec_t, init_funct_t >::set_init_function ( init_funct_t &  function)
inlinevirtual

REQUIRED

The init function is called in the beginning to fill the population with random individuals, so it is best to make this cover the part of the parameter space you are interested in. The method will find solutions outside this parameter space, but choosing a good init function will help finding solutions faster.

Definition at line 125 of file diff_evo.h.

Member Data Documentation

◆ cr

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
double o2scl::diff_evo< func_t, vec_t, init_funct_t >::cr

Usually between 0 and 1.

Definition at line 99 of file diff_evo.h.

◆ f

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
double o2scl::diff_evo< func_t, vec_t, init_funct_t >::f

A parameter which controls the amplification of the differential variation. Usually between 0 and 2.

Definition at line 93 of file diff_evo.h.

◆ pop_size

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
size_t o2scl::diff_evo< func_t, vec_t, init_funct_t >::pop_size

Should be at least 4. Typically between $ 5 d $ and $ 10 d $ where $ d $ is the dimensionality of the problem.

If this is 0 (the default), then it is set by mmin to be equal to $ 10 d $ .

Definition at line 81 of file diff_evo.h.

◆ population

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
vec_t o2scl::diff_evo< func_t, vec_t, init_funct_t >::population
protected

For now using one long vector with all agents after each other

Definition at line 302 of file diff_evo.h.

◆ rand_init_funct

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class init_funct_t = mm_funct11>
init_funct_t* o2scl::diff_evo< func_t, vec_t, init_funct_t >::rand_init_funct
protected

This function is used to fill the population with random agents

Definition at line 311 of file diff_evo.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).