50 for (
int i = 0; i <
ntime; ++i) {
55 auto f1 =
new TF1(
"f1",
"gaus");
56 auto f2 =
new TF1(
"f2",
"gaus");
62 std::vector<std::vector<float>>
x1(
ntime);
63 std::vector<std::vector<float>>
x2(
ntime);
65 for (
int i = 0; i <
ntime; ++i) {
66 x1[i] = std::vector<float>(ndim);
67 x2[i] = std::vector<float>(ndim);
70 for (
auto i = 0; i <
ntime; i++) {
71 bkg.Branch(
Form(
"vars_time%d", i),
"std::vector<float>", &
x1[i]);
72 sgn.Branch(
Form(
"vars_time%d", i),
"std::vector<float>", &
x2[i]);
89 for (
int i = 0; i <
n; ++i) {
92 std::cout <<
"Generating event ... " << i << std::endl;
104 h2->FillRandom(
"f2", 1000);
106 for (
int k = 0; k < ndim; ++k) {
150 const int ntime = 10;
151 const int batchSize = 100;
163 std::vector<std::string>
rnn_types = {
"RNN",
"LSTM",
"GRU"};
171#ifndef R__HAS_TMVAGPU
173#ifndef R__HAS_TMVACPU
174 Warning(
"TMVA_RNN_Classification",
"TMVA is not build with GPU or CPU multi-thread support. Cannot use TMVA Deep Learning for RNN");
221 Error(
"TMVA_RNN_Classification",
"Error opening input file %s - exit",
inputFileName.Data());
226 std::cout <<
"--- RNNClassification : Using input file: " <<
inputFile->GetName() << std::endl;
256 "!V:!Silent:Color:DrawProgressBar:Transformations=None:!Correlations:"
257 "AnalysisType=Classification:ModelPersistence");
266 for (
auto i = 0; i <
ntime; i++) {
275 auto vars =
datainfo.GetListOfVariables();
276 std::cout <<
"number of variables is " << vars.size() << std::endl;
278 std::cout <<
v <<
",";
279 std::cout << std::endl;
293 std::cout <<
"prepared DATA LOADER " << std::endl;
304 for (
int i = 0; i < 3; ++i) {
327 "ConvergenceSteps=5,BatchSize=%d,TestRepetitions=1,"
328 "WeightDecay=1e-2,Regularization=None,MaxEpochs=%d,"
329 "Optimizer=ADAM,DropConfig=0.0+0.+0.+0.",
337 "WeightInitialization=XAVIERUNIFORM:ValidationSize=0.2:RandomSeed=1234");
366 "ConvergenceSteps=10,BatchSize=256,TestRepetitions=1,"
367 "WeightDecay=1e-4,Regularization=None,MaxEpochs=20"
368 "DropConfig=0.0+0.+0.+0.,Optimizer=ADAM");
374 "WeightInitialization=XAVIER:RandomSeed=0");
398 for (
int i = 0; i < 3; i++) {
405 Info(
"TMVA_RNN_Classification",
"Building recurrent keras model using a %s layer",
rnn_types[i].c_str());
409 m.AddLine(
"import tensorflow");
410 m.AddLine(
"from tensorflow.keras.models import Sequential");
411 m.AddLine(
"from tensorflow.keras.optimizers import Adam");
412 m.AddLine(
"from tensorflow.keras.layers import Input, Dense, Dropout, Flatten, SimpleRNN, GRU, LSTM, Reshape, "
413 "BatchNormalization");
415 m.AddLine(
"model = Sequential() ");
416 m.AddLine(
"model.add(Reshape((10, 30), input_shape = (10*30, )))");
419 m.AddLine(
"model.add(LSTM(units=10, return_sequences=True) )");
421 m.AddLine(
"model.add(GRU(units=10, return_sequences=True) )");
423 m.AddLine(
"model.add(SimpleRNN(units=10, return_sequences=True) )");
426 m.AddLine(
"model.add(Flatten())");
427 m.AddLine(
"model.add(Dense(64, activation = 'tanh')) ");
428 m.AddLine(
"model.add(Dense(2, activation = 'sigmoid')) ");
430 "model.compile(loss = 'binary_crossentropy', optimizer = Adam(learning_rate = 0.001), weighted_metrics = ['accuracy'])");
432 m.AddLine(
"model.save(modelName)");
433 m.AddLine(
"model.summary()");
435 m.SaveSource(
"make_rnn_model.py");
442 Warning(
"TMVA_RNN_Classification",
"Error creating Keras recurrent model file - Skip using Keras");
446 Info(
"TMVA_RNN_Classification",
"Booking Keras %s model",
rnn_types[i].c_str());
450 "FilenameTrainedModel=%s:GpuOptions=allow_growth=True:"
451 "NumEpochs=%d:BatchSize=%d",
469 "!H:!V:NTrees=100:MinNodeSize=2.5%:BoostType=Grad:Shrinkage=0.10:UseBaggedBoost:"
470 "BaggedSampleFraction=0.5:nCuts=20:"
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TSystem * gSystem
A specialized string object used for TTree selections.
virtual void SetParameters(const Double_t *params)
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
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.
1-D histogram with a double per channel (see TH1 documentation)
void Reset(Option_t *option="") override
Reset.
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
static Config & Instance()
static function: returns TMVA instance
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.
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.
static void PyInitialize()
Initialize Python interpreter.
Class supporting a collection of lines with C++ code.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual Int_t Exec(const char *shellcmd)
Execute a command.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual void Setenv(const char *name, const char *value)
Set environment variable.
A TTree represents a columnar dataset.
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.