/usr/include/root/Math/GSLSimAnnealing.h is in libroot-math-mathmore-dev 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | // @(#)root/mathmore:$Id$
// Author: L. Moneta Thu Jan 25 11:13:48 2007
/**********************************************************************
* *
* Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this library (see file COPYING); if not, write *
* to the Free Software Foundation, Inc., 59 Temple Place, Suite *
* 330, Boston, MA 02111-1307 USA, or contact the author. *
* *
**********************************************************************/
// Header file for class GSLSimAnnealing
#ifndef ROOT_Math_GSLSimAnnealing
#define ROOT_Math_GSLSimAnnealing
#include "Math/IFunctionfwd.h"
#include <vector>
namespace ROOT {
namespace Math {
class GSLRandomEngine;
//_____________________________________________________________________________
/**
GSLSimAnFunc class description.
Interface class for the objetive function to be used in simulated annealing
If user wants to re-implement some of the methods (like the one defining the metric) which are used by the
the simulated annealing algorithm must build a user derived class.
NOTE: Derived classes must re-implement the assignment and copy constructor to call them of the parent class
@ingroup MultiMin
*/
class GSLSimAnFunc {
public:
/**
construct from an interface of a multi-dimensional function
*/
GSLSimAnFunc(const ROOT::Math::IMultiGenFunction & func, const double * x);
/**
construct from an interface of a multi-dimensional function
Use optionally a scale factor (for each coordinate) which can be used to scale the step sizes
(this is used for example by the minimization algorithm)
*/
GSLSimAnFunc(const ROOT::Math::IMultiGenFunction & func, const double * x, const double * scale);
protected:
/**
derived classes might need to re-define completely the class
*/
GSLSimAnFunc() :
fFunc(0)
{}
public:
/// virtual distructor (no operations)
virtual ~GSLSimAnFunc() { } //
/**
fast copy method called by GSL simuated annealing internally
copy only the things which have been changed
must be re-implemented by derived classes if needed
*/
virtual GSLSimAnFunc & FastCopy(const GSLSimAnFunc & f);
/**
clone method. Needs to be re-implemented by the derived classes for deep copying
*/
virtual GSLSimAnFunc * Clone() const {
return new GSLSimAnFunc(*this);
}
/**
evaluate the energy ( objective function value)
re-implement by derived classes if needed to be modified
*/
virtual double Energy() const;
/**
change the x[i] value using a random value urndm generated between [0,1]
up to a maximum value maxstep
re-implement by derived classes if needed to be modified
*/
virtual void Step(const GSLRandomEngine & r, double maxstep);
/**
calculate the distance (metric) between this one and another configuration
Presently a cartesian metric is used.
re-implement by derived classes if needed to be modified
*/
virtual double Distance(const GSLSimAnFunc & func) const;
/**
print the position in the standard output ostream
GSL prints in addition n iteration, n function calls, temperature and energy
re-implement by derived classes if necessary
*/
virtual void Print();
/**
change the x values (used by sim annealing to take a step)
*/
void SetX(const double * x) {
std::copy(x, x+ fX.size(), fX.begin() );
}
template <class IT>
void SetX(IT begin, IT end) {
std::copy(begin, end, fX.begin() );
}
unsigned int NDim() const { return fX.size(); }
double X(unsigned int i) const { return fX[i]; }
const std::vector<double> & X() const { return fX; }
double Scale(unsigned int i) const { return fScale[i]; }
void SetX(unsigned int i, double x) { fX[i] = x; }
// use compiler generated copy ctror and assignment operators
private:
std::vector<double> fX;
std::vector<double> fScale;
const ROOT::Math::IMultiGenFunction * fFunc;
};
//_____________________________________________________
/**
structure holding the simulated annealing parameters
@ingroup MultiMin
*/
struct GSLSimAnParams {
// constructor with some default values
GSLSimAnParams() {
n_tries = 200;
iters_fixed_T = 10;
step_size = 10;
// the following parameters are for the Boltzmann distribution */
k = 1.0;
t_initial = 0.002;
mu = 1.005;
t_min = 2.0E-6;
}
int n_tries; // number of points to try for each step
int iters_fixed_T; // number of iterations at each temperature
double step_size; // max step size used in random walk
/// parameters for the Boltzman distribution
double k;
double t_initial;
double mu;
double t_min;
};
//___________________________________________________________________________
/**
GSLSimAnnealing class for performing a simulated annealing search of
a multidimensional function
@ingroup MultiMin
*/
class GSLSimAnnealing {
public:
/**
Default constructor
*/
GSLSimAnnealing ();
/**
Destructor (no operations)
*/
~GSLSimAnnealing () {}
private:
// usually copying is non trivial, so we make this unaccessible
/**
Copy constructor
*/
GSLSimAnnealing(const GSLSimAnnealing &) {}
/**
Assignment operator
*/
GSLSimAnnealing & operator = (const GSLSimAnnealing & rhs) {
if (this == &rhs) return *this; // time saving self-test
return *this;
}
public:
/**
solve the simulated annealing given a multi-dim function, the initial vector parameters
and a vector containing the scaling factors for the parameters
*/
int Solve(const ROOT::Math::IMultiGenFunction & func, const double * x0, const double * scale, double * xmin, bool debug = false);
/**
solve the simulated annealing given a GSLSimAnFunc object
The object will contain the initial state at the beginning and the final minimum state at the end
*/
int Solve(GSLSimAnFunc & func, bool debug = false);
GSLSimAnParams & Params() { return fParams; }
const GSLSimAnParams & Params() const { return fParams; }
protected:
private:
GSLSimAnParams fParams; // parameters for GSLSimAnnealig
};
} // end namespace Math
} // end namespace ROOT
#endif /* ROOT_Math_GSLSimAnnealing */
|