34void TMVAMulticlass(
TString myMethodList =
"" )
51 std::map<std::string,int> Use;
59 std::cout << std::endl;
60 std::cout <<
"==> Start TMVAMulticlass" << std::endl;
62 if (myMethodList !=
"") {
63 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
66 for (
UInt_t i=0; i<mlist.size(); i++) {
67 std::string regMethod(mlist[i]);
69 if (Use.find(regMethod) == Use.end()) {
70 std::cout <<
"Method \"" << regMethod <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
71 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first <<
" ";
72 std::cout << std::endl;
80 TString outfileName =
"TMVAMulticlass.root";
84 "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=multiclass" );
88 dataloader->
AddVariable(
"var2",
"Variable 2",
"",
'F' );
89 dataloader->
AddVariable(
"var3",
"Variable 3",
"units",
'F' );
90 dataloader->
AddVariable(
"var4",
"Variable 4",
"units",
'F' );
93 TString fname =
"./tmva_example_multiple_background.root";
96 std::cout <<
"--- TMVAMulticlass : Accessing " << fname << std::endl;
100 std::cout <<
"Creating testdata...." << std::endl;
101 TString createDataMacro =
gROOT->GetTutorialDir() +
"/tmva/createData.C";
103 gROOT->ProcessLine(
"create_MultipleBackground(2000)");
104 std::cout <<
" created tmva_example_multiple_background.root for tests of the multiclass features"<<std::endl;
108 std::cout <<
"ERROR: could not open data file" << std::endl;
112 TTree *signalTree = (
TTree*)input->Get(
"TreeS");
113 TTree *background0 = (
TTree*)input->Get(
"TreeB0");
114 TTree *background1 = (
TTree*)input->Get(
"TreeB1");
115 TTree *background2 = (
TTree*)input->Get(
"TreeB2");
118 dataloader->
AddTree (signalTree,
"Signal");
119 dataloader->
AddTree (background0,
"bg0");
120 dataloader->
AddTree (background1,
"bg1");
121 dataloader->
AddTree (background2,
"bg2");
126 factory->
BookMethod( dataloader,
TMVA::Types::kBDT,
"BDTG",
"!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedBoost:BaggedSampleFraction=0.50:nCuts=20:MaxDepth=2");
128 factory->
BookMethod( dataloader,
TMVA::Types::kMLP,
"MLP",
"!H:!V:NeuronType=tanh:NCycles=1000:HiddenLayers=N+5,5:TestRate=5:EstimatorType=MSE");
130 factory->
BookMethod( dataloader,
TMVA::Types::kFDA,
"FDA_GA",
"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=300:Cycles=3:Steps=20:Trim=True:SaveBestGen=1" );
132 factory->
BookMethod( dataloader,
TMVA::Types::kPDEFoam,
"PDEFoam",
"!H:!V:TailCut=0.001:VolFrac=0.0666:nActiveCells=500:nSampl=2000:nBin=5:Nmin=100:Kernel=None:Compress=T" );
134 if (Use[
"DNN_CPU"]) {
135 TString layoutString(
"Layout=TANH|100,TANH|50,TANH|10,LINEAR");
136 TString training0(
"LearningRate=1e-1, Momentum=0.5, Repetitions=1, ConvergenceSteps=10,"
137 " BatchSize=256, TestRepetitions=10, Multithreading=True");
138 TString training1(
"LearningRate=1e-2, Momentum=0.0, Repetitions=1, ConvergenceSteps=10,"
139 " BatchSize=256, TestRepetitions=7, Multithreading=True");
140 TString trainingStrategyString(
"TrainingStrategy=");
141 trainingStrategyString += training0 +
"|" + training1;
142 TString nnOptions(
"!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=N:"
143 "WeightInitialization=XAVIERUNIFORM:Architecture=CPU");
144 nnOptions.Append(
":");
145 nnOptions.Append(layoutString);
146 nnOptions.Append(
":");
147 nnOptions.Append(trainingStrategyString);
165 std::cout <<
"==> Wrote root file: " << outputFile->
GetName() << std::endl;
166 std::cout <<
"==> TMVAMulticlass is done!" << std::endl;
177int main(
int argc,
char** argv )
181 for (
int i=1; i<argc; i++) {
183 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
185 methodList += regMethod;
187 TMVAMulticlass(methodList);
R__EXTERN TSystem * gSystem
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
virtual void Close(Option_t *option="")
Close a file.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, Int_t netopt=0)
Create / open a file.
void PrepareTrainingAndTestTree(const TCut &cut, const TString &splitOpt)
prepare the training and test trees -> same cuts for signal and background
void AddTree(TTree *tree, const TString &className, Double_t weight=1.0, const TCut &cut="", Types::ETreeType tt=Types::kMaxTreeType)
void AddVariable(const TString &expression, const TString &title, const TString &unit, char type='F', Double_t min=0, Double_t max=0)
user inserts discriminating variable in data set info
This is the main MVA steering class.
void TrainAllMethods()
Iterates through all booked methods and calls training.
MethodBase * BookMethod(DataLoader *loader, TString theMethodName, TString methodTitle, TString theOption="")
Book a classifier or regression method.
void TestAllMethods()
Evaluates all booked methods on the testing data and adds the output to the Results in the corresponi...
void EvaluateAllMethods(void)
Iterates over all MVAs that have been booked, and calls their evaluation methods.
virtual const char * GetName() const
Returns name of object.
const char * Data() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
A TTree represents a columnar dataset.
int main(int argc, char **argv)
create variable transformations
void TMVAMultiClassGui(const char *fName="TMVAMulticlass.root", TString dataset="")