Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
31Fitter 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
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;
79 fInitialTemperature = 1e+6;
80 fMinTemperature = 1e-6;
81 fEps = 1e-10;
82 fTemperatureScale = 1.0;
83 fAdaptiveSpeed = 1.0;
84 fTemperatureAdaptiveStep = 0.009875;
85 fKernelTemperatureS = "IncAdaptive";
86 fUseDefaultScale = kFALSE;
87 fUseDefaultTemperature = kFALSE;
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
136Double_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
141 SimulatedAnnealing sa( GetFitterTarget(), fRanges );
142
143 // set driving parameters
144 sa.SetOptions( fMaxCalls, fInitialTemperature, fMinTemperature, fEps, fKernelTemperatureS,
145 fTemperatureScale, fAdaptiveSpeed, fTemperatureAdaptiveStep,
146 fUseDefaultScale, fUseDefaultTemperature );
147
148 if (fIPyMaxIter){
149 *fIPyMaxIter = fMaxCalls;
150 sa.SetIPythonInteractive(fExitFromTraining, fIPyCurrentIter);
151 }
152 // minimise
153 Double_t fcn = sa.Minimize( pars );
154
155 return fcn;
156}
#define e(i)
Definition RSha256.hxx:103
const Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
#define ClassImp(name)
Definition Rtypes.h:364
char name[80]
Definition TGX11.cxx:110
virtual void ParseOptions()
options parser
Base class for TMVA fitters.
Definition FitterBase.h:51
Double_t Run()
estimator function interface for fitting
Interface for a fitter 'target'.
Fitter using a Simulated Annealing Algorithm.
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
SimulatedAnnealingFitter(IFitterTarget &target, const TString &name, const std::vector< TMVA::Interval * > &ranges, const TString &theOption)
constructor
Base implementation of simulated annealing fitting procedure.
Double_t Minimize(std::vector< Double_t > &parameters)
minimisation algorithm
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 SetIPythonInteractive(bool *ExitFromTraining, UInt_t *fIPyCurrentIter_)
Basic string class.
Definition TString.h:136
create variable transformations
MsgLogger & Endl(MsgLogger &ml)
Definition MsgLogger.h:148