Class anneal_gsl (o2scl)¶
-
template<class func_t = multi_funct, class vec_t = boost::numeric::ublas::vector<double>, class rng_t = o2scl::rng<>>
class anneal_gsl : public o2scl::anneal_base<multi_funct, boost::numeric::ublas::vector<double>, o2scl::rng<>>¶ Multidimensional minimization by simulated annealing (GSL)
This class is a modification of simulated annealing as implemented in GSL in the function
gsl_siman_solve()
. It acts as a generic multidimensional minimizer for any function given a generic temperature schedule specified by the user.There are a large variety of strategies for choosing the temperature evolution. To offer the user the largest possible flexibility, the temperature evolution is controlled by a the virtual functions start() and next() which can be freely changed by creating a child class which overwrites these functions.
The simulated annealing algorithm proposes a displacement of one coordinate of the previous point by
\[ x_{i,\mathrm{new}} = \mathrm{step\_size}_i (2 u_i - 1) + x_{i,\mathrm{old}} \]where the \(u_i\) are random numbers between 0 and 1. The displacement is accepted or rejected based on the Metropolis method. The random number generator is set in the parent, anneal.The default behavior is as follows: Initially, the step sizes are chosen to be 1.0 (or whatever was recently specified in set_step() ) and the temperature to be T_start (default 1.0). Each iteration decreases the temperature by a factor of T_dec (default 1.5) for each step, and the minimizer is finished when the next decrease would bring the temperature below o2scl::mmin_base::tol_abs. If none of the mmin_base::ntrial steps in a particular iteration changes the value of the minimum, and the step sizes are greater than min_step_ratio (default 100) times o2scl::mmin_base::tol_abs, then the step sizes are decreased by a factor of step_dec (default 1.5) for the next iteration.
If o2scl::mmin_base::verbose is greater than zero, then mmin() will print out information and/or request a keypress after the function iterations for each temperature.
An example demonstrating the usage of this class is given in
examples/ex_anneal.cpp
and in the Simulated annealing example.- Idea for Future:
Implement a more general simulated annealing routine which would allow the solution of discrete problems like the Traveling Salesman problem.
Subclassed by o2scl::anneal_para< func_t, vec_t >
Storage for points in parameter space
-
double step_norm¶
Normalization for step.
-
inline virtual int next(size_t nvar, vec_t &x_old, double min_old, vec_t &x_new, double min_new, double &T, size_t n_moves, vec_t &best_x, double best_E, bool &finished)¶
Determine how to change the minimization for the next iteration.
-
inline virtual int start(size_t nvar, double &T)¶
Setup initial temperature and stepsize.
Public Types
-
typedef boost::numeric::ublas::vector<double> ubvector¶
Public Functions
-
inline anneal_gsl()¶
-
inline virtual ~anneal_gsl()¶
-
inline virtual int mmin(size_t nvar, vec_t &x0, double &fmin, func_t &func)¶
Calculate the minimum
fmin
offunc
w.r.t the arrayx0
of sizenvar
.
-
inline virtual const char *type()¶
Return string denoting type (“anneal_gsl”)
-
inline anneal_gsl(const anneal_gsl<func_t, vec_t, rng_t> &ag)¶
Copy constructor.
-
inline anneal_gsl<func_t, vec_t, rng_t> &operator=(const anneal_gsl<func_t, vec_t, rng_t> &ag)¶
Copy constructor from operator=.