112 fModelPersistence(
kTRUE)
144 DeclareOptionRef(color,
"Color",
"Flag for coloured screen output (default: True, if in batch mode: False)");
147 "List of transformations to test; formatting example: \"Transformations=I;D;P;U;G,D\", for identity, "
148 "decorrelation, PCA, Uniform and Gaussianisation followed by decorrelation transformations");
152 "Batch mode: boolean silent flag inhibiting any output from TMVA after the creation of the factory "
153 "class object (default: False)");
155 "Draw progress bar to display training, testing and evaluation schedule (default: True)");
157 "Option to save the trained model in xml file or using serialization");
161 "Set the analysis type (Classification, Regression, Multiclass, Auto) (default: Auto)");
185 if (analysisType ==
"classification")
187 else if (analysisType ==
"regression")
189 else if (analysisType ==
"multiclass")
191 else if (analysisType ==
"auto")
234 DeclareOptionRef(color,
"Color",
"Flag for coloured screen output (default: True, if in batch mode: False)");
237 "List of transformations to test; formatting example: \"Transformations=I;D;P;U;G,D\", for identity, "
238 "decorrelation, PCA, Uniform and Gaussianisation followed by decorrelation transformations");
242 "Batch mode: boolean silent flag inhibiting any output from TMVA after the creation of the factory "
243 "class object (default: False)");
245 "Draw progress bar to display training, testing and evaluation schedule (default: True)");
247 "Option to save the trained model in xml file or using serialization");
251 "Set the analysis type (Classification, Regression, Multiclass, Auto) (default: Auto)");
275 if (analysisType ==
"classification")
277 else if (analysisType ==
"regression")
279 else if (analysisType ==
"multiclass")
281 else if (analysisType ==
"auto")
304 std::vector<TMVA::VariableTransformBase *>::iterator
trfIt = fDefaultTrfs.
begin();
308 this->DeleteAllMethods();
322 std::map<TString, MVector *>::iterator
itrMap;
329 Log() << kDEBUG <<
"Delete method: " << (*itrMethod)->GetName() <<
Endl;
357 if (fModelPersistence)
363 if (
loader->GetDataSetInfo().GetNClasses() == 2 &&
loader->GetDataSetInfo().GetClassInfo(
"Signal") !=
NULL &&
364 loader->GetDataSetInfo().GetClassInfo(
"Background") !=
NULL) {
366 }
else if (
loader->GetDataSetInfo().GetNClasses() >= 2) {
369 Log() << kFATAL <<
"No analysis type for " <<
loader->GetDataSetInfo().GetNClasses() <<
" classes and "
370 <<
loader->GetDataSetInfo().GetNTargets() <<
" regression targets." <<
Endl;
376 if (fMethodsMap.find(
datasetname) != fMethodsMap.end()) {
378 Log() << kFATAL <<
"Booking failed since method with title <" << methodTitle <<
"> already exists "
379 <<
"in with DataSet Name <" <<
loader->GetName() <<
"> " <<
Endl;
383 Log() << kHEADER <<
"Booking method: " <<
gTools().
Color(
"bold")
391 conf->DeclareOptionRef(
boostNum = 0,
"Boost_num",
"Number of times the classifier will be boosted");
392 conf->ParseOptions();
396 if (fModelPersistence) {
413 Log() << kDEBUG <<
"Boost Number is " <<
boostNum <<
" > 0: train boosted classifier" <<
Endl;
417 Log() << kFATAL <<
"Method with type kBoost cannot be casted to MethodCategory. /Factory" <<
Endl;
420 if (fModelPersistence)
422 methBoost->SetModelPersistence(fModelPersistence);
424 methBoost->fDataSetManager =
loader->GetDataSetInfo().GetDataSetManager();
426 methBoost->SetSilentFile(IsSilentFile());
437 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Factory"
441 if (fModelPersistence)
443 methCat->SetModelPersistence(fModelPersistence);
444 methCat->fDataSetManager =
loader->GetDataSetInfo().GetDataSetManager();
445 methCat->SetFile(fgTargetFile);
446 methCat->SetSilentFile(IsSilentFile());
449 if (!
method->HasAnalysisType(fAnalysisType,
loader->GetDataSetInfo().GetNClasses(),
450 loader->GetDataSetInfo().GetNTargets())) {
451 Log() << kWARNING <<
"Method " <<
method->GetMethodTypeName() <<
" is not capable of handling ";
453 Log() <<
"regression with " <<
loader->GetDataSetInfo().GetNTargets() <<
" targets." <<
Endl;
455 Log() <<
"multiclass classification with " <<
loader->GetDataSetInfo().GetNClasses() <<
" classes." <<
Endl;
457 Log() <<
"classification with " <<
loader->GetDataSetInfo().GetNClasses() <<
" classes." <<
Endl;
462 if (fModelPersistence)
464 method->SetModelPersistence(fModelPersistence);
465 method->SetAnalysisType(fAnalysisType);
469 method->SetFile(fgTargetFile);
470 method->SetSilentFile(IsSilentFile());
475 if (fMethodsMap.find(
datasetname) == fMethodsMap.end()) {
505 Log() << kERROR <<
"Cannot handle category methods for now." <<
Endl;
509 if (fModelPersistence) {
520 if (fModelPersistence)
522 method->SetModelPersistence(fModelPersistence);
523 method->SetAnalysisType(fAnalysisType);
525 method->SetFile(fgTargetFile);
526 method->SetSilentFile(IsSilentFile());
528 method->DeclareCompatibilityOptions();
531 method->ReadStateFromFile();
537 Log() << kFATAL <<
"Booking failed since method with title <" << methodTitle <<
"> already exists "
538 <<
"in with DataSet Name <" <<
loader->GetName() <<
"> " <<
Endl;
541 Log() << kINFO <<
"Booked classifier \"" <<
method->GetMethodName() <<
"\" of type: \""
542 <<
method->GetMethodTypeName() <<
"\"" <<
Endl;
559 if (fMethodsMap.find(
datasetname) == fMethodsMap.end())
568 if ((
mva->GetMethodName()) == methodTitle)
579 if (fMethodsMap.find(
datasetname) == fMethodsMap.end())
582 std::string methodName = methodTitle.
Data();
597 if (!RootBaseDir()->GetDirectory(fDataSetInfo.
GetName()))
598 RootBaseDir()->mkdir(fDataSetInfo.
GetName());
602 RootBaseDir()->cd(fDataSetInfo.
GetName());
651 std::vector<TMVA::TransformationHandler *>
trfs;
661 Log() << kDEBUG <<
"current transformation string: '" <<
trfS.Data() <<
"'" <<
Endl;
664 if (
trfS.BeginsWith(
'I'))
671 std::vector<TMVA::TransformationHandler *>::iterator
trfIt =
trfs.
begin();
675 (*trfIt)->SetRootDir(RootBaseDir()->GetDirectory(fDataSetInfo.
GetName()));
695 std::map<TString, MVector *>::iterator
itrMap;
707 Log() << kFATAL <<
"Dynamic cast to MethodBase failed" <<
Endl;
712 Log() << kWARNING <<
"Method " <<
mva->GetMethodName() <<
" not trained (training tree has less entries ["
717 Log() << kINFO <<
"Optimize method: " <<
mva->GetMethodName() <<
" for "
720 : (fAnalysisType ==
Types::kMulticlass ?
"Multiclass classification" :
"Classification"))
724 Log() << kINFO <<
"Optimization of tuning parameters finished for Method:" <<
mva->GetName() <<
Endl;
755 if (fMethodsMap.find(
datasetname) == fMethodsMap.end()) {
756 Log() << kERROR <<
Form(
"DataSet = %s not found in methods map.",
datasetname.Data()) <<
Endl;
768 Log() << kERROR <<
Form(
"Can only generate ROC curves for analysis type kClassification and kMulticlass.")
781 <<
Form(
"Given class number (iClass = %i) does not exist. There are %i classes in dataset.",
iClass,
803 std::vector<Float_t>
mvaRes;
855 if (fMethodsMap.find(
datasetname) == fMethodsMap.end()) {
856 Log() << kERROR <<
Form(
"DataSet = %s not found in methods map.",
datasetname.Data()) <<
Endl;
868 Log() << kERROR <<
Form(
"Can only generate ROC integral for analysis type kClassification. and kMulticlass.")
876 <<
Form(
"ROCCurve object was not created in Method = %s not found with Dataset = %s ",
theMethodName.Data(),
926 if (fMethodsMap.find(
datasetname) == fMethodsMap.end()) {
927 Log() << kERROR <<
Form(
"DataSet = %s not found in methods map.",
datasetname.Data()) <<
Endl;
939 Log() << kERROR <<
Form(
"Can only generate ROC curves for analysis type kClassification and kMulticlass.")
949 <<
Form(
"ROCCurve object was not created in Method = %s not found with Dataset = %s ",
theMethodName.Data(),
1014 <<
Form(
"Given class number (iClass = %i) does not exist. There are %i classes in dataset.",
iClass,
1032 if (
multigraph->GetListOfGraphs() ==
nullptr) {
1033 Log() << kERROR <<
Form(
"No metohds have class %i defined.",
iClass) <<
Endl;
1070 if (fMethodsMap.find(
datasetname) == fMethodsMap.end()) {
1071 Log() << kERROR <<
Form(
"DataSet = %s not found in methods map.",
datasetname.Data()) <<
Endl;
1084 multigraph->GetYaxis()->SetTitle(
"Background rejection (Specificity)");
1085 multigraph->GetXaxis()->SetTitle(
"Signal efficiency (Sensitivity)");
1096 canvas->
BuildLegend(0.15, 0.15, 0.35, 0.3,
"MVA Method");
1111 if (fMethodsMap.empty()) {
1112 Log() << kINFO <<
"...nothing found to train" <<
Endl;
1118 Log() << kDEBUG <<
"Train all methods for "
1124 std::map<TString, MVector *>::iterator
itrMap;
1138 if (
mva->DataInfo().GetDataSetManager()->DataInput().GetEntries() <=
1140 Log() << kFATAL <<
"No input data for the training provided!" <<
Endl;
1144 Log() << kFATAL <<
"You want to do regression training without specifying a target." <<
Endl;
1146 mva->DataInfo().GetNClasses() < 2)
1147 Log() << kFATAL <<
"You want to do classification training, but specified less than two classes." <<
Endl;
1150 if (!IsSilentFile())
1151 WriteDataInformation(
mva->fDataSetInfo);
1154 Log() << kWARNING <<
"Method " <<
mva->GetMethodName() <<
" not trained (training tree has less entries ["
1159 Log() << kHEADER <<
"Train method: " <<
mva->GetMethodName() <<
" for "
1162 : (fAnalysisType ==
Types::kMulticlass ?
"Multiclass classification" :
"Classification"))
1165 Log() << kHEADER <<
"Training finished" <<
Endl <<
Endl;
1172 Log() << kINFO <<
"Ranking input variables (method specific)..." <<
Endl;
1182 Log() << kINFO <<
"No variable ranking supplied by classifier: "
1189 if (!IsSilentFile()) {
1195 m->fTrainHistory.SaveHistory(
m->GetMethodName());
1203 if (fModelPersistence) {
1205 Log() << kHEADER <<
"=== Destroy and recreate all methods via weight files for testing ===" <<
Endl <<
Endl;
1207 if (!IsSilentFile())
1208 RootBaseDir()->cd();
1234 Log() << kFATAL <<
"Method with type kCategory cannot be casted to MethodCategory. /Factory" <<
Endl;
1236 methCat->fDataSetManager =
m->DataInfo().GetDataSetManager();
1243 m->SetModelPersistence(fModelPersistence);
1244 m->SetSilentFile(IsSilentFile());
1245 m->SetAnalysisType(fAnalysisType);
1247 m->ReadStateFromFile();
1267 if (fMethodsMap.empty()) {
1268 Log() << kINFO <<
"...nothing found to test" <<
Endl;
1271 std::map<TString, MVector *>::iterator
itrMap;
1284 Log() << kHEADER <<
"Test method: " <<
mva->GetMethodName() <<
" for "
1287 : (analysisType ==
Types::kMulticlass ?
"Multiclass classification" :
"Classification"))
1298 if (methodTitle !=
"") {
1303 Log() << kWARNING <<
"<MakeClass> Could not find classifier \"" << methodTitle <<
"\" in list" <<
Endl;
1314 Log() << kINFO <<
"Make response class for classifier: " <<
method->GetMethodName() <<
Endl;
1326 if (methodTitle !=
"") {
1329 method->PrintHelpMessage();
1331 Log() << kWARNING <<
"<PrintHelpMessage> Could not find classifier \"" << methodTitle <<
"\" in list" <<
Endl;
1342 Log() << kINFO <<
"Print help message for classifier: " <<
method->GetMethodName() <<
Endl;
1343 method->PrintHelpMessage();
1353 Log() << kINFO <<
"Evaluating all variables..." <<
Endl;
1356 for (
UInt_t i = 0; i <
loader->GetDataSetInfo().GetNVariables(); i++) {
1357 TString s =
loader->GetDataSetInfo().GetVariableInfo(i).GetLabel();
1360 this->BookMethod(
loader,
"Variable", s);
1372 if (fMethodsMap.empty()) {
1373 Log() << kINFO <<
"...nothing found to evaluate" <<
Endl;
1376 std::map<TString, MVector *>::iterator
itrMap;
1391 std::vector<std::vector<TString>>
mname(2);
1392 std::vector<std::vector<Double_t>> sig(2), sep(2),
roc(2);
1412 std::vector<std::vector<Double_t>>
biastrain(1);
1413 std::vector<std::vector<Double_t>>
biastest(1);
1414 std::vector<std::vector<Double_t>>
devtrain(1);
1415 std::vector<std::vector<Double_t>>
devtest(1);
1416 std::vector<std::vector<Double_t>>
rmstrain(1);
1417 std::vector<std::vector<Double_t>>
rmstest(1);
1418 std::vector<std::vector<Double_t>>
minftrain(1);
1419 std::vector<std::vector<Double_t>>
minftest(1);
1420 std::vector<std::vector<Double_t>>
rhotrain(1);
1421 std::vector<std::vector<Double_t>>
rhotest(1);
1424 std::vector<std::vector<Double_t>>
biastrainT(1);
1425 std::vector<std::vector<Double_t>>
biastestT(1);
1426 std::vector<std::vector<Double_t>>
devtrainT(1);
1427 std::vector<std::vector<Double_t>>
devtestT(1);
1428 std::vector<std::vector<Double_t>>
rmstrainT(1);
1429 std::vector<std::vector<Double_t>>
rmstestT(1);
1430 std::vector<std::vector<Double_t>>
minftrainT(1);
1431 std::vector<std::vector<Double_t>>
minftestT(1);
1446 theMethod->SetSilentFile(IsSilentFile());
1453 Log() << kINFO <<
"Evaluate regression method: " <<
theMethod->GetMethodName() <<
Endl;
1458 Log() << kINFO <<
"TestRegression (testing)" <<
Endl;
1470 Log() << kINFO <<
"TestRegression (training)" <<
Endl;
1484 if (!IsSilentFile()) {
1485 Log() << kDEBUG <<
"\tWrite evaluation histograms to file" <<
Endl;
1494 Log() << kINFO <<
"Evaluate multiclass classification method: " <<
theMethod->GetMethodName() <<
Endl;
1513 if (!IsSilentFile()) {
1514 Log() << kDEBUG <<
"\tWrite evaluation histograms to file" <<
Endl;
1523 Log() << kHEADER <<
"Evaluate classifier: " <<
theMethod->GetMethodName() <<
Endl <<
Endl;
1524 isel = (
theMethod->GetMethodTypeName().Contains(
"Variable")) ? 1 : 0;
1545 theMethod->GetTrainingEfficiency(
"Efficiency:0.01"));
1551 if (!IsSilentFile()) {
1552 Log() << kDEBUG <<
"\tWrite evaluation histograms to file" <<
Endl;
1561 std::vector<std::vector<Double_t>>
vtmp;
1607 for (
Int_t k = 0; k < 2; k++) {
1608 std::vector<std::vector<Double_t>>
vtemp;
1619 vtemp.push_back(sig[k]);
1620 vtemp.push_back(sep[k]);
1647 if (fCorrelations) {
1650 const Int_t nvar =
method->fDataSetInfo.GetNVariables();
1657 std::vector<Double_t>
rvec;
1664 std::vector<TString> *
theVars =
new std::vector<TString>;
1665 std::vector<ResultsClassification *>
mvaRes;
1671 theVars->push_back(
m->GetTestvarName());
1672 rvec.push_back(
m->GetSignalReferenceCut());
1673 theVars->back().ReplaceAll(
"MVA_",
"");
1696 Log() << kWARNING <<
"Found NaN return value in event: " <<
ievt <<
" for method \""
1704 if (
method->fDataSetInfo.IsSignal(
ev)) {
1716 (*theMat)(
im,
jm)++;
1718 (*theMat)(
jm,
im)++;
1725 (*overlapS) *= (1.0 /
defDs->GetNEvtSigTest());
1726 (*overlapB) *= (1.0 /
defDs->GetNEvtBkgdTest());
1728 tpSig->MakePrincipals();
1729 tpBkg->MakePrincipals();
1763 Log() << kINFO <<
Endl;
1764 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1765 <<
"Inter-MVA correlation matrix (signal):" <<
Endl;
1767 Log() << kINFO <<
Endl;
1769 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1770 <<
"Inter-MVA correlation matrix (background):" <<
Endl;
1772 Log() << kINFO <<
Endl;
1775 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1776 <<
"Correlations between input variables and MVA response (signal):" <<
Endl;
1778 Log() << kINFO <<
Endl;
1780 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1781 <<
"Correlations between input variables and MVA response (background):" <<
Endl;
1783 Log() << kINFO <<
Endl;
1785 Log() << kWARNING <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1786 <<
"<TestAllMethods> cannot compute correlation matrices" <<
Endl;
1789 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1790 <<
"The following \"overlap\" matrices contain the fraction of events for which " <<
Endl;
1791 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1792 <<
"the MVAs 'i' and 'j' have returned conform answers about \"signal-likeness\"" <<
Endl;
1793 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1794 <<
"An event is signal-like, if its MVA output exceeds the following value:" <<
Endl;
1796 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1797 <<
"which correspond to the working point: eff(signal) = 1 - eff(background)" <<
Endl;
1801 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1802 <<
"Note: no correlations and overlap with cut method are provided at present" <<
Endl;
1805 Log() << kINFO <<
Endl;
1806 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1807 <<
"Inter-MVA overlap matrix (signal):" <<
Endl;
1809 Log() << kINFO <<
Endl;
1811 Log() << kINFO <<
Form(
"Dataset[%s] : ",
method->fDataSetInfo.GetName())
1812 <<
"Inter-MVA overlap matrix (background):" <<
Endl;
1835 Log() << kINFO <<
Endl;
1837 "--------------------------------------------------------------------------------------------------";
1838 Log() << kINFO <<
"Evaluation results ranked by smallest RMS on test sample:" <<
Endl;
1839 Log() << kINFO <<
"(\"Bias\" quotes the mean deviation of the regression from true target." <<
Endl;
1840 Log() << kINFO <<
" \"MutInf\" is the \"Mutual Information\" between regression and target." <<
Endl;
1841 Log() << kINFO <<
" Indicated by \"_T\" are the corresponding \"truncated\" quantities ob-" <<
Endl;
1842 Log() << kINFO <<
" tained when removing events deviating more than 2sigma from average.)" <<
Endl;
1854 <<
Form(
"%-20s %-15s:%#9.3g%#9.3g%#9.3g%#9.3g | %#5.3f %#5.3f",
theMethod->fDataSetInfo.GetName(),
1860 Log() << kINFO <<
Endl;
1861 Log() << kINFO <<
"Evaluation results ranked by smallest RMS on training sample:" <<
Endl;
1862 Log() << kINFO <<
"(overtraining check)" <<
Endl;
1865 <<
"DataSet Name: MVA Method: <Bias> <Bias_T> RMS RMS_T | MutInf MutInf_T"
1874 <<
Form(
"%-20s %-15s:%#9.3g%#9.3g%#9.3g%#9.3g | %#5.3f %#5.3f",
theMethod->fDataSetInfo.GetName(),
1880 Log() << kINFO <<
Endl;
1887 "-------------------------------------------------------------------------------------------------------";
1927 "Sig eff@B=0.10",
"Sig eff@B=0.30");
1929 "test (train)",
"test (train)");
1930 Log() << kINFO <<
Endl;
1931 Log() << kINFO <<
"1-vs-rest performance metrics per class" <<
Endl;
1933 Log() << kINFO <<
Endl;
1934 Log() << kINFO <<
"Considers the listed class as signal and the other classes" <<
Endl;
1935 Log() << kINFO <<
"as background, reporting the resulting binary performance." <<
Endl;
1936 Log() << kINFO <<
"A score of 0.820 (0.850) means 0.820 was acheived on the" <<
Endl;
1937 Log() << kINFO <<
"test set and 0.850 on the training set." <<
Endl;
1939 Log() << kINFO <<
Endl;
1942 for (
Int_t k = 0; k < 2; k++) {
1945 mname[k][i].ReplaceAll(
"Variable_",
"");
1956 Log() << kINFO <<
Endl;
1958 Log() << kINFO << row <<
Endl;
1959 Log() << kINFO <<
"------------------------------" <<
Endl;
1982 Log() << kINFO << row <<
Endl;
1989 Log() << kINFO <<
Endl;
1991 Log() << kINFO <<
Endl;
2009 stream << kINFO << header <<
Endl;
2025 stream << kINFO <<
Endl;
2029 Log() << kINFO <<
Endl;
2030 Log() << kINFO <<
"Confusion matrices for all methods" <<
Endl;
2032 Log() << kINFO <<
Endl;
2033 Log() << kINFO <<
"Does a binary comparison between the two classes given by a " <<
Endl;
2034 Log() << kINFO <<
"particular row-column combination. In each case, the class " <<
Endl;
2035 Log() << kINFO <<
"given by the row is considered signal while the class given " <<
Endl;
2036 Log() << kINFO <<
"by the column index is considered background." <<
Endl;
2037 Log() << kINFO <<
Endl;
2050 <<
"=== Showing confusion matrix for method : " <<
Form(
"%-15s", (
const char *)
mname[0][
iMethod])
2052 Log() << kINFO <<
"(Signal Efficiency for Background Efficiency 0.01%)" <<
Endl;
2053 Log() << kINFO <<
"---------------------------------------------------" <<
Endl;
2056 Log() << kINFO <<
Endl;
2058 Log() << kINFO <<
"(Signal Efficiency for Background Efficiency 0.10%)" <<
Endl;
2059 Log() << kINFO <<
"---------------------------------------------------" <<
Endl;
2062 Log() << kINFO <<
Endl;
2064 Log() << kINFO <<
"(Signal Efficiency for Background Efficiency 0.30%)" <<
Endl;
2065 Log() << kINFO <<
"---------------------------------------------------" <<
Endl;
2068 Log() << kINFO <<
Endl;
2071 Log() << kINFO <<
Endl;
2076 Log().EnableOutput();
2079 TString hLine =
"------------------------------------------------------------------------------------------"
2080 "-------------------------";
2081 Log() << kINFO <<
"Evaluation results ranked by best signal efficiency and purity (area)" <<
Endl;
2083 Log() << kINFO <<
"DataSet MVA " <<
Endl;
2084 Log() << kINFO <<
"Name: Method: ROC-integ" <<
Endl;
2090 for (
Int_t k = 0; k < 2; k++) {
2093 Log() << kINFO <<
"Input Variables: " <<
Endl <<
hLine <<
Endl;
2118 if (sep[k][i] < 0 || sig[k][i] < 0) {
2147 Log() << kINFO <<
Endl;
2148 Log() << kINFO <<
"Testing efficiency compared to training efficiency (overtraining check)" <<
Endl;
2151 <<
"DataSet MVA Signal efficiency: from test sample (from training sample) "
2153 Log() << kINFO <<
"Name: Method: @B=0.01 @B=0.10 @B=0.30 "
2156 for (
Int_t k = 0; k < 2; k++) {
2159 Log() << kINFO <<
"Input Variables: " <<
Endl <<
hLine <<
Endl;
2163 mname[k][i].ReplaceAll(
"Variable_",
"");
2169 <<
Form(
"%-20s %-15s: %#1.3f (%#1.3f) %#1.3f (%#1.3f) %#1.3f (%#1.3f)",
2176 Log() << kINFO <<
Endl;
2178 if (
gTools().CheckForSilentOption(GetOptions()))
2179 Log().InhibitOutput();
2182 if (!IsSilentFile()) {
2183 std::list<TString> datasets;
2184 for (
Int_t k = 0; k < 2; k++) {
2190 RootBaseDir()->cd(
theMethod->fDataSetInfo.GetName());
2191 if (std::find(datasets.begin(), datasets.end(),
theMethod->fDataSetInfo.GetName()) == datasets.end()) {
2194 datasets.push_back(
theMethod->fDataSetInfo.GetName());
2210 fModelPersistence =
kFALSE;
2211 fSilentFile =
kTRUE;
2214 const int nbits =
loader->GetDataSetInfo().GetNVariables();
2215 if (
vitype == VIType::kShort)
2217 else if (
vitype == VIType::kAll)
2219 else if (
vitype == VIType::kRandom) {
2223 }
else if (
nbits < 10) {
2224 Log() << kERROR <<
"Error in Variable Importance: Random mode require more that 10 variables in the dataset."
2226 }
else if (
nbits > 30) {
2227 Log() << kERROR <<
"Error in Variable Importance: Number of variables is too large for Random mode"
2244 const int nbits =
loader->GetDataSetInfo().GetNVariables();
2245 std::vector<TString>
varNames =
loader->GetDataSetInfo().GetListOfVariables();
2248 Log() << kERROR <<
"Number of combinations is too large , is 2^" <<
nbits <<
Endl;
2252 Log() << kWARNING <<
"Number of combinations is very large , is 2^" <<
nbits <<
Endl;
2254 uint64_t
range =
static_cast<uint64_t
>(pow(2,
nbits));
2262 for (
int i = 0; i <
nbits; i++)
2282 seedloader->PrepareTrainingAndTestTree(
loader->GetDataSetInfo().GetCut(
"Signal"),
2283 loader->GetDataSetInfo().GetCut(
"Background"),
2284 loader->GetDataSetInfo().GetSplitOptions());
2292 EvaluateAllMethods();
2295 ROC[
x] = GetROCIntegral(
xbitset.to_string(), methodTitle);
2303 this->DeleteAllMethods();
2305 fMethodsMap.clear();
2311 for (uint32_t i = 0; i <
VIBITS; ++i) {
2312 if (
x & (uint64_t(1) << i)) {
2313 y =
x & ~(uint64_t(1) << i);
2318 uint32_t
ny =
static_cast<uint32_t
>( log(
x -
y) / 0.693147 ) ;
2331 std::cout <<
"--- Variable Importance Results (All)" << std::endl;
2335static uint64_t
sum(uint64_t i)
2338 if (i > 62)
return 0;
2339 return static_cast<uint64_t
>( std::pow(2, i + 1)) - 1;
2355 const int nbits =
loader->GetDataSetInfo().GetNVariables();
2356 std::vector<TString>
varNames =
loader->GetDataSetInfo().GetListOfVariables();
2359 Log() << kERROR <<
"Number of combinations is too large , is 2^" <<
nbits <<
Endl;
2366 for (
int i = 0; i <
nbits; i++)
2375 Log() << kFATAL <<
"Error: need at least one variable.";
2395 EvaluateAllMethods();
2398 SROC = GetROCIntegral(
xbitset.to_string(), methodTitle);
2406 this->DeleteAllMethods();
2407 fMethodsMap.clear();
2411 for (uint32_t i = 0; i <
VIBITS; ++i) {
2412 if (
x & (uint64_t(1) << i)) {
2413 y =
x & ~(uint64_t(1) << i);
2418 uint32_t
ny =
static_cast<uint32_t
>(log(
x -
y) / 0.693147);
2441 EvaluateAllMethods();
2444 SSROC = GetROCIntegral(
ybitset.to_string(), methodTitle);
2453 this->DeleteAllMethods();
2454 fMethodsMap.clear();
2457 std::cout <<
"--- Variable Importance Results (Short)" << std::endl;
2472 const int nbits =
loader->GetDataSetInfo().GetNVariables();
2473 std::vector<TString>
varNames =
loader->GetDataSetInfo().GetListOfVariables();
2479 for (
int i = 0; i <
nbits; i++)
2508 EvaluateAllMethods();
2511 SROC = GetROCIntegral(
xbitset.to_string(), methodTitle);
2520 this->DeleteAllMethods();
2521 fMethodsMap.clear();
2525 for (uint32_t i = 0; i < 32; ++i) {
2526 if (
x & (uint64_t(1) << i)) {
2527 y =
x & ~(uint64_t(1) << i);
2556 EvaluateAllMethods();
2559 SSROC = GetROCIntegral(
ybitset.to_string(), methodTitle);
2570 this->DeleteAllMethods();
2571 fMethodsMap.clear();
2575 std::cout <<
"--- Variable Importance Results (Random)" << std::endl;
2588 for (
int i = 0; i <
nbits; i++) {
2599 x_ie[i - 1] = (i - 1) * 1.;
2602 std::cout <<
"--- " <<
varNames[i - 1] <<
" = " <<
roc <<
" %" << std::endl;
2603 vih1->GetXaxis()->SetBinLabel(i,
varNames[i - 1].Data());
2609 vih1->LabelsOption(
"v >",
"X");
2610 vih1->SetBarWidth(0.97);
2615 vih1->GetYaxis()->SetTitle(
"Importance (%)");
2616 vih1->GetYaxis()->SetTitleSize(0.045);
2617 vih1->GetYaxis()->CenterTitle();
2618 vih1->GetYaxis()->SetTitleOffset(1.24);
2620 vih1->GetYaxis()->SetRangeUser(-7, 50);
2621 vih1->SetDirectory(
nullptr);
#define MinNoTrainingEvents
void printMatrix(const TMatrixD &mat)
write a matrix
int Int_t
Signed integer 4 bytes (int)
float Float_t
Float 4 bytes (float)
double Double_t
Double 8 bytes.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TMatrixT< Double_t > TMatrixD
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
const_iterator begin() const
const_iterator end() const
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
A TGraph is an object made of two arrays X and Y with npoints each.
TAxis * GetXaxis() const
Get x axis of the graph.
TAxis * GetYaxis() const
Get y axis of the graph.
void SetTitle(const char *title="") override
Change (i.e.
1-D histogram with a float per channel (see TH1 documentation)
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Service class for 2-D histogram classes.
static ClassifierFactory & Instance()
access to the ClassifierFactory singleton creates the instance if needed
TString fWeightFileDirPrefix
void SetDrawProgressBar(Bool_t d)
void SetUseColor(Bool_t uc)
class TMVA::Config::VariablePlotting fVariablePlotting
void SetConfigDescription(const char *d)
OptionBase * DeclareOptionRef(T &ref, const TString &name, const TString &desc="")
void AddPreDefVal(const T &)
void SetConfigName(const char *n)
virtual void ParseOptions()
options parser
const TString & GetOptions() const
MsgLogger * fLogger
! message logger
void CheckForUnusedOptions() const
checks for unused options in option string
Class that contains all the data information.
const TMatrixD * CorrelationMatrix(const TString &className) const
UInt_t GetNClasses() const
DataSet * GetDataSet() const
returns data set
TH2 * CreateCorrelationMatrixHist(const TMatrixD *m, const TString &hName, const TString &hTitle) const
const char * GetName() const override
Returns name of object.
ClassInfo * GetClassInfo(Int_t clNum) const
Class that contains all the data information.
Results * GetResults(const TString &, Types::ETreeType type, Types::EAnalysisType analysistype)
void SetCurrentType(Types::ETreeType type) const
const std::vector< Event * > & GetEventCollection(Types::ETreeType type=Types::kMaxTreeType) const
static void SetIsTraining(Bool_t)
when this static function is called, it sets the flag whether events with negative event weight shoul...
void PrintHelpMessage(const TString &datasetname, const TString &methodTitle="") const
Print predefined help message of classifier.
Bool_t fCorrelations
! enable to calculate correlations
std::vector< IMethod * > MVector
void TrainAllMethods()
Iterates through all booked methods and calls training.
Bool_t Verbose(void) const
void WriteDataInformation(DataSetInfo &fDataSetInfo)
Factory(TString theJobName, TFile *theTargetFile, TString theOption="")
Standard constructor.
void TestAllMethods()
Evaluates all booked methods on the testing data and adds the output to the Results in the corresponi...
Bool_t fVerbose
! verbose mode
void EvaluateAllMethods(void)
Iterates over all MVAs that have been booked, and calls their evaluation methods.
TH1F * EvaluateImportanceRandom(DataLoader *loader, UInt_t nseeds, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
TH1F * GetImportance(const int nbits, std::vector< Double_t > importances, std::vector< TString > varNames)
Bool_t fROC
! enable to calculate ROC values
void EvaluateAllVariables(DataLoader *loader, TString options="")
Iterates over all MVA input variables and evaluates them.
TString fVerboseLevel
! verbosity level, controls granularity of logging
TMultiGraph * GetROCCurveAsMultiGraph(DataLoader *loader, UInt_t iClass, Types::ETreeType type=Types::kTesting)
Generate a collection of graphs, for all methods for a given class.
TH1F * EvaluateImportance(DataLoader *loader, VIType vitype, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Evaluate Variable Importance.
Double_t GetROCIntegral(DataLoader *loader, TString theMethodName, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Calculate the integral of the ROC curve, also known as the area under curve (AUC),...
virtual ~Factory()
Destructor.
MethodBase * BookMethod(DataLoader *loader, MethodName theMethodName, TString methodTitle, TString theOption="")
Books an MVA classifier or regression method.
virtual void MakeClass(const TString &datasetname, const TString &methodTitle="") const
MethodBase * BookMethodWeightfile(DataLoader *dataloader, TMVA::Types::EMVA methodType, const TString &weightfile)
Adds an already constructed method to be managed by this factory.
Bool_t fModelPersistence
! option to save the trained model in xml file or using serialization
std::map< TString, Double_t > OptimizeAllMethods(TString fomType="ROCIntegral", TString fitType="FitGA")
Iterates through all booked methods and sees if they use parameter tuning and if so does just that,...
ROCCurve * GetROC(DataLoader *loader, TString theMethodName, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Private method to generate a ROCCurve instance for a given method.
TH1F * EvaluateImportanceShort(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
Types::EAnalysisType fAnalysisType
! the training type
Bool_t HasMethod(const TString &datasetname, const TString &title) const
Checks whether a given method name is defined for a given dataset.
TGraph * GetROCCurve(DataLoader *loader, TString theMethodName, Bool_t setTitles=kTRUE, UInt_t iClass=0, Types::ETreeType type=Types::kTesting)
Argument iClass specifies the class to generate the ROC curve in a multiclass setting.
TH1F * EvaluateImportanceAll(DataLoader *loader, Types::EMVA theMethod, TString methodTitle, const char *theOption="")
void SetVerbose(Bool_t v=kTRUE)
TFile * fgTargetFile
! ROOT output file
IMethod * GetMethod(const TString &datasetname, const TString &title) const
Returns pointer to MVA that corresponds to given method title.
void DeleteAllMethods(void)
Delete methods.
TString fTransformations
! list of transformations to test
void Greetings()
Print welcome message.
Interface for all concrete MVA method implementations.
Virtual base Class for all MVA method.
const TString & GetMethodName() const
Class for boosting a TMVA method.
Class for categorizing the phase space.
ostringstream derivative to redirect and format output
void SetMinType(EMsgType minType)
void SetSource(const std::string &source)
static void InhibitOutput()
Ranking for variables in method (implementation)
Class that is the base-class for a vector of result.
Class which takes the results of a multiclass classification.
Class that is the base-class for a vector of result.
Singleton class for Global types used by TMVA.
static Types & Instance()
The single instance of "Types" if existing already, or create it (Singleton)
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
@ kOverwrite
overwrite existing object with same name
virtual const char * GetName() const
Returns name of object.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
TLegend * BuildLegend(Double_t x1=0.3, Double_t y1=0.21, Double_t x2=0.3, Double_t y2=0.21, const char *title="", Option_t *option="") override
Build a legend from the graphical objects in the pad.
Principal Components Analysis (PCA)
Random number generator class based on M.
void ToLower()
Change string to lower-case.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
void SetTitleXOffset(Float_t offset=1)
virtual int MakeDirectory(const char *name)
Make a directory.
void DataLoaderCopy(TMVA::DataLoader *des, TMVA::DataLoader *src)
void CreateVariableTransforms(const TString &trafoDefinition, TMVA::DataSetInfo &dataInfo, TMVA::TransformationHandler &transformationHandler, TMVA::MsgLogger &log)
MsgLogger & Endl(MsgLogger &ml)
static uint64_t sum(uint64_t i)
const Int_t MinNoTrainingEvents