51 : fKernelTemperature (kIncreasingAdaptive),
52 fFitterTarget ( target ),
56 fInitialTemperature ( 1000 ),
57 fMinTemperature ( 0 ),
59 fTemperatureScale ( 0.06 ),
60 fAdaptiveSpeed ( 1.0 ),
61 fTemperatureAdaptiveStep( 0.0 ),
62 fUseDefaultScale (
kFALSE ),
63 fUseDefaultTemperature (
kFALSE ),
64 fLogger( new
MsgLogger(
"SimulatedAnnealing") ),
82 Bool_t useDefaultTemperature)
89 if (kernelTemperatureS ==
"IncreasingAdaptive") {
91 Log() << kINFO <<
"Using increasing adaptive algorithm" <<
Endl;
93 else if (kernelTemperatureS ==
"DecreasingAdaptive") {
95 Log() << kINFO <<
"Using decreasing adaptive algorithm" <<
Endl;
97 else if (kernelTemperatureS ==
"Sqrt") {
99 Log() << kINFO <<
"Using \"Sqrt\" algorithm" <<
Endl;
101 else if (kernelTemperatureS ==
"Homo") {
103 Log() << kINFO <<
"Using \"Homo\" algorithm" <<
Endl;
105 else if (kernelTemperatureS ==
"Log") {
107 Log() << kINFO <<
"Using \"Log\" algorithm" <<
Endl;
109 else if (kernelTemperatureS ==
"Sin") {
111 Log() << kINFO <<
"Using \"Sin\" algorithm" <<
Endl;
134 for (
UInt_t rIter = 0; rIter < parameters.size(); rIter++) {
144 for (
UInt_t rIter = 0; rIter < from.size(); rIter++) to[rIter] = from[rIter];
155 for (
UInt_t rIter=0;rIter<parameters.size();rIter++) {
159 sign = (uni - 0.5 >= 0.0) ? (1.0) : (-1.0);
160 distribution = currentTemperature * (
TMath::Power(1.0 + 1.0/currentTemperature,
TMath::Abs(2.0*uni - 1.0)) -1.0)*sign;
161 parameters[rIter] = oldParameters[rIter] + (
fRanges[rIter]->GetMax()-
fRanges[rIter]->GetMin())*0.1*distribution;
163 while (parameters[rIter] <
fRanges[rIter]->GetMin() || parameters[rIter] >
fRanges[rIter]->GetMax() );
171 std::vector<Double_t> newParameters(
fRanges.size() );
173 for (
UInt_t rIter=0; rIter<parameters.size(); rIter++) {
177 sign = (uni - 0.5 >= 0.0) ? (1.0) : (-1.0);
178 distribution = currentTemperature * (
TMath::Power(1.0 + 1.0/currentTemperature,
TMath::Abs(2.0*uni - 1.0)) -1.0)*sign;
179 newParameters[rIter] = parameters[rIter] + (
fRanges[rIter]->GetMax()-
fRanges[rIter]->GetMin())*0.1*distribution;
181 while (newParameters[rIter] <
fRanges[rIter]->GetMin() || newParameters[rIter] >
fRanges[rIter]->GetMax() );
184 return newParameters;
213 else Log() << kFATAL <<
"No such kernel!" <<
Endl;
245 else Log() << kFATAL <<
"No such kernel!" <<
Endl;
255 Double_t t, dT, cold, delta, deltaY,
y, yNew, yBest, yOld;
260 for (
UInt_t rIter = 0; rIter <
x.size(); rIter++)
261 x[rIter] = (
fRanges[rIter]->GetMax() +
fRanges[rIter]->GetMin() ) / 2.0;
264 if ((i>0) && (deltaY>0.0)) {
272 for (
Int_t k=0; (k<30) && (equilibrium<=12); k++ ) {
285 if (y != 0.0) delta /=
y;
286 else if (yNew != 0.0) delta /=
y;
289 if (delta < 0.1) equilibrium++;
290 else equilibrium = 0;
297 deltaY = yNew - yOld;
298 if ( (deltaY < 0.0 )&&( yNew < yBest)) {
303 if ((stopper) && (deltaY >= (100.0 * cold)))
break;
314 std::vector<Double_t> bestParameters(
fRanges.size());
315 std::vector<Double_t> oldParameters (
fRanges.size());
317 Double_t currentTemperature, bestFit, currentFit;
318 Int_t optimizeCalls, generalCalls, equals;
341 <<
", current temperature = " << currentTemperature <<
Endl;
343 bestParameters = parameters;
347 generalCalls =
fMaxCalls - optimizeCalls;
352 for (
Int_t sample = 0; sample < generalCalls; sample++) {
358 if (localFit < currentFit ||
TMath::Abs(currentFit-localFit) <
fEps) {
369 currentFit = localFit;
371 if (currentFit < bestFit) {
373 bestFit = currentFit;
377 if (!
ShouldGoIn(localFit, currentFit, currentTemperature))
380 currentFit = localFit;
392 Log() << kINFO <<
"Elapsed time: " << timer.GetElapsedTime()
398 currentTemperature = startingTemperature;
401 for (
Int_t sample=0;sample<optimizeCalls;sample++) {
405 if (localFit < currentFit) {
406 currentFit = localFit;
409 if (currentFit < bestFit) {
411 bestFit = currentFit;
416 currentTemperature-=(startingTemperature -
fEps)/optimizeCalls;
Double_t GenerateMaxTemperature(std::vector< Double_t > ¶meters)
maximum temperature
void FillWithRandomValues(std::vector< Double_t > ¶meters)
random starting parameters
virtual Double_t EstimatorFunction(std::vector< Double_t > ¶meters)=0
void GenerateNewTemperature(Double_t ¤tTemperature, Int_t Iter)
generate new temperature
Random number generator class based on M.
MsgLogger & Endl(MsgLogger &ml)
const std::vector< TMVA::Interval * > & fRanges
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
SimulatedAnnealing(IFitterTarget &target, const std::vector< TMVA::Interval *> &ranges)
constructor
IFitterTarget & fFitterTarget
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
void GenerateNeighbour(std::vector< Double_t > ¶meters, std::vector< Double_t > &oldParameters, Double_t currentTemperature)
generate adjacent parameters
Double_t fTemperatureAdaptiveStep
Bool_t fUseDefaultTemperature
virtual ~SimulatedAnnealing()
destructor
void SetOptions(Int_t maxCalls, Double_t initialTemperature, Double_t minTemperature, Double_t eps, TString kernelTemperatureS, Double_t temperatureScale, Double_t adaptiveSpeed, Double_t temperatureAdaptiveStep, Bool_t useDefaultScale, Bool_t useDefaultTemperature)
option setter
Base implementation of simulated annealing fitting procedure.
void SetDefaultScale()
setting of default scale
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
ostringstream derivative to redirect and format output
Bool_t ShouldGoIn(Double_t currentFit, Double_t localFit, Double_t currentTemperature)
result checker
enum TMVA::SimulatedAnnealing::EKernelTemperature fKernelTemperature
std::string GetSource() const
Double_t Minimize(std::vector< Double_t > ¶meters)
minimisation algorithm
Double_t fInitialTemperature
Double_t Sqrt(Double_t x)
Interface for a fitter 'target'.
Double_t fTemperatureScale
Timing information for training and evaluation of MVA methods.
void ReWriteParameters(std::vector< Double_t > &from, std::vector< Double_t > &to)
copy parameters