Logo ROOT   6.08/07
Reference Guide
SimulatedAnnealing.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Krzysztof Danielowski, Kamil Kraszewski, Maciej Kruk
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : SimulatedAnnealing *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation of simulated annealing fitting procedure *
12  * *
13  * Authors (alphabetical): *
14  * Krzysztof Danielowski <danielow@cern.ch> - IFJ & AGH, Poland *
15  * Kamil Kraszewski <kalq@cern.ch> - IFJ & UJ, Poland *
16  * Maciej Kruk <mkruk@cern.ch> - IFJ & AGH, Poland *
17  * *
18  * Copyright (c) 2008: *
19  * IFJ-Krakow, Poland *
20  * CERN, Switzerland *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #ifndef ROOT_TMVA_SimulatedAnnealing
29 #define ROOT_TMVA_SimulatedAnnealing
30 
31 //////////////////////////////////////////////////////////////////////////
32 // //
33 // SimulatedAnnealing //
34 // //
35 // Base implementation of simulated annealing fitting procedure //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include <vector>
40 #include <list>
41 
42 #ifndef ROOT_TMVA_Types
43 #include "TMVA/Types.h"
44 #endif
45 
46 class TRandom;
47 
48 namespace TMVA {
49 
50  class IFitterTarget;
51  class Interval;
52  class MsgLogger;
53 
55 
56  public:
57 
58  SimulatedAnnealing( IFitterTarget& target, const std::vector<TMVA::Interval*>& ranges );
59  virtual ~SimulatedAnnealing();
60 
61  // returns FCN value at minimum
62  Double_t Minimize( std::vector<Double_t>& parameters );
63 
64  // accessors
65  void SetMaxCalls ( Int_t mc ) { fMaxCalls = mc; }
67  void SetMinTemp ( Double_t min ) { fMinTemperature = min; }
68  void SetAccuracy ( Double_t eps ) { fEps = eps; }
69  void SetTemperatureScale ( Double_t scale ) { fTemperatureScale = scale; }
70  void SetAdaptiveSpeed ( Double_t speed ) { fAdaptiveSpeed = speed; }
71 
72  void SetOptions( Int_t maxCalls, Double_t initialTemperature, Double_t minTemperature, Double_t eps,
73  TString kernelTemperatureS, Double_t temperatureScale, Double_t adaptiveSpeed,
74  Double_t temperatureAdaptiveStep, Bool_t useDefaultScale, Bool_t useDefaultTemperature );
75 
76  //setting up helper variables for JsMVA
77  void SetIPythonInteractive(bool* ExitFromTraining, UInt_t *fIPyCurrentIter_){
78  fExitFromTraining = ExitFromTraining;
79  fIPyCurrentIter = fIPyCurrentIter_;
80  }
81 
82  private:
83 
85  kSqrt = 0,
93 
94  void FillWithRandomValues( std::vector<Double_t>& parameters );
95  void ReWriteParameters( std::vector<Double_t>& from, std::vector<Double_t>& to );
96  void GenerateNewTemperature(Double_t& currentTemperature, Int_t Iter );
97  void GenerateNeighbour( std::vector<Double_t>& parameters, std::vector<Double_t>& oldParameters, Double_t currentTemperature );
98  Bool_t ShouldGoIn( Double_t currentFit, Double_t localFit, Double_t currentTemperature );
99  void SetDefaultScale();
100  Double_t GenerateMaxTemperature( std::vector<Double_t>& parameters );
101  std::vector<Double_t> GenerateNeighbour( std::vector<Double_t>& parameters, Double_t currentTemperature );
102 
103  IFitterTarget& fFitterTarget; // the fitter target
104  TRandom* fRandom; // random generator
105  const std::vector<TMVA::Interval*>& fRanges; // parameter ranges
106 
107  // fitter setup
108  Int_t fMaxCalls; // maximum number of minimisation calls
109  Double_t fInitialTemperature; // initial temperature
110  Double_t fMinTemperature; // mimimum temperature
111  Double_t fEps; // epsilon
112  Double_t fTemperatureScale; // how fast temperature change
113  Double_t fAdaptiveSpeed; // how fast temperature change in adaptive (in adaptive two variables describe
114  // the change of temperature, but fAdaptiveSpeed should be 1.0 and its not
115  // recomended to change it)
116  Double_t fTemperatureAdaptiveStep;// used to calculate InitialTemperature if fUseDefaultTemperature
117 
118  Bool_t fUseDefaultScale; // if TRUE, SA calculates its own TemperatureScale
119  Bool_t fUseDefaultTemperature; // if TRUE, SA calculates its own InitialTemperature (MinTemperautre)
120 
121  mutable MsgLogger* fLogger; // message logger
122  MsgLogger& Log() const { return *fLogger; }
123 
125 
126  // variables for JsMVA
128  bool * fExitFromTraining = nullptr;
129 
130  ClassDef(SimulatedAnnealing,0); // Base class for Simulated Annealing fitting
131  };
132 
133 } // namespace TMVA
134 
135 #endif
136 
Double_t GenerateMaxTemperature(std::vector< Double_t > &parameters)
maximum temperature
void FillWithRandomValues(std::vector< Double_t > &parameters)
random starting parameters
void GenerateNewTemperature(Double_t &currentTemperature, Int_t Iter)
generate new temperature
const std::vector< TMVA::Interval * > & fRanges
void SetAccuracy(Double_t eps)
SimulatedAnnealing(IFitterTarget &target, const std::vector< TMVA::Interval *> &ranges)
constructor
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
void GenerateNeighbour(std::vector< Double_t > &parameters, std::vector< Double_t > &oldParameters, Double_t currentTemperature)
generate adjacent parameters
#define ClassDef(name, id)
Definition: Rtypes.h:254
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:31
virtual ~SimulatedAnnealing()
destructor
void SetTemperatureScale(Double_t scale)
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
unsigned int UInt_t
Definition: RtypesCore.h:42
void SetInitTemp(Double_t it)
void SetDefaultScale()
setting of default scale
double Double_t
Definition: RtypesCore.h:55
Bool_t ShouldGoIn(Double_t currentFit, Double_t localFit, Double_t currentTemperature)
result checker
void SetIPythonInteractive(bool *ExitFromTraining, UInt_t *fIPyCurrentIter_)
enum TMVA::SimulatedAnnealing::EKernelTemperature fKernelTemperature
Abstract ClassifierFactory template that handles arbitrary types.
Double_t Minimize(std::vector< Double_t > &parameters)
minimisation algorithm
void ReWriteParameters(std::vector< Double_t > &from, std::vector< Double_t > &to)
copy parameters
void SetAdaptiveSpeed(Double_t speed)
void SetMinTemp(Double_t min)