ROOT  6.06/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 //_______________________________________________________________________
30 //
31 // Fitter using a Simulated Annealing Algorithm
32 //_______________________________________________________________________
33 
36 #include "TMVA/Interval.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// constructor
42 
43 TMVA::SimulatedAnnealingFitter::SimulatedAnnealingFitter( IFitterTarget& target,
44  const TString& name,
45  const std::vector<Interval*>& ranges,
46  const TString& theOption )
47  : TMVA::FitterBase( target, name, ranges, theOption )
48 {
49  // default parameters settings for Simulated Annealing algorithm
50  DeclareOptions();
51  ParseOptions();
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// declare SA options
56 
58 {
59  // MaxCalls <int> maximum number of calls for simulated annealing
60  // TemperatureGradient <float> temperature gradient for simulated annealing
61  // UseAdaptiveTemperature <bool> use of adaptive temperature for simulated annealing
62  // InitialTemperature <float> initial temperature for simulated annealing
63  // MinTemperature <float> minimum temperature for simulated annealing
64  // Eps <int> number of epochs for simulated annealing
65  // NFunLoops <int> number of loops for simulated annealing
66  // NEps <int> number of epochs for simulated annealing
67 
68  // default settings
69  fMaxCalls = 100000;
70  fInitialTemperature = 1e+6;
71  fMinTemperature = 1e-6;
72  fEps = 1e-10;
73  fTemperatureScale = 1.0;
74  fAdaptiveSpeed = 1.0;
75  fTemperatureAdaptiveStep = 0.009875;
76  fKernelTemperatureS = "IncAdaptive";
79 
80  DeclareOptionRef(fMaxCalls, "MaxCalls", "Maximum number of minimisation calls");
81  DeclareOptionRef(fInitialTemperature, "InitialTemp", "Initial temperature");
82  DeclareOptionRef(fMinTemperature, "MinTemp", "Mimimum temperature");
83  DeclareOptionRef(fEps, "Eps", "Epsilon");
84  DeclareOptionRef(fTemperatureScale, "TempScale", "Temperature scale");
85  DeclareOptionRef(fAdaptiveSpeed, "AdaptiveSpeed", "Adaptive speed");
86  DeclareOptionRef(fTemperatureAdaptiveStep,"TempAdaptiveStep", "Step made in each generation temperature adaptive");
87  DeclareOptionRef(fUseDefaultScale, "UseDefaultScale", "Use default temperature scale for temperature minimisation algorithm");
88  DeclareOptionRef(fUseDefaultTemperature, "UseDefaultTemp", "Use default initial temperature");
89 
90  DeclareOptionRef(fKernelTemperatureS, "KernelTemp", "Temperature minimisation algorithm");
91  AddPreDefVal(TString("IncAdaptive"));
92  AddPreDefVal(TString("DecAdaptive"));
93  AddPreDefVal(TString("Sqrt"));
94  AddPreDefVal(TString("Log"));
95  AddPreDefVal(TString("Sin"));
96  AddPreDefVal(TString("Homo"));
97  AddPreDefVal(TString("Geo"));
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// set SA configuration parameters
102 
104  Double_t initialTemperature,
105  Double_t minTemperature,
106  Double_t eps,
107  TString kernelTemperatureS,
108  Double_t temperatureScale,
109  Double_t temperatureAdaptiveStep,
110  Bool_t useDefaultScale,
111  Bool_t useDefaultTemperature)
112 {
113  fMaxCalls = maxCalls;
114  fInitialTemperature = initialTemperature;
115  fMinTemperature = minTemperature;
116  fEps = eps;
117  fKernelTemperatureS = kernelTemperatureS;
118  fTemperatureScale = temperatureScale;
119  fTemperatureAdaptiveStep = temperatureAdaptiveStep;
120  fUseDefaultScale = useDefaultScale;
121  fUseDefaultTemperature = useDefaultTemperature;
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Execute fitting
126 
127 Double_t TMVA::SimulatedAnnealingFitter::Run( std::vector<Double_t>& pars )
128 {
129  Log() << kINFO << "<SimulatedAnnealingFitter> Optimisation, please be patient ... " << Endl;
130  Log() << kINFO << "(progress timing may be inaccurate for SA)" << Endl;
131 
132  SimulatedAnnealing sa( GetFitterTarget(), fRanges );
133 
134  // set driving parameters
135  sa.SetOptions( fMaxCalls, fInitialTemperature, fMinTemperature, fEps, fKernelTemperatureS,
136  fTemperatureScale, fAdaptiveSpeed, fTemperatureAdaptiveStep,
137  fUseDefaultScale, fUseDefaultTemperature );
138  // minimise
139  Double_t fcn = sa.Minimize( pars );
140 
141  return fcn;
142 }
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void DeclareOptions()
declare SA options
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
STL namespace.
Double_t Run()
estimator function interface for fitting
Definition: FitterBase.cxx:73
ClassImp(TMVA::SimulatedAnnealingFitter) TMVA
constructor
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
double Double_t
Definition: RtypesCore.h:55
void AddPreDefVal(const T &)
Definition: Configurable.h:177
#define name(a, b)
Definition: linkTestLib0.cpp:5
Abstract ClassifierFactory template that handles arbitrary types.
Double_t Minimize(std::vector< Double_t > &parameters)
minimisation algorithm
Definition: math.cpp:60