1 |
kukartse |
1.1 |
// @(#)root/tmva $Id: TMVAnalysis.C,v 1.11 2007/06/19 13:26:21 brun Exp $
|
2 |
|
|
/**********************************************************************************
|
3 |
|
|
* Project : TMVA - a Root-integrated toolkit for multivariate data analysis *
|
4 |
|
|
* Package : TMVA *
|
5 |
|
|
* Root Macro: TMVAnalysis *
|
6 |
|
|
* *
|
7 |
|
|
* This macro provides examples for the training and testing of all the *
|
8 |
|
|
* TMVA classifiers. *
|
9 |
|
|
* *
|
10 |
|
|
* As input data is used a toy-MC sample consisting of four Gaussian-distributed *
|
11 |
|
|
* and linearly correlated input variables. *
|
12 |
|
|
* *
|
13 |
|
|
* The methods to be used can be switched on and off by means of booleans, or *
|
14 |
|
|
* via the prompt command, for example: *
|
15 |
|
|
* *
|
16 |
|
|
* root -l TMVAnalysis.C\(\"Fisher,Likelihood\"\) *
|
17 |
|
|
* *
|
18 |
|
|
* (note that the backslashes are mandatory) *
|
19 |
|
|
* *
|
20 |
|
|
* The output file "TMVA.root" can be analysed with the use of dedicated *
|
21 |
|
|
* macros (simply say: root -l <macro.C>), which can be conveniently *
|
22 |
|
|
* invoked through a GUI that will appear at the end of the run of this macro. *
|
23 |
|
|
**********************************************************************************/
|
24 |
|
|
|
25 |
|
|
#include <iostream>
|
26 |
|
|
|
27 |
|
|
#include "TCut.h"
|
28 |
|
|
#include "TFile.h"
|
29 |
|
|
#include "TSystem.h"
|
30 |
|
|
#include "TTree.h"
|
31 |
|
|
// requires links
|
32 |
|
|
// #include "TMVA/Factory.h"
|
33 |
|
|
// #include "TMVA/Tools.h"
|
34 |
|
|
// #include "TMVA/Config.h"
|
35 |
|
|
|
36 |
|
|
#include "TMVAGui.C"
|
37 |
|
|
|
38 |
|
|
// ---------------------------------------------------------------
|
39 |
|
|
// choose MVA methods to be trained + tested
|
40 |
|
|
Bool_t Use_Cuts = 0;
|
41 |
|
|
Bool_t Use_CutsD = 0;
|
42 |
|
|
Bool_t Use_CutsGA = 1;
|
43 |
|
|
// ---
|
44 |
|
|
Bool_t Use_Likelihood = 1;
|
45 |
|
|
Bool_t Use_LikelihoodD = 0; // the "D" extension indicates decorrelated input variables (see option strings)
|
46 |
|
|
Bool_t Use_LikelihoodPCA = 1; // the "PCA" extension indicates PCA-transformed input variables (see option strings)
|
47 |
|
|
Bool_t Use_LikelihoodKDE = 0;
|
48 |
|
|
Bool_t Use_LikelihoodMIX = 0;
|
49 |
|
|
// ---
|
50 |
|
|
Bool_t Use_PDERS = 1;
|
51 |
|
|
Bool_t Use_PDERSD = 0;
|
52 |
|
|
Bool_t Use_PDERSPCA = 0;
|
53 |
|
|
Bool_t Use_KNN = 1;
|
54 |
|
|
// ---
|
55 |
|
|
Bool_t Use_HMatrix = 1;
|
56 |
|
|
Bool_t Use_Fisher = 1;
|
57 |
|
|
// ---
|
58 |
|
|
Bool_t Use_FDA_GA = 0;
|
59 |
|
|
Bool_t Use_FDA_MC = 0;
|
60 |
|
|
Bool_t Use_FDA_SA = 0;
|
61 |
|
|
Bool_t Use_FDA_MT = 1;
|
62 |
|
|
Bool_t Use_FDA_GAMT = 0;
|
63 |
|
|
Bool_t Use_FDA_MCMT = 0;
|
64 |
|
|
// ---
|
65 |
|
|
Bool_t Use_MLP = 1; // this is the recommended ANN
|
66 |
|
|
Bool_t Use_CFMlpANN = 0;
|
67 |
|
|
Bool_t Use_TMlpANN = 0;
|
68 |
|
|
// ---
|
69 |
|
|
Bool_t Use_BDT = 1;
|
70 |
|
|
Bool_t Use_BDTD = 0;
|
71 |
|
|
// ---
|
72 |
|
|
Bool_t Use_RuleFitTMVA = 1;
|
73 |
|
|
Bool_t Use_RuleFitJF = 0;
|
74 |
|
|
// ---
|
75 |
|
|
Bool_t Use_SVM_Gauss = 1;
|
76 |
|
|
Bool_t Use_SVM_Poly = 0;
|
77 |
|
|
Bool_t Use_SVM_Lin = 0;
|
78 |
|
|
// ---------------------------------------------------------------
|
79 |
|
|
|
80 |
|
|
// read input data file with ascii format (otherwise ROOT) ?
|
81 |
|
|
Bool_t ReadDataFromAsciiIFormat = kFALSE;
|
82 |
|
|
|
83 |
|
|
void TMVAnalysis( TString myMethodList = "" )
|
84 |
|
|
{
|
85 |
|
|
// explicit loading of the shared libTMVA is done in TMVAlogon.C, defined in .rootrc
|
86 |
|
|
// if you use your private .rootrc, or run from a different directory, please copy the
|
87 |
|
|
// corresponding lines from .rootrc
|
88 |
|
|
|
89 |
|
|
// methods to be processed can be given as an argument; use format:
|
90 |
|
|
//
|
91 |
|
|
// mylinux~> root -l TMVAnalysis.C\(\"myMethod1,myMethod2,myMethod3\"\)
|
92 |
|
|
//
|
93 |
|
|
TList* mlist = TMVA::Tools::ParseFormatLine( myMethodList, " :," );
|
94 |
|
|
|
95 |
|
|
if (mlist->GetSize()>0) {
|
96 |
|
|
Use_CutsGA = Use_CutsD = Use_Cuts
|
97 |
|
|
= Use_LikelihoodKDE = Use_LikelihoodMIX = Use_LikelihoodPCA = Use_LikelihoodD = Use_Likelihood
|
98 |
|
|
= Use_PDERSPCA = Use_PDERSD = Use_PDERS
|
99 |
|
|
= Use_KNN
|
100 |
|
|
= Use_MLP = Use_CFMlpANN = Use_TMlpANN
|
101 |
|
|
= Use_HMatrix = Use_Fisher = Use_BDTD = Use_BDT
|
102 |
|
|
= Use_RuleFitTMVA = Use_RuleFitJF
|
103 |
|
|
= Use_SVM_Gauss = Use_SVM_Poly = Use_SVM_Lin
|
104 |
|
|
= Use_FDA_GA = Use_FDA_MC = Use_FDA_SA = Use_FDA_MT = Use_FDA_GAMT = Use_FDA_MCMT
|
105 |
|
|
= 0;
|
106 |
|
|
|
107 |
|
|
if (mlist->FindObject( "Cuts" ) != 0) Use_Cuts = 1;
|
108 |
|
|
if (mlist->FindObject( "CutsD" ) != 0) Use_CutsD = 1;
|
109 |
|
|
if (mlist->FindObject( "CutsGA" ) != 0) Use_CutsGA = 1;
|
110 |
|
|
if (mlist->FindObject( "Likelihood" ) != 0) Use_Likelihood = 1;
|
111 |
|
|
if (mlist->FindObject( "LikelihoodD" ) != 0) Use_LikelihoodD = 1;
|
112 |
|
|
if (mlist->FindObject( "LikelihoodPCA" ) != 0) Use_LikelihoodPCA = 1;
|
113 |
|
|
if (mlist->FindObject( "LikelihoodKDE" ) != 0) Use_LikelihoodKDE = 1;
|
114 |
|
|
if (mlist->FindObject( "LikelihoodMIX" ) != 0) Use_LikelihoodMIX = 1;
|
115 |
|
|
if (mlist->FindObject( "PDERSPCA" ) != 0) Use_PDERSPCA = 1;
|
116 |
|
|
if (mlist->FindObject( "PDERSD" ) != 0) Use_PDERSD = 1;
|
117 |
|
|
if (mlist->FindObject( "PDERS" ) != 0) Use_PDERS = 1;
|
118 |
|
|
if (mlist->FindObject( "KNN" ) != 0) Use_KNN = 1;
|
119 |
|
|
if (mlist->FindObject( "HMatrix" ) != 0) Use_HMatrix = 1;
|
120 |
|
|
if (mlist->FindObject( "Fisher" ) != 0) Use_Fisher = 1;
|
121 |
|
|
if (mlist->FindObject( "MLP" ) != 0) Use_MLP = 1;
|
122 |
|
|
if (mlist->FindObject( "CFMlpANN" ) != 0) Use_CFMlpANN = 1;
|
123 |
|
|
if (mlist->FindObject( "TMlpANN" ) != 0) Use_TMlpANN = 1;
|
124 |
|
|
if (mlist->FindObject( "BDTD" ) != 0) Use_BDTD = 1;
|
125 |
|
|
if (mlist->FindObject( "BDT" ) != 0) Use_BDT = 1;
|
126 |
|
|
if (mlist->FindObject( "RuleFitJF" ) != 0) Use_RuleFitJF = 1;
|
127 |
|
|
if (mlist->FindObject( "RuleFitTMVA" ) != 0) Use_RuleFitTMVA = 1;
|
128 |
|
|
if (mlist->FindObject( "SVM_Gauss" ) != 0) Use_SVM_Gauss = 1;
|
129 |
|
|
if (mlist->FindObject( "SVM_Poly" ) != 0) Use_SVM_Poly = 1;
|
130 |
|
|
if (mlist->FindObject( "SVM_Lin" ) != 0) Use_SVM_Lin = 1;
|
131 |
|
|
if (mlist->FindObject( "FDA_MC" ) != 0) Use_FDA_MC = 1;
|
132 |
|
|
if (mlist->FindObject( "FDA_GA" ) != 0) Use_FDA_GA = 1;
|
133 |
|
|
if (mlist->FindObject( "FDA_SA" ) != 0) Use_FDA_SA = 1;
|
134 |
|
|
if (mlist->FindObject( "FDA_MT" ) != 0) Use_FDA_MT = 1;
|
135 |
|
|
if (mlist->FindObject( "FDA_GAMT" ) != 0) Use_FDA_GAMT = 1;
|
136 |
|
|
if (mlist->FindObject( "FDA_MCMT" ) != 0) Use_FDA_MCMT = 1;
|
137 |
|
|
|
138 |
|
|
delete mlist;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
std::cout << "Start Test TMVAnalysis" << std::endl
|
142 |
|
|
<< "======================" << std::endl
|
143 |
|
|
<< std::endl;
|
144 |
|
|
std::cout << "Testing all standard methods may take about 10 minutes of running..." << std::endl;
|
145 |
|
|
|
146 |
|
|
// Create a new root output file.
|
147 |
|
|
TString outfileName( "TMVA.root" );
|
148 |
|
|
TFile* outputFile = TFile::Open( outfileName, "RECREATE" );
|
149 |
|
|
|
150 |
|
|
// Create the factory object. Later you can choose the methods
|
151 |
|
|
// whose performance you'd like to investigate. The factory will
|
152 |
|
|
// then run the performance analysis for you.
|
153 |
|
|
//
|
154 |
|
|
// The first argument is the base of the name of all the
|
155 |
|
|
// weightfiles in the directory weight/
|
156 |
|
|
//
|
157 |
|
|
// The second argument is the output file for the training results
|
158 |
|
|
TMVA::Factory *factory = new TMVA::Factory( "TMVAnalysis", outputFile, Form("!V:%sColor", gROOT->IsBatch()?"!":"") );
|
159 |
|
|
|
160 |
|
|
// if you wish to modify default settings
|
161 |
|
|
// (please check "src/Config.h" to see all available global options)
|
162 |
|
|
// (TMVA::gConfig().GetVariablePlotting()).fTimesRMS = 8.0;
|
163 |
|
|
// (TMVA::gConfig().GetIONames()).fWeightFileDir = "myWeightDirectory";
|
164 |
|
|
|
165 |
|
|
if (ReadDataFromAsciiIFormat) {
|
166 |
|
|
// load the signal and background event samples from ascii files
|
167 |
|
|
// format in file must be:
|
168 |
|
|
// var1/F:var2/F:var3/F:var4/F
|
169 |
|
|
// 0.04551 0.59923 0.32400 -0.19170
|
170 |
|
|
// ...
|
171 |
|
|
|
172 |
|
|
TString datFileS = "data/toy_sig_lincorr.dat";
|
173 |
|
|
TString datFileB = "data/toy_bkg_lincorr.dat";
|
174 |
|
|
if (!factory->SetInputTrees( datFileS, datFileB )) exit(1);
|
175 |
|
|
}
|
176 |
|
|
else {
|
177 |
|
|
// load the signal and background event samples from ROOT trees
|
178 |
|
|
TFile *input(0);
|
179 |
|
|
TString fname = "./tmva_example.root";
|
180 |
|
|
if (!gSystem->AccessPathName( fname )) {
|
181 |
|
|
// first we try to find tmva_example.root in the local directory
|
182 |
|
|
std::cout << "--- TMVAnalysis : accessing " << fname << std::endl;
|
183 |
|
|
input = TFile::Open( fname );
|
184 |
|
|
}
|
185 |
|
|
else {
|
186 |
|
|
// second we try accessing the file via the web from
|
187 |
|
|
// http://root.cern.ch/files/tmva_example.root
|
188 |
|
|
std::cout << "--- TMVAnalysis : accessing tmva_example.root file from http://root.cern.ch/files" << std::endl;
|
189 |
|
|
std::cout << "--- TMVAnalysis : for faster startup you may consider downloading it into you local directory" << std::endl;
|
190 |
|
|
input = TFile::Open( "http://root.cern.ch/files/tmva_example.root" );
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
if (!input) {
|
194 |
|
|
std::cout << "ERROR: could not open data file" << std::endl;
|
195 |
|
|
exit(1);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
TTree *signal = (TTree*)input->Get("TreeS");
|
199 |
|
|
TTree *background = (TTree*)input->Get("TreeB");
|
200 |
|
|
|
201 |
|
|
// global event weights (see below for setting event-wise weights)
|
202 |
|
|
Double_t signalWeight = 1.0;
|
203 |
|
|
Double_t backgroundWeight = 1.0;
|
204 |
|
|
|
205 |
|
|
factory->AddSignalTree ( signal, signalWeight );
|
206 |
|
|
factory->AddBackgroundTree( background, backgroundWeight );
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
// Define the input variables that shall be used for the MVA training
|
210 |
|
|
// note that you may also use variable expressions, such as: "3*var1/var2*abs(var3)"
|
211 |
|
|
// [all types of expressions that can also be parsed by TTree::Draw( "expression" )]
|
212 |
|
|
factory->AddVariable("var1+var2", 'F');
|
213 |
|
|
factory->AddVariable("var1-var2", 'F');
|
214 |
|
|
factory->AddVariable("var3", 'F');
|
215 |
|
|
factory->AddVariable("var4", 'F');
|
216 |
|
|
|
217 |
|
|
// This would set individual event weights (the variables defined in the
|
218 |
|
|
// expression need to exist in the original TTree)
|
219 |
|
|
// factory->SetWeightExpression("weight1*weight2");
|
220 |
|
|
|
221 |
|
|
// Apply additional cuts on the signal and background sample.
|
222 |
|
|
TCut mycut = ""; // for example: TCut mycut = "abs(var1)<0.5 && abs(var2-0.5)<1";
|
223 |
|
|
|
224 |
|
|
// tell the factory to use all remaining events in the trees after training for testing:
|
225 |
|
|
factory->PrepareTrainingAndTestTree( mycut, "NSigTrain=3000:NBkgTrain=3000:SplitMode=Random:NormMode=NumEvents:!V" );
|
226 |
|
|
|
227 |
|
|
// If no numbers of events are given, half of the events in the tree are used for training, and
|
228 |
|
|
// the other half for testing:
|
229 |
|
|
// factory->PrepareTrainingAndTestTree( mycut, "SplitMode=random:!V" );
|
230 |
|
|
// To also specify the number of testing events, use:
|
231 |
|
|
// factory->PrepareTrainingAndTestTree( mycut,
|
232 |
|
|
// "NSigTrain=3000:NBkgTrain=3000:NSigTest=3000:NBkgTest=3000:SplitMode=Random:!V" );
|
233 |
|
|
|
234 |
|
|
// ---- Book MVA methods
|
235 |
|
|
//
|
236 |
|
|
// please lookup the various method configuration options in the corresponding cxx files, eg:
|
237 |
|
|
// src/MethoCuts.cxx, etc.
|
238 |
|
|
// it is possible to preset ranges in the option string in which the cut optimisation should be done:
|
239 |
|
|
// "...:CutRangeMin[2]=-1:CutRangeMax[2]=1"...", where [2] is the third input variable
|
240 |
|
|
|
241 |
|
|
// Cut optimisation
|
242 |
|
|
if (Use_Cuts)
|
243 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "Cuts",
|
244 |
|
|
"!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart" );
|
245 |
|
|
|
246 |
|
|
if (Use_CutsD)
|
247 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsD",
|
248 |
|
|
"!H:!V:FitMethod=MC:EffSel:SampleSize=200000:VarProp=FSmart:VarTransform=Decorrelate" );
|
249 |
|
|
|
250 |
|
|
if (Use_CutsGA)
|
251 |
|
|
factory->BookMethod( TMVA::Types::kCuts, "CutsGA",
|
252 |
|
|
"!H:!V:FitMethod=GA:EffSel:Steps=30:Cycles=3:PopSize=100:SC_steps=10:SC_rate=5:SC_factor=0.95:VarProp=FSmart" );
|
253 |
|
|
|
254 |
|
|
// Likelihood
|
255 |
|
|
if (Use_Likelihood)
|
256 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "Likelihood",
|
257 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=100:NSmoothBkg[0]=10:NSmoothBkg[1]=100:NSmooth=10:NAvEvtPerBin=50" );
|
258 |
|
|
|
259 |
|
|
// test the decorrelated likelihood
|
260 |
|
|
if (Use_LikelihoodD)
|
261 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodD",
|
262 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=100:NSmoothBkg[0]=10:NSmooth=5:NAvEvtPerBin=50:VarTransform=Decorrelate" );
|
263 |
|
|
|
264 |
|
|
if (Use_LikelihoodPCA)
|
265 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodPCA",
|
266 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=Spline2:NSmoothSig[0]=100:NSmoothBkg[0]=10:NSmooth=5:NAvEvtPerBin=50:VarTransform=PCA" );
|
267 |
|
|
|
268 |
|
|
// test the new kernel density estimator
|
269 |
|
|
if (Use_LikelihoodKDE)
|
270 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodKDE",
|
271 |
|
|
"!H:!V:!TransformOutput:PDFInterpol=KDE:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" );
|
272 |
|
|
|
273 |
|
|
// test the mixed splines and kernel density estimator (depending on which variable)
|
274 |
|
|
if (Use_LikelihoodMIX)
|
275 |
|
|
factory->BookMethod( TMVA::Types::kLikelihood, "LikelihoodMIX",
|
276 |
|
|
"!H:!V:!TransformOutput:PDFInterpol[0]=KDE:PDFInterpol[1]=KDE:PDFInterpol[2]=Spline2:PDFInterpol[3]=Spline2:KDEtype=Gauss:KDEiter=Nonadaptive:KDEborder=None:NAvEvtPerBin=50" );
|
277 |
|
|
|
278 |
|
|
// PDE - RS method
|
279 |
|
|
if (Use_PDERS)
|
280 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERS",
|
281 |
|
|
"!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99" );
|
282 |
|
|
|
283 |
|
|
if (Use_PDERSD)
|
284 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERSD",
|
285 |
|
|
"!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99:VarTransform=Decorrelate" );
|
286 |
|
|
|
287 |
|
|
if (Use_PDERSPCA)
|
288 |
|
|
factory->BookMethod( TMVA::Types::kPDERS, "PDERSPCA",
|
289 |
|
|
"!H:!V:VolumeRangeMode=Adaptive:KernelEstimator=Gauss:GaussSigma=0.3:NEventsMin=400:NEventsMax=600:InitialScale=0.99:VarTransform=PCA" );
|
290 |
|
|
|
291 |
|
|
// K-Nearest Neighbour classifier (KNN)
|
292 |
|
|
if (Use_KNN)
|
293 |
|
|
factory->BookMethod( TMVA::Types::kKNN, "KNN",
|
294 |
|
|
"nkNN=40:TreeOptDepth=6:ScaleFrac=0.8:!UseKernel:!Trim" );
|
295 |
|
|
|
296 |
|
|
// H-Matrix (chi2-squared) method
|
297 |
|
|
if (Use_HMatrix)
|
298 |
|
|
factory->BookMethod( TMVA::Types::kHMatrix, "HMatrix", "!H:!V" );
|
299 |
|
|
|
300 |
|
|
// Fisher discriminant
|
301 |
|
|
if (Use_Fisher)
|
302 |
|
|
factory->BookMethod( TMVA::Types::kFisher, "Fisher",
|
303 |
|
|
"H:!V:!Normalise:CreateMVAPdfs:Fisher:NbinsMVAPdf=50:NsmoothMVAPdf=1" );
|
304 |
|
|
|
305 |
|
|
// Function discrimination analysis (FDA) -- test of various fitters - the recommended one is Minuit or GA
|
306 |
|
|
if (Use_FDA_MC)
|
307 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MC",
|
308 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:SampleSize=100000:Sigma=0.1" );
|
309 |
|
|
|
310 |
|
|
if (Use_FDA_GA)
|
311 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_GA",
|
312 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:PopSize=100:Cycles=3:Steps=20:Trim=True:SaveBestGen=0" );
|
313 |
|
|
|
314 |
|
|
if (Use_FDA_SA)
|
315 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_SA",
|
316 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=SA:MaxCalls=50000:TemperatureGradient=0.7:InitialTemperature=2000000:MinTemperature=500:Eps=1e-04:NFunLoops=5:NEps=4" );
|
317 |
|
|
|
318 |
|
|
if (Use_FDA_MT)
|
319 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MT",
|
320 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=2:UseImprove:UseMinos:SetBatch" );
|
321 |
|
|
|
322 |
|
|
if (Use_FDA_GAMT)
|
323 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_GAMT",
|
324 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=GA:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:Cycles=1:PopSize=5:Steps=5:Trim" );
|
325 |
|
|
|
326 |
|
|
if (Use_FDA_MCMT)
|
327 |
|
|
factory->BookMethod( TMVA::Types::kFDA, "FDA_MCMT",
|
328 |
|
|
"H:!V:Formula=(0)+(1)*x0+(2)*x1+(3)*x2+(4)*x3:ParRanges=(-1,1);(-10,10);(-10,10);(-10,10);(-10,10):FitMethod=MC:Converger=MINUIT:ErrorLevel=1:PrintLevel=-1:FitStrategy=0:!UseImprove:!UseMinos:SetBatch:SampleSize=20" );
|
329 |
|
|
|
330 |
|
|
// TMVA ANN: MLP (recommended ANN) -- all ANNs in TMVA are Multilayer Perceptrons
|
331 |
|
|
if (Use_MLP)
|
332 |
|
|
factory->BookMethod( TMVA::Types::kMLP, "MLP", "Normalise:H:!V:NCycles=200:HiddenLayers=N+1,N:TestRate=5" );
|
333 |
|
|
|
334 |
|
|
// CF(Clermont-Ferrand)ANN
|
335 |
|
|
if (Use_CFMlpANN)
|
336 |
|
|
factory->BookMethod( TMVA::Types::kCFMlpANN, "CFMlpANN", "!H:!V:NCycles=500:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
|
337 |
|
|
|
338 |
|
|
// Tmlp(Root)ANN
|
339 |
|
|
if (Use_TMlpANN)
|
340 |
|
|
factory->BookMethod( TMVA::Types::kTMlpANN, "TMlpANN", "!H:!V:NCycles=200:HiddenLayers=N+1,N" ); // n_cycles:#nodes:#nodes:...
|
341 |
|
|
|
342 |
|
|
// Support Vector Machines using three different Kernel types (Gauss, polynomial and linear)
|
343 |
|
|
if (Use_SVM_Gauss)
|
344 |
|
|
factory->BookMethod( TMVA::Types::kSVM, "SVM_Gauss", "Sigma=2:C=1:Tol=0.001:Kernel=Gauss" );
|
345 |
|
|
|
346 |
|
|
if (Use_SVM_Poly)
|
347 |
|
|
factory->BookMethod( TMVA::Types::kSVM, "SVM_Poly", "Order=4:Theta=1:C=0.1:Tol=0.001:Kernel=Polynomial" );
|
348 |
|
|
|
349 |
|
|
if (Use_SVM_Lin)
|
350 |
|
|
factory->BookMethod( TMVA::Types::kSVM, "SVM_Lin", "!H:!V:Kernel=Linear:C=1:Tol=0.001" );
|
351 |
|
|
|
352 |
|
|
// Boosted Decision Trees (second one with decorrelation)
|
353 |
|
|
if (Use_BDT)
|
354 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDT",
|
355 |
|
|
"!H:!V:NTrees=400:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=CostComplexity:PruneStrength=4.5" );
|
356 |
|
|
if (Use_BDTD)
|
357 |
|
|
factory->BookMethod( TMVA::Types::kBDT, "BDTD",
|
358 |
|
|
"!H:!V:NTrees=400:BoostType=AdaBoost:SeparationType=GiniIndex:nCuts=20:PruneMethod=CostComplexity:PruneStrength=4.5:VarTransform=Decorrelate" );
|
359 |
|
|
|
360 |
|
|
// RuleFit -- TMVA implementation of Friedman's method
|
361 |
|
|
if (Use_RuleFitTMVA)
|
362 |
|
|
factory->BookMethod( TMVA::Types::kRuleFit, "RuleFitTMVA",
|
363 |
|
|
"H:!V:RuleFitModule=RFTMVA:Model=ModRuleLinear:MinImp=0.001:RuleMinDist=0.001:NTrees=20:fEventsMin=0.01:fEventsMax=0.5:GDTau=-1.0:GDTauPrec=0.01:GDStep=0.01:GDNSteps=10000:GDErrScale=1.02" );
|
364 |
|
|
|
365 |
|
|
// Friedman's RuleFit method, implementation by J. Friedman
|
366 |
|
|
if (Use_RuleFitJF)
|
367 |
|
|
factory->BookMethod( TMVA::Types::kRuleFit, "RuleFitJF",
|
368 |
|
|
"!V:RuleFitModule=RFFriedman:Model=ModRuleLinear:GDStep=0.01:GDNSteps=10000:GDErrScale=1.1:RFNendnodes=4" );
|
369 |
|
|
|
370 |
|
|
// ---- Now you can tell the factory to train, test, and evaluate the MVAs
|
371 |
|
|
|
372 |
|
|
// Train MVAs using the set of training events
|
373 |
|
|
factory->TrainAllMethods();
|
374 |
|
|
|
375 |
|
|
// ---- Evaluate all MVAs using the set of test events
|
376 |
|
|
factory->TestAllMethods();
|
377 |
|
|
|
378 |
|
|
// ----- Evaluate and compare performance of all configured MVAs
|
379 |
|
|
factory->EvaluateAllMethods();
|
380 |
|
|
|
381 |
|
|
// --------------------------------------------------------------
|
382 |
|
|
|
383 |
|
|
// Save the output
|
384 |
|
|
outputFile->Close();
|
385 |
|
|
|
386 |
|
|
std::cout << "==> wrote root file TMVA.root" << std::endl;
|
387 |
|
|
std::cout << "==> TMVAnalysis is done!" << std::endl;
|
388 |
|
|
|
389 |
|
|
// Clean up
|
390 |
|
|
delete factory;
|
391 |
|
|
|
392 |
|
|
// Launch the GUI for the root macros
|
393 |
|
|
if (!gROOT->IsBatch()) TMVAGui( outfileName );
|
394 |
|
|
}
|