Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
o2scl::anneal_mt< func_t, vec_t, rng_t, rng_dist_t > Class Template Reference

Multidimensional minimization by simulated annealing (Boost multi-threaded version) More...

#include <anneal_mt.h>

Inheritance diagram for o2scl::anneal_mt< func_t, vec_t, rng_t, rng_dist_t >:
o2scl::anneal_base< func_t, vec_t, rng_t, rng_dist_t > o2scl::mmin_base< func_t, func_t, vec_t >

Public Member Functions

virtual int mmin (size_t nv, vec_t &x0, double &fmin, func_t &func)
 Desc.
 
virtual const char * type ()
 Return string denoting type ("anneal_mt")
 
int set_verbose_stream (std::ostream &out, std::istream &in)
 Set streams for verbose I/O.
 
virtual int print_iter (size_t nv, vec_t &xx, double y, int iter, double tptr, std::string comment)
 Print out iteration information. More...
 
template<class vec2_t >
int set_step (size_t nv, vec2_t &stepv)
 Set the step sizes.
 
Basic usage
virtual int mmin (size_t nv, vec_t &x0, double &fmin, func_t &func, size_t np)
 Calculate the minimum fmin of func w.r.t the array x0 of size nv using np threads.
 
Iteration control
virtual int next (size_t nv, vec_t &x_old, double min_old, vec_t &x_new, double min_new, double &T, size_t n_moves, bool &finished)
 Determine how to change the minimization for the next iteration.
 
virtual int start (size_t nv, double &T)
 Setup initial temperature and stepsize.
 
- Public Member Functions inherited from o2scl::anneal_base< func_t, vec_t, rng_t, rng_dist_t >
 anneal_base (const anneal_base< func_t, vec_t, rng_t > &ab)
 Copy constructor.
 
anneal_base< func_t, vec_t, rng_t > & operator= (const anneal_base< func_t, vec_t, rng_t > &ab)
 Copy constructor from operator=.
 
- 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

rng_t def_rng
 The default random number generator.
 
Parameters
double boltz
 Boltzmann factor (default 1.0).
 
int ntrial
 Number of iterations.
 
int verbose
 Output control.
 
bool out_step_changes
 Output step size changes (default false)
 
bool out_best
 Output best point (default false)
 
double tolx
 The independent variable tolerance (default $ 10^{-6} $ )
 
double T_start
 Initial temperature (default 1.0)
 
double T_dec
 Factor to decrease temperature by (default 1.5)
 
double step_dec
 Factor to decrease step size by (default 1.5)
 
double min_step_ratio
 Ratio between minimum step size and tolx (default 100.0)
 
- Public Attributes inherited from o2scl::anneal_base< func_t, vec_t, rng_t, rng_dist_t >
rng_t rng
 The default random number generator.
 
o2scl::prob_dens_uniform dist
 The random distribution object.
 
- 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

void func_wrapper (size_t ip)
 The function wrapper executed by thread with index ip.
 
virtual int allocate (size_t nv, size_t np)
 Allocate memory for a minimizer over n dimensions with stepsize step.
 
virtual int step (size_t nv, vec_t &sx)
 Make a step to a new attempted minimum.
 

Protected Attributes

std::ostream * outs
 Stream for verbose output.
 
std::istream * ins
 Stream for verbose input.
 
size_t nproc
 The number of threads to run.
 
size_t nvar
 The number of variables over which we minimize.
 
func_t * f
 The function to minimize.
 
vec_t step_vec
 Vector of step sizes.
 
Storage for present, next, and best vectors
vec_t x
 
vec_t best_x
 
vec_t new_E
 
vec_t old_x
 
std::vector< vec_t > new_x
 
- 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.
 

Detailed Description

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class rng_t = int, class rng_dist_t = rng_gsl>
class o2scl::anneal_mt< func_t, vec_t, rng_t, rng_dist_t >

This header-only class additionally requires the Boost libraries. It performs simulated annealing using an arbitrary number of processors using boost::thread, which is closely related to the standard Unix pthread library. It works very similarly to anneal_gsl, it performs ntrial evaluations over each processor, then applying the metropolis algorithm to the results from all of the processors at the end.

Because np function calls are happening simultaneously, where np is the number of processors, np copies of the function parameters of type param_t must also be specified. The user-defined function to minimize must also be thread-safe, allowing multiple threads to call the function at once (albeit given different parameters). The default type for these np copies of the parameters of type param_t is std::vector<param_t>.

This works particularly well for functions which are not trivial to evaluate, i.e. functions where the execution time is more longer than the bookkeeping that anneal_mt performs between trials. For functions which satisfy this requirement, this algorithm scales nearly linearly with the number of processors.

Verbose I/O for this class happens only outside the theads unless the user places I/O in the streams in the function that is specified.

Idea for Future:
There may be a good way to remove the function indirection here to make this class a bit faster.

Definition at line 76 of file anneal_mt.h.

Member Function Documentation

◆ print_iter()

template<class func_t = multi_funct11, class vec_t = boost::numeric::ublas::vector<double>, class rng_t = int, class rng_dist_t = rng_gsl>
virtual int o2scl::anneal_mt< func_t, vec_t, rng_t, rng_dist_t >::print_iter ( size_t  nv,
vec_t &  xx,
double  y,
int  iter,
double  tptr,
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. If verbose>0, then after each iteration, the present values of x and y are output to std::cout along with the iteration number. Also, if verbose>0, every time a new smallest function value is found, the location and the function value is output. If verbose>=2 then each iteration waits for a character between each trial.

Reimplemented from o2scl::anneal_base< func_t, vec_t, rng_t, rng_dist_t >.

Definition at line 312 of file anneal_mt.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).