Logo ROOT   6.08/07
Reference Guide
SimulatedAnnealingFitter.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andraes Hoecker, Kamil Kraszewski, Maciej Kruk
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : SimulatedAnnealingFitter *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation *
12  * *
13  * Authors (alphabetical): *
14  * Krzysztof Danielowski <danielow@cern.ch> - IFJ & AGH, Poland *
15  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
16  * Kamil Kraszewski <kalq@cern.ch> - IFJ & UJ, Poland *
17  * Maciej Kruk <mkruk@cern.ch> - IFJ & AGH, Poland *
18  * *
19  * Copyright (c) 2008: *
20  * IFJ-Krakow, Poland *
21  * CERN, Switzerland *
22  * MPI-K Heidelberg, Germany *
23  * *
24  * Redistribution and use in source and binary forms, with or without *
25  * modification, are permitted according to the terms listed in LICENSE *
26  * (http://tmva.sourceforge.net/LICENSE) *
27  **********************************************************************************/
28 
29 //_______________________________________________________________________
30 //
31 // Fitter using a Simulated Annealing Algorithm
32 //_______________________________________________________________________
33 
35 
36 #include "TMVA/Configurable.h"
37 #include "TMVA/FitterBase.h"
38 #include "TMVA/Interval.h"
39 #include "TMVA/MsgLogger.h"
41 #include "TMVA/Types.h"
42 
43 #include "Rtypes.h"
44 #include "TString.h"
45 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// constructor
50 
52  const TString& name,
53  const std::vector<Interval*>& ranges,
54  const TString& theOption )
55 : TMVA::FitterBase( target, name, ranges, theOption )
56 {
57  // default parameters settings for Simulated Annealing algorithm
58  DeclareOptions();
59  ParseOptions();
60 }
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 /// declare SA options
64 
66 {
67  // MaxCalls <int> maximum number of calls for simulated annealing
68  // TemperatureGradient <float> temperature gradient for simulated annealing
69  // UseAdaptiveTemperature <bool> use of adaptive temperature for simulated annealing
70  // InitialTemperature <float> initial temperature for simulated annealing
71  // MinTemperature <float> minimum temperature for simulated annealing
72  // Eps <int> number of epochs for simulated annealing
73  // NFunLoops <int> number of loops for simulated annealing
74  // NEps <int> number of epochs for simulated annealing
75 
76  // default settings
77  fMaxCalls = 100000;
79  fMinTemperature = 1e-6;
80  fEps = 1e-10;
81  fTemperatureScale = 1.0;
82  fAdaptiveSpeed = 1.0;
83  fTemperatureAdaptiveStep = 0.009875;
84  fKernelTemperatureS = "IncAdaptive";
87 
88  DeclareOptionRef(fMaxCalls, "MaxCalls", "Maximum number of minimisation calls");
89  DeclareOptionRef(fInitialTemperature, "InitialTemp", "Initial temperature");
90  DeclareOptionRef(fMinTemperature, "MinTemp", "Mimimum temperature");
91  DeclareOptionRef(fEps, "Eps", "Epsilon");
92  DeclareOptionRef(fTemperatureScale, "TempScale", "Temperature scale");
93  DeclareOptionRef(fAdaptiveSpeed, "AdaptiveSpeed", "Adaptive speed");
94  DeclareOptionRef(fTemperatureAdaptiveStep,"TempAdaptiveStep", "Step made in each generation temperature adaptive");
95  DeclareOptionRef(fUseDefaultScale, "UseDefaultScale", "Use default temperature scale for temperature minimisation algorithm");
96  DeclareOptionRef(fUseDefaultTemperature, "UseDefaultTemp", "Use default initial temperature");
97 
98  DeclareOptionRef(fKernelTemperatureS, "KernelTemp", "Temperature minimisation algorithm");
99  AddPreDefVal(TString("IncAdaptive"));
100  AddPreDefVal(TString("DecAdaptive"));
101  AddPreDefVal(TString("Sqrt"));
102  AddPreDefVal(TString("Log"));
103  AddPreDefVal(TString("Sin"));
104  AddPreDefVal(TString("Homo"));
105  AddPreDefVal(TString("Geo"));
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// set SA configuration parameters
110 
112  Double_t initialTemperature,
113  Double_t minTemperature,
114  Double_t eps,
115  TString kernelTemperatureS,
116  Double_t temperatureScale,
117  Double_t temperatureAdaptiveStep,
118  Bool_t useDefaultScale,
119  Bool_t useDefaultTemperature)
120 {
121  fMaxCalls = maxCalls;
122  fInitialTemperature = initialTemperature;
123  fMinTemperature = minTemperature;
124  fEps = eps;
125  fKernelTemperatureS = kernelTemperatureS;
126  fTemperatureScale = temperatureScale;
127  fTemperatureAdaptiveStep = temperatureAdaptiveStep;
128  fUseDefaultScale = useDefaultScale;
129  fUseDefaultTemperature = useDefaultTemperature;
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Execute fitting
134 
135 Double_t TMVA::SimulatedAnnealingFitter::Run( std::vector<Double_t>& pars )
136 {
137  Log() << kHEADER << "<SimulatedAnnealingFitter> Optimisation, please be patient ... " << Endl;
138  Log() << kINFO << "(progress timing may be inaccurate for SA)" << Endl;
139 
141 
142  // set driving parameters
146 
147  if (fIPyMaxIter){
150  }
151  // minimise
152  Double_t fcn = sa.Minimize( pars );
153 
154  return fcn;
155 }
const std::vector< TMVA::Interval * > fRanges
Definition: FitterBase.h:91
UInt_t * fIPyCurrentIter
Definition: FitterBase.h:100
MsgLogger & Log() const
Definition: FitterBase.h:95
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void DeclareOptions()
declare SA options
bool * fExitFromTraining
Definition: FitterBase.h:101
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
UInt_t * fIPyMaxIter
Definition: FitterBase.h:100
STL namespace.
IFitterTarget & GetFitterTarget() const
Definition: FitterBase.h:70
Double_t Run()
estimator function interface for fitting
Definition: FitterBase.cxx:80
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
void SetParameters(Int_t fMaxCalls, Double_t fInitialTemperature, Double_t fMinTemperature, Double_t fEps, TString fKernelTemperatureS, Double_t fTemperatureScale, Double_t fTemperatureAdaptiveStep, Bool_t fUseDefaultScale, Bool_t fUseDefaultTemperature)
set SA configuration parameters
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
void AddPreDefVal(const T &)
Definition: Configurable.h:174
void SetIPythonInteractive(bool *ExitFromTraining, UInt_t *fIPyCurrentIter_)
Abstract ClassifierFactory template that handles arbitrary types.
Double_t Minimize(std::vector< Double_t > &parameters)
minimisation algorithm
char name[80]
Definition: TGX11.cxx:109