Logo ROOT   6.12/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 #include "TMVA/Types.h"
43 
44 class TRandom;
45 
46 namespace TMVA {
47 
48  class IFitterTarget;
49  class Interval;
50  class MsgLogger;
51 
53 
54  public:
55 
56  SimulatedAnnealing( IFitterTarget& target, const std::vector<TMVA::Interval*>& ranges );
57  virtual ~SimulatedAnnealing();
58 
59  // returns FCN value at minimum
60  Double_t Minimize( std::vector<Double_t>& parameters );
61 
62  // accessors
63  void SetMaxCalls ( Int_t mc ) { fMaxCalls = mc; }
65  void SetMinTemp ( Double_t min ) { fMinTemperature = min; }
66  void SetAccuracy ( Double_t eps ) { fEps = eps; }
67  void SetTemperatureScale ( Double_t scale ) { fTemperatureScale = scale; }
68  void SetAdaptiveSpeed ( Double_t speed ) { fAdaptiveSpeed = speed; }
69 
70  void SetOptions( Int_t maxCalls, Double_t initialTemperature, Double_t minTemperature, Double_t eps,
71  TString kernelTemperatureS, Double_t temperatureScale, Double_t adaptiveSpeed,
72  Double_t temperatureAdaptiveStep, Bool_t useDefaultScale, Bool_t useDefaultTemperature );
73 
74  //setting up helper variables for JsMVA
75  void SetIPythonInteractive(bool* ExitFromTraining, UInt_t *fIPyCurrentIter_){
76  fExitFromTraining = ExitFromTraining;
77  fIPyCurrentIter = fIPyCurrentIter_;
78  }
79 
80  private:
81 
83  kSqrt = 0,
91 
92  void FillWithRandomValues( std::vector<Double_t>& parameters );
93  void ReWriteParameters( std::vector<Double_t>& from, std::vector<Double_t>& to );
94  void GenerateNewTemperature(Double_t& currentTemperature, Int_t Iter );
95  void GenerateNeighbour( std::vector<Double_t>& parameters, std::vector<Double_t>& oldParameters, Double_t currentTemperature );
96  Bool_t ShouldGoIn( Double_t currentFit, Double_t localFit, Double_t currentTemperature );
97  void SetDefaultScale();
98  Double_t GenerateMaxTemperature( std::vector<Double_t>& parameters );
99  std::vector<Double_t> GenerateNeighbour( std::vector<Double_t>& parameters, Double_t currentTemperature );
100 
101  IFitterTarget& fFitterTarget; // the fitter target
102  TRandom* fRandom; // random generator
103  const std::vector<TMVA::Interval*>& fRanges; // parameter ranges
104 
105  // fitter setup
106  Int_t fMaxCalls; // maximum number of minimisation calls
107  Double_t fInitialTemperature; // initial temperature
108  Double_t fMinTemperature; // minimum temperature
109  Double_t fEps; // epsilon
110  Double_t fTemperatureScale; // how fast temperature change
111  Double_t fAdaptiveSpeed; // how fast temperature change in adaptive (in adaptive two variables describe
112  // the change of temperature, but fAdaptiveSpeed should be 1.0 and its not
113  // recommended to change it)
114  Double_t fTemperatureAdaptiveStep;// used to calculate InitialTemperature if fUseDefaultTemperature
115 
116  Bool_t fUseDefaultScale; // if TRUE, SA calculates its own TemperatureScale
117  Bool_t fUseDefaultTemperature; // if TRUE, SA calculates its own InitialTemperature (MinTemperautre)
118 
119  mutable MsgLogger* fLogger; // message logger
120  MsgLogger& Log() const { return *fLogger; }
121 
123 
124  // variables for JsMVA
126  bool * fExitFromTraining = nullptr;
127 
128  ClassDef(SimulatedAnnealing,0); // Base class for Simulated Annealing fitting
129  };
130 
131 } // namespace TMVA
132 
133 #endif
134 
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:125
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:320
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
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)
Base implementation of simulated annealing fitting procedure.
void SetDefaultScale()
setting of default scale
double Double_t
Definition: RtypesCore.h:55
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
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
Interface for a fitter &#39;target&#39;.
Definition: IFitterTarget.h:44
void ReWriteParameters(std::vector< Double_t > &from, std::vector< Double_t > &to)
copy parameters
void SetAdaptiveSpeed(Double_t speed)
void SetMinTemp(Double_t min)