All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
o2scl::anneal_mt< param_t, param_vec_t, func_t, vec_t, alloc_vec_t, alloc_t, rng_t > Class Template Reference

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

Detailed Description

template<class param_t, class param_vec_t = std::vector<param_t>, class func_t = multi_funct<param_t>, class vec_t = ubvector, class alloc_vec_t = ubvector, class alloc_t = ubvector_alloc, class rng_t = rng_gsl>
class o2scl::anneal_mt< param_t, param_vec_t, func_t, vec_t, alloc_vec_t, alloc_t, rng_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 74 of file anneal_mt.h.

#include <anneal_mt.h>

Public Member Functions

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, param_vec_t &pars)
 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.
 

Data Fields

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)
 

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 free (size_t np)
 Free allocated memory.
 
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.
 
param_vec_t * params
 The user-specified parameters.
 
size_t nvar
 The number of variables over which we minimize.
 
func_t * f
 The function to minimize.
 
alloc_t ao
 Allocation object.
 
ubvector step_vec
 Vector of step sizes.
 
Storage for present, next, and best vectors
alloc_vec_t x
 
alloc_vec_t * new_x
 
alloc_vec_t best_x
 
alloc_vec_t new_E
 
alloc_vec_t old_x
 

Member Function Documentation

template<class param_t , class param_vec_t = std::vector<param_t>, class func_t = multi_funct<param_t>, class vec_t = ubvector, class alloc_vec_t = ubvector, class alloc_t = ubvector_alloc, class rng_t = rng_gsl>
virtual int o2scl::anneal_mt< param_t, param_vec_t, func_t, vec_t, alloc_vec_t, alloc_t, rng_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.

Definition at line 303 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).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..