File indexing completed on 2025-01-30 10:23:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef ROOT_TMVA_SimulatedAnnealing
0029 #define ROOT_TMVA_SimulatedAnnealing
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #include <vector>
0040
0041 #include "TMVA/Types.h"
0042
0043 class TRandom;
0044
0045 namespace TMVA {
0046
0047 class IFitterTarget;
0048 class Interval;
0049 class MsgLogger;
0050
0051 class SimulatedAnnealing {
0052
0053 public:
0054
0055 SimulatedAnnealing( IFitterTarget& target, const std::vector<TMVA::Interval*>& ranges );
0056 virtual ~SimulatedAnnealing();
0057
0058
0059 Double_t Minimize( std::vector<Double_t>& parameters );
0060
0061
0062 void SetMaxCalls ( Int_t mc ) { fMaxCalls = mc; }
0063 void SetInitTemp ( Double_t it ) { fInitialTemperature = it; }
0064 void SetMinTemp ( Double_t min ) { fMinTemperature = min; }
0065 void SetAccuracy ( Double_t eps ) { fEps = eps; }
0066 void SetTemperatureScale ( Double_t scale ) { fTemperatureScale = scale; }
0067 void SetAdaptiveSpeed ( Double_t speed ) { fAdaptiveSpeed = speed; }
0068
0069 void SetOptions( Int_t maxCalls, Double_t initialTemperature, Double_t minTemperature, Double_t eps,
0070 TString kernelTemperatureS, Double_t temperatureScale, Double_t adaptiveSpeed,
0071 Double_t temperatureAdaptiveStep, Bool_t useDefaultScale, Bool_t useDefaultTemperature );
0072
0073
0074 void SetIPythonInteractive(bool* ExitFromTraining, UInt_t *fIPyCurrentIter_){
0075 fExitFromTraining = ExitFromTraining;
0076 fIPyCurrentIter = fIPyCurrentIter_;
0077 }
0078
0079 private:
0080
0081 enum EKernelTemperature {
0082 kSqrt = 0,
0083 kIncreasingAdaptive,
0084 kDecreasingAdaptive,
0085 kLog,
0086 kHomo,
0087 kSin,
0088 kGeo
0089 } fKernelTemperature;
0090
0091 void FillWithRandomValues( std::vector<Double_t>& parameters );
0092 void ReWriteParameters( std::vector<Double_t>& from, std::vector<Double_t>& to );
0093 void GenerateNewTemperature(Double_t& currentTemperature, Int_t Iter );
0094 void GenerateNeighbour( std::vector<Double_t>& parameters, std::vector<Double_t>& oldParameters, Double_t currentTemperature );
0095 Bool_t ShouldGoIn( Double_t currentFit, Double_t localFit, Double_t currentTemperature );
0096 void SetDefaultScale();
0097 Double_t GenerateMaxTemperature( std::vector<Double_t>& parameters );
0098 std::vector<Double_t> GenerateNeighbour( std::vector<Double_t>& parameters, Double_t currentTemperature );
0099
0100 IFitterTarget& fFitterTarget;
0101 TRandom* fRandom;
0102 const std::vector<TMVA::Interval*>& fRanges;
0103
0104
0105 Int_t fMaxCalls;
0106 Double_t fInitialTemperature;
0107 Double_t fMinTemperature;
0108 Double_t fEps;
0109 Double_t fTemperatureScale;
0110 Double_t fAdaptiveSpeed;
0111
0112
0113 Double_t fTemperatureAdaptiveStep;
0114
0115 Bool_t fUseDefaultScale;
0116 Bool_t fUseDefaultTemperature;
0117
0118 mutable MsgLogger* fLogger;
0119 MsgLogger& Log() const { return *fLogger; }
0120
0121 Double_t fProgress;
0122
0123
0124 UInt_t *fIPyCurrentIter = nullptr;
0125 bool * fExitFromTraining = nullptr;
0126
0127 ClassDef(SimulatedAnnealing,0);
0128 };
0129
0130 }
0131
0132 #endif
0133