15#include "gsl/gsl_siman.h"
35 fX( std::vector<double>(
x,
x + func.NDim() ) ),
36 fScale( std::vector<double>(func.NDim() )),
44 fX( std::vector<double>(
x,
x + func.NDim() ) ),
45 fScale( std::vector<double>(scale, scale + func.NDim() ) ),
57 unsigned int ndim =
NDim();
58 for (
unsigned int i = 0; i < ndim; ++i) {
59 double urndm = random();
60 double sstep = maxstep *
fScale[i];
61 fX[i] += 2 * sstep * urndm - sstep;
68 const std::vector<double> &
x =
fX;
69 const std::vector<double> &
y =
f.X();
70 unsigned int n =
x.size();
71 assert (
n ==
y.size());
74 for (
unsigned int i = 0; i <
n; ++i)
75 d2 += (
x[i] -
y[i] ) * (
x[i] -
y[i] );
80 return std::abs(
x[0] -
y[0] );
86 std::cout <<
"\tx = ( ";
88 for (
unsigned int i = 0; i <
n-1; ++i) {
89 std::cout <<
fX[i] <<
" , ";
91 std::cout <<
fX.back() <<
" )\t";
93 std::cout <<
"E / E_best = ";
99 std::copy(rhs.
fX.begin(), rhs.
fX.end(),
fX.begin() );
110 double E(
void * xp) {
117 void Step(
const gsl_rng *
r,
void * xp,
double step_size) {
126 fx->
Step(random, step_size);
129 double Dist(
void * xp,
void * yp) {
160 return static_cast<void *
> ( fx->
Clone() );
190 int iret =
Solve(fx, debug);
194 std::copy(fx.
X().begin(), fx.
X().end(),
xmin);
203 gsl_rng *
r = gsl_rng_alloc(gsl_rng_mt19937);
207 gsl_siman_params_t simanParams;
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
GSLRngWrapper class to wrap gsl_rng structure.
GSLSimAnFunc class description.
double X(unsigned int i) const
virtual double Distance(const GSLSimAnFunc &func) const
calculate the distance (metric) between this one and another configuration Presently a cartesian metr...
virtual void Print()
print the position in the standard output std::ostream GSL prints in addition n iteration,...
GSLSimAnFunc()
derived classes might need to re-define completely the class
unsigned int NDim() const
virtual GSLSimAnFunc & FastCopy(const GSLSimAnFunc &f)
fast copy method called by GSL simuated annealing internally copy only the things which have been cha...
virtual double Energy() const
evaluate the energy ( objective function value) re-implement by derived classes if needed to be modif...
virtual void Step(const GSLRandomEngine &r, double maxstep)
change the x[i] value using a random value urndm generated between [0,1] up to a maximum value maxste...
virtual GSLSimAnFunc * Clone() const
clone method.
std::vector< double > fScale
const ROOT::Math::IMultiGenFunction * fFunc
int Solve(const ROOT::Math::IMultiGenFunction &func, const double *x0, const double *scale, double *xmin, bool debug=false)
solve the simulated annealing given a multi-dim function, the initial vector parameters and a vector ...
GSLSimAnnealing()
Default constructor.
Documentation for the abstract class IBaseFunctionMultiDim.
Namespace for new Math classes and functions.
double Dist(void *xp, void *yp)
void * CopyCtor(void *xp)
void Copy(void *source, void *dest)
void Step(const gsl_rng *r, void *xp, double step_size)
double k
parameters for the Boltzman distribution
#define dest(otri, vertexptr)