34void TMVAMulticlass(
TString myMethodList =
"" )
51 std::map<std::string,int> Use;
66 std::cout << std::endl;
67 std::cout <<
"==> Start TMVAMulticlass" << std::endl;
69 if (myMethodList !=
"") {
70 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;
73 for (
UInt_t i=0; i<mlist.size(); i++) {
74 std::string regMethod(mlist[i]);
76 if (Use.find(regMethod) == Use.end()) {
77 std::cout <<
"Method \"" << regMethod <<
"\" not known in TMVA under this name. Choose among the following:" << std::endl;
78 for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first <<
" ";
79 std::cout << std::endl;
87 TString outfileName =
"TMVAMulticlass.root";
91 "!V:!Silent:Color:DrawProgressBar:Transformations=I;D;P;G,D:AnalysisType=multiclass" );
95 dataloader->
AddVariable(
"var2",
"Variable 2",
"",
'F' );
96 dataloader->
AddVariable(
"var3",
"Variable 3",
"units",
'F' );
97 dataloader->
AddVariable(
"var4",
"Variable 4",
"units",
'F' );
100 TString fname =
"./tmva_example_multiclass.root";
106 input =
TFile::Open(
"http://root.cern.ch/files/tmva_multiclass_example.root",
"CACHEREAD");
109 std::cout <<
"ERROR: could not open data file" << std::endl;
112 std::cout <<
"--- TMVAMulticlass: Using input file: " << input->GetName() << std::endl;
114 TTree *signalTree = (
TTree*)input->Get(
"TreeS");
115 TTree *background0 = (
TTree*)input->Get(
"TreeB0");
116 TTree *background1 = (
TTree*)input->Get(
"TreeB1");
117 TTree *background2 = (
TTree*)input->Get(
"TreeB2");
120 dataloader->
AddTree (signalTree,
"Signal");
121 dataloader->
AddTree (background0,
"bg0");
122 dataloader->
AddTree (background1,
"bg1");
123 dataloader->
AddTree (background2,
"bg2");
128 factory->
BookMethod( dataloader,
TMVA::Types::kBDT,
"BDTG",
"!H:!V:NTrees=1000:BoostType=Grad:Shrinkage=0.10:UseBaggedBoost:BaggedSampleFraction=0.50:nCuts=20:MaxDepth=2");
130 factory->
BookMethod( dataloader,
TMVA::Types::kMLP,
"MLP",
"!H:!V:NeuronType=tanh:NCycles=1000:HiddenLayers=N+5,5:TestRate=5:EstimatorType=MSE");
132 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" );
134 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" );
138 TString layoutString(
"Layout=TANH|100,TANH|50,TANH|10,LINEAR");
139 TString trainingStrategyString(
"TrainingStrategy=Optimizer=ADAM,LearningRate=1e-3,"
140 "TestRepetitions=1,ConvergenceSteps=10,BatchSize=100");
141 TString nnOptions(
"!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=N:"
142 "WeightInitialization=XAVIERUNIFORM:Architecture=GPU");
143 nnOptions.Append(
":");
144 nnOptions.Append(layoutString);
145 nnOptions.Append(
":");
146 nnOptions.Append(trainingStrategyString);
150 TString layoutString(
"Layout=TANH|100,TANH|50,TANH|10,LINEAR");
151 TString trainingStrategyString(
"TrainingStrategy=Optimizer=ADAM,LearningRate=1e-3,"
152 "TestRepetitions=1,ConvergenceSteps=10,BatchSize=100");
153 TString nnOptions(
"!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=N:"
154 "WeightInitialization=XAVIERUNIFORM:Architecture=GPU");
155 nnOptions.Append(
":");
156 nnOptions.Append(layoutString);
157 nnOptions.Append(
":");
158 nnOptions.Append(trainingStrategyString);
177 std::cout <<
"==> Wrote root file: " << outputFile->
GetName() << std::endl;
178 std::cout <<
"==> TMVAMulticlass is done!" << std::endl;
189int main(
int argc,
char** argv )
193 for (
int i=1; i<argc; i++) {
195 if(regMethod==
"-b" || regMethod==
"--batch")
continue;
197 methodList += regMethod;
199 TMVAMulticlass(methodList);
R__EXTERN TSystem * gSystem
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
void Close(Option_t *option="") override
Close 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.
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.
create variable transformations
void TMVAMultiClassGui(const char *fName="TMVAMulticlass.root", TString dataset="")