Class anneal_mt (o2scl)

O2scl : Class List

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, 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.

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)

double min_step_ratio

Ratio between minimum step size and tolx (default 100.0)

rng_t def_rng

The default random number generator.

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.

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.

template<class vec2_t>
inline int set_step(size_t nv, vec2_t &stepv)

Set the step sizes.

inline void func_wrapper(size_t ip)

The function wrapper executed by thread with index ip.

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
vec_t step_vec

Vector of step sizes.

inline virtual int allocate(size_t nv, size_t np)

Allocate memory for a minimizer over n dimensions with stepsize step.

inline virtual int step(size_t nv, vec_t &sx)

Make a step to a new attempted minimum.

Basic usage

inline 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.

inline virtual int mmin(size_t nv, vec_t &x0, double &fmin, func_t &func)

Desc.

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.

Public Functions

inline anneal_mt()
inline virtual ~anneal_mt()