Logo ROOT   6.10/09
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 /*! \class TMVA::SimulatedAnnealingFitter
30 \ingroup TMVA
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 ///
65 /// - MaxCalls <int> maximum number of calls for simulated annealing
66 /// - TemperatureGradient <float> temperature gradient for simulated annealing
67 /// - UseAdaptiveTemperature <bool> use of adaptive temperature for simulated annealing
68 /// - InitialTemperature <float> initial temperature for simulated annealing
69 /// - MinTemperature <float> minimum temperature for simulated annealing
70 /// - Eps <int> number of epochs for simulated annealing
71 /// - NFunLoops <int> number of loops for simulated annealing
72 /// - NEps <int> number of epochs for simulated annealing
73 
75 {
76 
77  // default settings
78  fMaxCalls = 100000;
80  fMinTemperature = 1e-6;
81  fEps = 1e-10;
82  fTemperatureScale = 1.0;
83  fAdaptiveSpeed = 1.0;
84  fTemperatureAdaptiveStep = 0.009875;
85  fKernelTemperatureS = "IncAdaptive";
88 
89  DeclareOptionRef(fMaxCalls, "MaxCalls", "Maximum number of minimisation calls");
90  DeclareOptionRef(fInitialTemperature, "InitialTemp", "Initial temperature");
91  DeclareOptionRef(fMinTemperature, "MinTemp", "Minimum temperature");
92  DeclareOptionRef(fEps, "Eps", "Epsilon");
93  DeclareOptionRef(fTemperatureScale, "TempScale", "Temperature scale");
94  DeclareOptionRef(fAdaptiveSpeed, "AdaptiveSpeed", "Adaptive speed");
95  DeclareOptionRef(fTemperatureAdaptiveStep,"TempAdaptiveStep", "Step made in each generation temperature adaptive");
96  DeclareOptionRef(fUseDefaultScale, "UseDefaultScale", "Use default temperature scale for temperature minimisation algorithm");
97  DeclareOptionRef(fUseDefaultTemperature, "UseDefaultTemp", "Use default initial temperature");
98 
99  DeclareOptionRef(fKernelTemperatureS, "KernelTemp", "Temperature minimisation algorithm");
100  AddPreDefVal(TString("IncAdaptive"));
101  AddPreDefVal(TString("DecAdaptive"));
102  AddPreDefVal(TString("Sqrt"));
103  AddPreDefVal(TString("Log"));
104  AddPreDefVal(TString("Sin"));
105  AddPreDefVal(TString("Homo"));
106  AddPreDefVal(TString("Geo"));
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// set SA configuration parameters
111 
113  Double_t initialTemperature,
114  Double_t minTemperature,
115  Double_t eps,
116  TString kernelTemperatureS,
117  Double_t temperatureScale,
118  Double_t temperatureAdaptiveStep,
119  Bool_t useDefaultScale,
120  Bool_t useDefaultTemperature)
121 {
122  fMaxCalls = maxCalls;
123  fInitialTemperature = initialTemperature;
124  fMinTemperature = minTemperature;
125  fEps = eps;
126  fKernelTemperatureS = kernelTemperatureS;
127  fTemperatureScale = temperatureScale;
128  fTemperatureAdaptiveStep = temperatureAdaptiveStep;
129  fUseDefaultScale = useDefaultScale;
130  fUseDefaultTemperature = useDefaultTemperature;
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Execute fitting
135 
136 Double_t TMVA::SimulatedAnnealingFitter::Run( std::vector<Double_t>& pars )
137 {
138  Log() << kHEADER << "<SimulatedAnnealingFitter> Optimisation, please be patient ... " << Endl;
139  Log() << kINFO << "(progress timing may be inaccurate for SA)" << Endl;
140 
142 
143  // set driving parameters
147 
148  if (fIPyMaxIter){
151  }
152  // minimise
153  Double_t fcn = sa.Minimize( pars );
154 
155  return fcn;
156 }
const std::vector< TMVA::Interval * > fRanges
Definition: FitterBase.h:85
UInt_t * fIPyCurrentIter
Definition: FitterBase.h:94
MsgLogger & Log() const
Definition: FitterBase.h:89
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:158
Base class for TMVA fitters.
Definition: FitterBase.h:51
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void DeclareOptions()
declare SA options.
bool * fExitFromTraining
Definition: FitterBase.h:95
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
UInt_t * fIPyMaxIter
Definition: FitterBase.h:94
STL namespace.
IFitterTarget & GetFitterTarget() const
Definition: FitterBase.h:64
Double_t Run()
estimator function interface for fitting
Definition: FitterBase.cxx:74
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
The TMVA::Interval Class.
Definition: Interval.h:61
Base implementation of simulated annealing fitting procedure.
const Bool_t kFALSE
Definition: RtypesCore.h:92
#define ClassImp(name)
Definition: Rtypes.h:336
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:168
void SetIPythonInteractive(bool *ExitFromTraining, UInt_t *fIPyCurrentIter_)
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
Fitter using a Simulated Annealing Algorithm.