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() ) ),
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;
212 simanParams.n_tries = fParams.n_tries;
213 simanParams.iters_fixed_T = fParams.iters_fixed_T;
214 simanParams.step_size = fParams.step_size;
216 simanParams.k = fParams.k;
217 simanParams.t_initial = fParams.t_initial;
218 simanParams.mu_t = fParams.mu;
219 simanParams.t_min = fParams.t_min;
GSLSimAnnealing()
Default constructor.
Namespace for new ROOT classes and functions.
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...
const ROOT::Math::IMultiGenFunction * fFunc
GSLSimAnFunc class description.
void Step(const gsl_rng *r, void *xp, double step_size)
virtual double Energy() const
evaluate the energy ( objective function value) re-implement by derived classes if needed to be modif...
you should not use this method at all Int_t y
virtual GSLSimAnFunc * Clone() const
clone method.
virtual double Distance(const GSLSimAnFunc &func) const
calculate the distance (metric) between this one and another configuration Presently a cartesian metr...
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 ...
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
GSLRngWrapper class to wrap gsl_rng structure.
virtual void Print()
print the position in the standard output std::ostream GSL prints in addition n iteration, n function calls, temperature and energy re-implement by derived classes if necessary
double Dist(void *xp, void *yp)
double X(unsigned int i) const
Documentation for the abstract class IBaseFunctionMultiDim.
unsigned int NDim() const
std::vector< double > fScale
* x
Deprecated and error prone model selection interface.
virtual GSLSimAnFunc & FastCopy(const GSLSimAnFunc &f)
fast copy method called by GSL simuated annealing internally copy only the things which have been cha...
void Copy(void *source, void *dest)
GSLSimAnFunc()
derived classes might need to re-define completely the class
Namespace for new Math classes and functions.
#define dest(otri, vertexptr)
void * CopyCtor(void *xp)