NUMERICAL RECIPES
Webnote No. 15, Rev. 1
Code for Minimization with Simulated
Annealing
You should compare the following routine, Amebsa, with its counterpart Amoeba
in 10.5. Note that the argument iter is used in a somewhat different manner. Just
like Amoeba, this routine also has three different user interfaces. The simplest re-
quires you to specify the starting simplex as in equation (10.5.1):
VecDoub point = ...; Doub del = ...;
Amebsa<Doub(VecDoub_I &)> amebsa(point,del,funk,ftol);
Int iter = ...; Doub temperature = ...;
Bool converged=amebsa.anneal(iter,temptr);
In practice you loop over calls to anneal with an annealing schedule that resets
temperature and possibly iter on each call. You test converged to see whether
the convergence criterion has been met. The final minimum point is available in
amebsa.pb and the value at the minimum in amebsa.yb.
The second interface allows you to specify the starting simplex with a vector of
increments
i
:
VecDoub dels = ...;
Amebsa<Doub(VecDoub_I &)> amebsa(point,dels,funk,ftol);
The most general interface lets you specify the simplex as an .N C 1/ N matrix
whose rows are the coordinates of each vertex:
MatDoub p = ...;
Amebsa<Doub(VecDoub_I &)> amebsa(p,funk,ftol);
Here is the routine:
template <class T> amebsa.h
struct Amebsa {
Multidimensional minimization by simulated annealing combined with the downhill simplex
method of Nelder and Mead.
T &funk;
const Doub ftol;
Ranq1 ran;
Doub yb;
Function value at the minimum.
Int ndim;
VecDoub pb;
Minimum point.
Int mpts;
VecDoub y;
Function values at the vertices of the simplex.
MatDoub p; Current simplex.
Doub tt; Communicates annealing temperature to amotsa.
Amebsa(VecDoub_I &point, const Doub del, T &funkk, const Doub ftoll) :
funk(funkk), ftol(ftoll), ran(1234),
yb(numeric_limits<Doub>::max()), ndim(point.size()), pb(ndim),
mpts(ndim+1), y(mpts), p(mpts,ndim)
1
Copyright 2007 Numerical Recipes Software
- 1
- 2
前往页