Class anneal_mt (o2scl)¶
-
template<class func_t = multi_funct, class vec_t = boost::numeric::ublas::vector<double>, class rng_t = int, class rng_dist_t = rng>
class anneal_mt : public o2scl::anneal_base<multi_funct, boost::numeric::ublas::vector<double>, int, rng>¶ Multidimensional minimization by simulated annealing (Boost multi-threaded version)
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, wherenp
is the number of processors,np
copies of the function parameters of typeparam_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 thesenp
copies of the parameters of typeparam_t
isstd::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.
Todo
Future: In class anneal_mt, here may be a good way to remove the function indirection here to make this class a bit faster.
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)
-
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.
-
inline virtual const char *type()¶
Return string denoting type (“anneal_mt”)
-
inline int set_verbose_stream(std::ostream &out, std::istream &in)¶
Set streams for verbose I/O.
-
inline virtual int print_iter(size_t nv, vec_t &xx, double y, int iter, double tptr, std::string comment)¶
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. 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.
-
inline void func_wrapper(size_t ip)¶
The function wrapper executed by thread with index
ip
.
Storage for present, next, and best vectors
-
inline virtual int allocate(size_t nv, size_t np)¶
Allocate memory for a minimizer over
n
dimensions with stepsizestep
.
Basic usage
Iteration control
-
inline 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.
-
inline virtual int start(size_t nv, double &T)¶
Setup initial temperature and stepsize.
-
double boltz¶