Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVA_RNN_Classification.py File Reference

Detailed Description

View in nbviewer Open in SWAN
TMVA Classification Example Using a Recurrent Neural Network

This is an example of using a RNN in TMVA. We do classification using a toy time dependent data set that is generated when running this example macro

DataSetInfo : [dataset] : Added class "Signal"
: Add Tree sgn of type Signal with 2000 events
DataSetInfo : [dataset] : Added class "Background"
: Add Tree bkg of type Background with 2000 events
Factory : Booking method: ␛[1mTMVA_LSTM␛[0m
:
: Parsing option string:
: ... "!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=None:WeightInitialization=XAVIERUNIFORM:ValidationSize=0.2:RandomSeed=1234:InputLayout=10|30:Layout=LSTM|10|30|10|0|1,RESHAPE|FLAT,DENSE|64|TANH,LINEAR:TrainingStrategy=LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,WeightDecay=1e-2,Regularization=None,MaxEpochs=10Optimizer=ADAM,DropConfig=0.0+0.+0.+0.:Architecture=CPU"
: The following options are set:
: - By User:
: <none>
: - Default:
: Boost_num: "0" [Number of times the classifier will be boosted]
: Parsing option string:
: ... "!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=None:WeightInitialization=XAVIERUNIFORM:ValidationSize=0.2:RandomSeed=1234:InputLayout=10|30:Layout=LSTM|10|30|10|0|1,RESHAPE|FLAT,DENSE|64|TANH,LINEAR:TrainingStrategy=LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,WeightDecay=1e-2,Regularization=None,MaxEpochs=10Optimizer=ADAM,DropConfig=0.0+0.+0.+0.:Architecture=CPU"
: The following options are set:
: - By User:
: V: "True" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
: VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
: H: "False" [Print method-specific help message]
: InputLayout: "10|30" [The Layout of the input]
: Layout: "LSTM|10|30|10|0|1,RESHAPE|FLAT,DENSE|64|TANH,LINEAR" [Layout of the network.]
: ErrorStrategy: "CROSSENTROPY" [Loss function: Mean squared error (regression) or cross entropy (binary classification).]
: WeightInitialization: "XAVIERUNIFORM" [Weight initialization strategy]
: RandomSeed: "1234" [Random seed used for weight initialization and batch shuffling]
: ValidationSize: "0.2" [Part of the training data to use for validation. Specify as 0.2 or 20% to use a fifth of the data set as validation set. Specify as 100 to use exactly 100 events. (Default: 20%)]
: Architecture: "CPU" [Which architecture to perform the training on.]
: TrainingStrategy: "LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=5,BatchSize=100,TestRepetitions=1,WeightDecay=1e-2,Regularization=None,MaxEpochs=10Optimizer=ADAM,DropConfig=0.0+0.+0.+0." [Defines the training strategies.]
: - Default:
: VerbosityLevel: "Default" [Verbosity level]
: CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
: IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
: BatchLayout: "0|0|0" [The Layout of the batch]
: Will now use the CPU architecture with BLAS and IMT support !
Factory : Booking method: ␛[1mTMVA_DNN␛[0m
:
: Parsing option string:
: ... "!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=None:WeightInitialization=XAVIER:RandomSeed=0:InputLayout=1|1|300:Layout=DENSE|64|TANH,DENSE|TANH|64,DENSE|TANH|64,LINEAR:TrainingStrategy=LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=10,BatchSize=256,TestRepetitions=1,WeightDecay=1e-4,Regularization=None,MaxEpochs=20DropConfig=0.0+0.+0.+0.,Optimizer=ADAM:CPU"
: The following options are set:
: - By User:
: <none>
: - Default:
: Boost_num: "0" [Number of times the classifier will be boosted]
: Parsing option string:
: ... "!H:V:ErrorStrategy=CROSSENTROPY:VarTransform=None:WeightInitialization=XAVIER:RandomSeed=0:InputLayout=1|1|300:Layout=DENSE|64|TANH,DENSE|TANH|64,DENSE|TANH|64,LINEAR:TrainingStrategy=LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=10,BatchSize=256,TestRepetitions=1,WeightDecay=1e-4,Regularization=None,MaxEpochs=20DropConfig=0.0+0.+0.+0.,Optimizer=ADAM:CPU"
: The following options are set:
: - By User:
: V: "True" [Verbose output (short form of "VerbosityLevel" below - overrides the latter one)]
: VarTransform: "None" [List of variable transformations performed before training, e.g., "D_Background,P_Signal,G,N_AllClasses" for: "Decorrelation, PCA-transformation, Gaussianisation, Normalisation, each for the given class of events ('AllClasses' denotes all events of all classes, if no class indication is given, 'All' is assumed)"]
: H: "False" [Print method-specific help message]
: InputLayout: "1|1|300" [The Layout of the input]
: Layout: "DENSE|64|TANH,DENSE|TANH|64,DENSE|TANH|64,LINEAR" [Layout of the network.]
: ErrorStrategy: "CROSSENTROPY" [Loss function: Mean squared error (regression) or cross entropy (binary classification).]
: WeightInitialization: "XAVIER" [Weight initialization strategy]
: RandomSeed: "0" [Random seed used for weight initialization and batch shuffling]
: Architecture: "CPU" [Which architecture to perform the training on.]
: TrainingStrategy: "LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=10,BatchSize=256,TestRepetitions=1,WeightDecay=1e-4,Regularization=None,MaxEpochs=20DropConfig=0.0+0.+0.+0.,Optimizer=ADAM" [Defines the training strategies.]
: - Default:
: VerbosityLevel: "Default" [Verbosity level]
: CreateMVAPdfs: "False" [Create PDFs for classifier outputs (signal and background)]
: IgnoreNegWeightsInTraining: "False" [Events with negative weights are ignored in the training (but are included for testing and performance evaluation)]
: BatchLayout: "0|0|0" [The Layout of the batch]
: ValidationSize: "20%" [Part of the training data to use for validation. Specify as 0.2 or 20% to use a fifth of the data set as validation set. Specify as 100 to use exactly 100 events. (Default: 20%)]
: Will now use the CPU architecture with BLAS and IMT support !
Running with nthreads = 4
--- RNNClassification : Using input file: time_data_t10_d30.root
number of variables is 300
vars_time0[0]
vars_time0[1]
vars_time0[2]
vars_time0[3]
vars_time0[4]
vars_time0[5]
vars_time0[6]
vars_time0[7]
vars_time0[8]
vars_time0[9]
vars_time0[10]
vars_time0[11]
vars_time0[12]
vars_time0[13]
vars_time0[14]
vars_time0[15]
vars_time0[16]
vars_time0[17]
vars_time0[18]
vars_time0[19]
vars_time0[20]
vars_time0[21]
vars_time0[22]
vars_time0[23]
vars_time0[24]
vars_time0[25]
vars_time0[26]
vars_time0[27]
vars_time0[28]
vars_time0[29]
vars_time1[0]
vars_time1[1]
vars_time1[2]
vars_time1[3]
vars_time1[4]
vars_time1[5]
vars_time1[6]
vars_time1[7]
vars_time1[8]
vars_time1[9]
vars_time1[10]
vars_time1[11]
vars_time1[12]
vars_time1[13]
vars_time1[14]
vars_time1[15]
vars_time1[16]
vars_time1[17]
vars_time1[18]
vars_time1[19]
vars_time1[20]
vars_time1[21]
vars_time1[22]
vars_time1[23]
vars_time1[24]
vars_time1[25]
vars_time1[26]
vars_time1[27]
vars_time1[28]
vars_time1[29]
vars_time2[0]
vars_time2[1]
vars_time2[2]
vars_time2[3]
vars_time2[4]
vars_time2[5]
vars_time2[6]
vars_time2[7]
vars_time2[8]
vars_time2[9]
vars_time2[10]
vars_time2[11]
vars_time2[12]
vars_time2[13]
vars_time2[14]
vars_time2[15]
vars_time2[16]
vars_time2[17]
vars_time2[18]
vars_time2[19]
vars_time2[20]
vars_time2[21]
vars_time2[22]
vars_time2[23]
vars_time2[24]
vars_time2[25]
vars_time2[26]
vars_time2[27]
vars_time2[28]
vars_time2[29]
vars_time3[0]
vars_time3[1]
vars_time3[2]
vars_time3[3]
vars_time3[4]
vars_time3[5]
vars_time3[6]
vars_time3[7]
vars_time3[8]
vars_time3[9]
vars_time3[10]
vars_time3[11]
vars_time3[12]
vars_time3[13]
vars_time3[14]
vars_time3[15]
vars_time3[16]
vars_time3[17]
vars_time3[18]
vars_time3[19]
vars_time3[20]
vars_time3[21]
vars_time3[22]
vars_time3[23]
vars_time3[24]
vars_time3[25]
vars_time3[26]
vars_time3[27]
vars_time3[28]
vars_time3[29]
vars_time4[0]
vars_time4[1]
vars_time4[2]
vars_time4[3]
vars_time4[4]
vars_time4[5]
vars_time4[6]
vars_time4[7]
vars_time4[8]
vars_time4[9]
vars_time4[10]
vars_time4[11]
vars_time4[12]
vars_time4[13]
vars_time4[14]
vars_time4[15]
vars_time4[16]
vars_time4[17]
vars_time4[18]
vars_time4[19]
vars_time4[20]
vars_time4[21]
vars_time4[22]
vars_time4[23]
vars_time4[24]
vars_time4[25]
vars_time4[26]
vars_time4[27]
vars_time4[28]
vars_time4[29]
vars_time5[0]
vars_time5[1]
vars_time5[2]
vars_time5[3]
vars_time5[4]
vars_time5[5]
vars_time5[6]
vars_time5[7]
vars_time5[8]
vars_time5[9]
vars_time5[10]
vars_time5[11]
vars_time5[12]
vars_time5[13]
vars_time5[14]
vars_time5[15]
vars_time5[16]
vars_time5[17]
vars_time5[18]
vars_time5[19]
vars_time5[20]
vars_time5[21]
vars_time5[22]
vars_time5[23]
vars_time5[24]
vars_time5[25]
vars_time5[26]
vars_time5[27]
vars_time5[28]
vars_time5[29]
vars_time6[0]
vars_time6[1]
vars_time6[2]
vars_time6[3]
vars_time6[4]
vars_time6[5]
vars_time6[6]
vars_time6[7]
vars_time6[8]
vars_time6[9]
vars_time6[10]
vars_time6[11]
vars_time6[12]
vars_time6[13]
vars_time6[14]
vars_time6[15]
vars_time6[16]
vars_time6[17]
vars_time6[18]
vars_time6[19]
vars_time6[20]
vars_time6[21]
vars_time6[22]
vars_time6[23]
vars_time6[24]
vars_time6[25]
vars_time6[26]
vars_time6[27]
vars_time6[28]
vars_time6[29]
vars_time7[0]
vars_time7[1]
vars_time7[2]
vars_time7[3]
vars_time7[4]
vars_time7[5]
vars_time7[6]
vars_time7[7]
vars_time7[8]
vars_time7[9]
vars_time7[10]
vars_time7[11]
vars_time7[12]
vars_time7[13]
vars_time7[14]
vars_time7[15]
vars_time7[16]
vars_time7[17]
vars_time7[18]
vars_time7[19]
vars_time7[20]
vars_time7[21]
vars_time7[22]
vars_time7[23]
vars_time7[24]
vars_time7[25]
vars_time7[26]
vars_time7[27]
vars_time7[28]
vars_time7[29]
vars_time8[0]
vars_time8[1]
vars_time8[2]
vars_time8[3]
vars_time8[4]
vars_time8[5]
vars_time8[6]
vars_time8[7]
vars_time8[8]
vars_time8[9]
vars_time8[10]
vars_time8[11]
vars_time8[12]
vars_time8[13]
vars_time8[14]
vars_time8[15]
vars_time8[16]
vars_time8[17]
vars_time8[18]
vars_time8[19]
vars_time8[20]
vars_time8[21]
vars_time8[22]
vars_time8[23]
vars_time8[24]
vars_time8[25]
vars_time8[26]
vars_time8[27]
vars_time8[28]
vars_time8[29]
vars_time9[0]
vars_time9[1]
vars_time9[2]
vars_time9[3]
vars_time9[4]
vars_time9[5]
vars_time9[6]
vars_time9[7]
vars_time9[8]
vars_time9[9]
vars_time9[10]
vars_time9[11]
vars_time9[12]
vars_time9[13]
vars_time9[14]
vars_time9[15]
vars_time9[16]
vars_time9[17]
vars_time9[18]
vars_time9[19]
vars_time9[20]
vars_time9[21]
vars_time9[22]
vars_time9[23]
vars_time9[24]
vars_time9[25]
vars_time9[26]
vars_time9[27]
vars_time9[28]
vars_time9[29]
prepared DATA LOADER
Building recurrent keras model using a LSTM layer
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
reshape (Reshape) (None, 10, 30) 0
lstm (LSTM) (None, 10, 10) 1640
flatten (Flatten) (None, 100) 0
dense (Dense) (None, 64) 6464
dense_1 (Dense) (None, 2) 130
=================================================================
Total params: 8234 (32.16 KB)
Trainable params: 8234 (32.16 KB)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
Factory : Booking method: ␛[1mPyKeras_LSTM␛[0m
:
: Setting up tf.keras
: Using TensorFlow version 2
: Use Keras version from TensorFlow : tf.keras
: Applying GPU option: gpu_options.allow_growth=True
: Loading Keras Model
: Loaded model from file: model_LSTM.h5
Factory : Booking method: ␛[1mBDTG␛[0m
:
: the option NegWeightTreatment=InverseBoostNegWeights does not exist for BoostType=Grad
: --> change to new default NegWeightTreatment=Pray
: Rebuilding Dataset dataset
: Building event vectors for type 2 Signal
: Dataset[dataset] : create input formulas for tree sgn
: Using variable vars_time0[0] from array expression vars_time0 of size 30
: Using variable vars_time1[0] from array expression vars_time1 of size 30
: Using variable vars_time2[0] from array expression vars_time2 of size 30
: Using variable vars_time3[0] from array expression vars_time3 of size 30
: Using variable vars_time4[0] from array expression vars_time4 of size 30
: Using variable vars_time5[0] from array expression vars_time5 of size 30
: Using variable vars_time6[0] from array expression vars_time6 of size 30
: Using variable vars_time7[0] from array expression vars_time7 of size 30
: Using variable vars_time8[0] from array expression vars_time8 of size 30
: Using variable vars_time9[0] from array expression vars_time9 of size 30
: Building event vectors for type 2 Background
: Dataset[dataset] : create input formulas for tree bkg
: Using variable vars_time0[0] from array expression vars_time0 of size 30
: Using variable vars_time1[0] from array expression vars_time1 of size 30
: Using variable vars_time2[0] from array expression vars_time2 of size 30
: Using variable vars_time3[0] from array expression vars_time3 of size 30
: Using variable vars_time4[0] from array expression vars_time4 of size 30
: Using variable vars_time5[0] from array expression vars_time5 of size 30
: Using variable vars_time6[0] from array expression vars_time6 of size 30
: Using variable vars_time7[0] from array expression vars_time7 of size 30
: Using variable vars_time8[0] from array expression vars_time8 of size 30
: Using variable vars_time9[0] from array expression vars_time9 of size 30
DataSetFactory : [dataset] : Number of events in input trees
:
:
: Number of training and testing events
: ---------------------------------------------------------------------------
: Signal -- training events : 1600
: Signal -- testing events : 400
: Signal -- training and testing events: 2000
: Background -- training events : 1600
: Background -- testing events : 400
: Background -- training and testing events: 2000
:
Factory : ␛[1mTrain all methods␛[0m
Factory : Train method: TMVA_LSTM for Classification
:
: Start of deep neural network training on CPU using MT, nthreads = 4
:
: ***** Deep Learning Network *****
DEEP NEURAL NETWORK: Depth = 4 Input = ( 10, 1, 30 ) Batch size = 100 Loss function = C
Layer 0 LSTM Layer: (NInput = 30, NState = 10, NTime = 10 ) Output = ( 100 , 10 , 10 )
Layer 1 RESHAPE Layer Input = ( 1 , 10 , 10 ) Output = ( 1 , 100 , 100 )
Layer 2 DENSE Layer: ( Input = 100 , Width = 64 ) Output = ( 1 , 100 , 64 ) Activation Function = Tanh
Layer 3 DENSE Layer: ( Input = 64 , Width = 1 ) Output = ( 1 , 100 , 1 ) Activation Function = Identity
: Using 2560 events for training and 640 for testing
: Compute initial loss on the validation data
: Training phase 1 of 1: Optimizer ADAM (beta1=0.9,beta2=0.999,eps=1e-07) Learning rate = 0.001 regularization 0 minimum error = 0.705605
: --------------------------------------------------------------
: Epoch | Train Err. Val. Err. t(s)/epoch t(s)/Loss nEvents/s Conv. Steps
: --------------------------------------------------------------
: Start epoch iteration ...
: 1 Minimum Test error found - save the configuration
: 1 | 0.698391 0.696978 0.602397 0.0403782 4448.25 0
: 2 Minimum Test error found - save the configuration
: 2 | 0.688676 0.691614 0.581596 0.0398569 4614.77 0
: 3 Minimum Test error found - save the configuration
: 3 | 0.685188 0.689705 0.551792 0.0392808 4877.94 0
: 4 Minimum Test error found - save the configuration
: 4 | 0.674166 0.672658 0.537726 0.0391069 5013.84 0
: 5 Minimum Test error found - save the configuration
: 5 | 0.666624 0.665348 0.539926 0.0389425 4990.18 0
: 6 Minimum Test error found - save the configuration
: 6 | 0.657391 0.65012 0.539136 0.039065 4999.29 0
: 7 Minimum Test error found - save the configuration
: 7 | 0.645793 0.63953 0.552889 0.039118 4865.98 0
: 8 Minimum Test error found - save the configuration
: 8 | 0.634796 0.630618 0.532868 0.0386425 5058.42 0
: 9 Minimum Test error found - save the configuration
: 9 | 0.62774 0.628891 0.515528 0.0387471 5243.5 0
: 10 Minimum Test error found - save the configuration
: 10 | 0.612291 0.614589 0.50562 0.0385027 5351.97 0
:
: Elapsed time for training with 3200 events: 5.51 sec
: Evaluate deep neural network on CPU using batches with size = 100
:
TMVA_LSTM : [dataset] : Evaluation of TMVA_LSTM on training sample (3200 events)
: Elapsed time for evaluation of 3200 events: 0.204 sec
: Creating xml weight file: ␛[0;36mdataset/weights/TMVAClassification_TMVA_LSTM.weights.xml␛[0m
: Creating standalone class: ␛[0;36mdataset/weights/TMVAClassification_TMVA_LSTM.class.C␛[0m
Factory : Training finished
:
Factory : Train method: TMVA_DNN for Classification
:
: Start of deep neural network training on CPU using MT, nthreads = 4
:
: ***** Deep Learning Network *****
DEEP NEURAL NETWORK: Depth = 4 Input = ( 1, 1, 300 ) Batch size = 256 Loss function = C
Layer 0 DENSE Layer: ( Input = 300 , Width = 64 ) Output = ( 1 , 256 , 64 ) Activation Function = Tanh
Layer 1 DENSE Layer: ( Input = 64 , Width = 64 ) Output = ( 1 , 256 , 64 ) Activation Function = Tanh
Layer 2 DENSE Layer: ( Input = 64 , Width = 64 ) Output = ( 1 , 256 , 64 ) Activation Function = Tanh
Layer 3 DENSE Layer: ( Input = 64 , Width = 1 ) Output = ( 1 , 256 , 1 ) Activation Function = Identity
: Using 2560 events for training and 640 for testing
: Compute initial loss on the validation data
: Training phase 1 of 1: Optimizer ADAM (beta1=0.9,beta2=0.999,eps=1e-07) Learning rate = 0.001 regularization 0 minimum error = 0.732329
: --------------------------------------------------------------
: Epoch | Train Err. Val. Err. t(s)/epoch t(s)/Loss nEvents/s Conv. Steps
: --------------------------------------------------------------
: Start epoch iteration ...
: 1 Minimum Test error found - save the configuration
: 1 | 0.715542 0.690353 0.195072 0.0158154 14281.2 0
: 2 Minimum Test error found - save the configuration
: 2 | 0.675066 0.670943 0.192712 0.0156344 14456.9 0
: 3 Minimum Test error found - save the configuration
: 3 | 0.668255 0.663997 0.192499 0.0156215 14473.3 0
: 4 | 0.66631 0.670202 0.192064 0.0152671 14479.9 1
: 5 | 0.66298 0.674451 0.191153 0.0151178 14542.6 2
: 6 Minimum Test error found - save the configuration
: 6 | 0.654014 0.662883 0.191568 0.0155752 14546.1 0
: 7 | 0.652158 0.68059 0.191556 0.0152882 14523.3 1
: 8 | 0.655377 0.671286 0.191439 0.0152596 14530.7 2
: 9 Minimum Test error found - save the configuration
: 9 | 0.642381 0.660304 0.191933 0.0155824 14516.5 0
: 10 Minimum Test error found - save the configuration
: 10 | 0.650519 0.658225 0.193974 0.0156951 14359.6 0
: 11 Minimum Test error found - save the configuration
: 11 | 0.653502 0.655971 0.192417 0.0155913 14477.5 0
: 12 Minimum Test error found - save the configuration
: 12 | 0.652167 0.653252 0.192193 0.0155988 14496.5 0
: 13 Minimum Test error found - save the configuration
: 13 | 0.649671 0.651133 0.192469 0.0155755 14472 0
: 14 Minimum Test error found - save the configuration
: 14 | 0.644717 0.645647 0.192249 0.0155678 14489.4 0
: 15 | 0.649172 0.65079 0.191389 0.0152358 14532.8 1
: 16 | 0.638646 0.653465 0.191144 0.015184 14548.8 2
: 17 | 0.641435 0.661328 0.19132 0.0152332 14538.3 3
: 18 | 0.643889 0.652668 0.192834 0.0153446 14423.4 4
: 19 | 0.642316 0.664235 0.191782 0.0152833 14504.3 5
: 20 | 0.644848 0.672785 0.191471 0.0152714 14528.9 6
:
: Elapsed time for training with 3200 events: 3.86 sec
: Evaluate deep neural network on CPU using batches with size = 256
:
TMVA_DNN : [dataset] : Evaluation of TMVA_DNN on training sample (3200 events)
: Elapsed time for evaluation of 3200 events: 0.101 sec
: Creating xml weight file: ␛[0;36mdataset/weights/TMVAClassification_TMVA_DNN.weights.xml␛[0m
: Creating standalone class: ␛[0;36mdataset/weights/TMVAClassification_TMVA_DNN.class.C␛[0m
Factory : Training finished
:
Factory : Train method: PyKeras_LSTM for Classification
:
:
: ␛[1m================================================================␛[0m
: ␛[1mH e l p f o r M V A m e t h o d [ PyKeras_LSTM ] :␛[0m
:
: Keras is a high-level API for the Theano and Tensorflow packages.
: This method wraps the training and predictions steps of the Keras
: Python package for TMVA, so that dataloading, preprocessing and
: evaluation can be done within the TMVA system. To use this Keras
: interface, you have to generate a model with Keras first. Then,
: this model can be loaded and trained in TMVA.
:
:
: <Suppress this message by specifying "!H" in the booking option>
: ␛[1m================================================================␛[0m
:
: Split TMVA training data in 2560 training events and 640 validation events
: Training Model Summary
saved recurrent model model_LSTM.h5
Booking Keras model LSTM
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
reshape (Reshape) (None, 10, 30) 0
lstm (LSTM) (None, 10, 10) 1640
flatten (Flatten) (None, 100) 0
dense (Dense) (None, 64) 6464
dense_1 (Dense) (None, 2) 130
=================================================================
Total params: 8234 (32.16 KB)
Trainable params: 8234 (32.16 KB)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
: Option SaveBestOnly: Only model weights with smallest validation loss will be stored
Epoch 1/10
1/26 [>.............................] - ETA: 41s - loss: 0.7166 - accuracy: 0.4800␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
6/26 [=====>........................] - ETA: 0s - loss: 0.7032 - accuracy: 0.5117 ␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
14/26 [===============>..............] - ETA: 0s - loss: 0.6999 - accuracy: 0.5164␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
22/26 [========================>.....] - ETA: 0s - loss: 0.6958 - accuracy: 0.5314
Epoch 1: val_loss improved from inf to 0.68452, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 3s 37ms/step - loss: 0.6952 - accuracy: 0.5309 - val_loss: 0.6845 - val_accuracy: 0.5578
Epoch 2/10
1/26 [>.............................] - ETA: 0s - loss: 0.6880 - accuracy: 0.5500␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
10/26 [==========>...................] - ETA: 0s - loss: 0.6854 - accuracy: 0.5720␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
18/26 [===================>..........] - ETA: 0s - loss: 0.6834 - accuracy: 0.5800␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - ETA: 0s - loss: 0.6792 - accuracy: 0.5875
Epoch 2: val_loss improved from 0.68452 to 0.67624, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 9ms/step - loss: 0.6792 - accuracy: 0.5875 - val_loss: 0.6762 - val_accuracy: 0.5797
Epoch 3/10
1/26 [>.............................] - ETA: 0s - loss: 0.6764 - accuracy: 0.5300␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
9/26 [=========>....................] - ETA: 0s - loss: 0.6734 - accuracy: 0.5667␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
17/26 [==================>...........] - ETA: 0s - loss: 0.6722 - accuracy: 0.5794␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
24/26 [==========================>...] - ETA: 0s - loss: 0.6678 - accuracy: 0.5971
Epoch 3: val_loss improved from 0.67624 to 0.66393, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 10ms/step - loss: 0.6673 - accuracy: 0.5977 - val_loss: 0.6639 - val_accuracy: 0.6125
Epoch 4/10
1/26 [>.............................] - ETA: 0s - loss: 0.6577 - accuracy: 0.6200␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
10/26 [==========>...................] - ETA: 0s - loss: 0.6568 - accuracy: 0.6260␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
18/26 [===================>..........] - ETA: 0s - loss: 0.6562 - accuracy: 0.6261
Epoch 4: val_loss improved from 0.66393 to 0.64637, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 9ms/step - loss: 0.6536 - accuracy: 0.6273 - val_loss: 0.6464 - val_accuracy: 0.6422
Epoch 5/10
1/26 [>.............................] - ETA: 0s - loss: 0.6404 - accuracy: 0.6300␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
10/26 [==========>...................] - ETA: 0s - loss: 0.6403 - accuracy: 0.6450␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
20/26 [======================>.......] - ETA: 0s - loss: 0.6356 - accuracy: 0.6510
Epoch 5: val_loss improved from 0.64637 to 0.62325, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 8ms/step - loss: 0.6368 - accuracy: 0.6480 - val_loss: 0.6232 - val_accuracy: 0.6766
Epoch 6/10
1/26 [>.............................] - ETA: 0s - loss: 0.6246 - accuracy: 0.6400␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
11/26 [===========>..................] - ETA: 0s - loss: 0.6159 - accuracy: 0.6755␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
21/26 [=======================>......] - ETA: 0s - loss: 0.6235 - accuracy: 0.6667
Epoch 6: val_loss improved from 0.62325 to 0.60058, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 8ms/step - loss: 0.6191 - accuracy: 0.6687 - val_loss: 0.6006 - val_accuracy: 0.7047
Epoch 7/10
1/26 [>.............................] - ETA: 0s - loss: 0.5851 - accuracy: 0.7000␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
11/26 [===========>..................] - ETA: 0s - loss: 0.5919 - accuracy: 0.6809␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
21/26 [=======================>......] - ETA: 0s - loss: 0.5986 - accuracy: 0.6757
Epoch 7: val_loss did not improve from 0.60058
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 7ms/step - loss: 0.6017 - accuracy: 0.6738 - val_loss: 0.6012 - val_accuracy: 0.6594
Epoch 8/10
1/26 [>.............................] - ETA: 0s - loss: 0.5544 - accuracy: 0.7600␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
12/26 [============>.................] - ETA: 0s - loss: 0.6004 - accuracy: 0.6708␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
23/26 [=========================>....] - ETA: 0s - loss: 0.5861 - accuracy: 0.6935
Epoch 8: val_loss improved from 0.60058 to 0.56160, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 8ms/step - loss: 0.5866 - accuracy: 0.6941 - val_loss: 0.5616 - val_accuracy: 0.7188
Epoch 9/10
1/26 [>.............................] - ETA: 0s - loss: 0.5078 - accuracy: 0.7500␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
10/26 [==========>...................] - ETA: 0s - loss: 0.5638 - accuracy: 0.6970␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
19/26 [====================>.........] - ETA: 0s - loss: 0.5695 - accuracy: 0.6926
Epoch 9: val_loss improved from 0.56160 to 0.55339, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 8ms/step - loss: 0.5661 - accuracy: 0.7035 - val_loss: 0.5534 - val_accuracy: 0.7172
Epoch 10/10
1/26 [>.............................] - ETA: 0s - loss: 0.5823 - accuracy: 0.6900␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
10/26 [==========>...................] - ETA: 0s - loss: 0.5600 - accuracy: 0.7160␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
19/26 [====================>.........] - ETA: 0s - loss: 0.5515 - accuracy: 0.7253
Epoch 10: val_loss improved from 0.55339 to 0.53100, saving model to trained_model_LSTM.h5
␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈␈
26/26 [==============================] - 0s 8ms/step - loss: 0.5509 - accuracy: 0.7281 - val_loss: 0.5310 - val_accuracy: 0.7484
: Getting training history for item:0 name = 'loss'
: Getting training history for item:1 name = 'accuracy'
: Getting training history for item:2 name = 'val_loss'
: Getting training history for item:3 name = 'val_accuracy'
: Elapsed time for training with 3200 events: 4.64 sec
: Setting up tf.keras
: Using TensorFlow version 2
: Use Keras version from TensorFlow : tf.keras
: Applying GPU option: gpu_options.allow_growth=True
: Disabled TF eager execution when evaluating model
: Loading Keras Model
: Loaded model from file: trained_model_LSTM.h5
PyKeras_LSTM : [dataset] : Evaluation of PyKeras_LSTM on training sample (3200 events)
: Elapsed time for evaluation of 3200 events: 0.246 sec
: Creating xml weight file: ␛[0;36mdataset/weights/TMVAClassification_PyKeras_LSTM.weights.xml␛[0m
: Creating standalone class: ␛[0;36mdataset/weights/TMVAClassification_PyKeras_LSTM.class.C␛[0m
Factory : Training finished
:
Factory : Train method: BDTG for Classification
:
:
: ␛[1m================================================================␛[0m
: ␛[1mH e l p f o r M V A m e t h o d [ BDTG ] :␛[0m
:
: ␛[1m--- Short description:␛[0m
:
: Boosted Decision Trees are a collection of individual decision
: trees which form a multivariate classifier by (weighted) majority
: vote of the individual trees. Consecutive decision trees are
: trained using the original training data set with re-weighted
: events. By default, the AdaBoost method is employed, which gives
: events that were misclassified in the previous tree a larger
: weight in the training of the following tree.
:
: Decision trees are a sequence of binary splits of the data sample
: using a single discriminant variable at a time. A test event
: ending up after the sequence of left-right splits in a final
: ("leaf") node is classified as either signal or background
: depending on the majority type of training events in that node.
:
: ␛[1m--- Performance optimisation:␛[0m
:
: By the nature of the binary splits performed on the individual
: variables, decision trees do not deal well with linear correlations
: between variables (they need to approximate the linear split in
: the two dimensional space by a sequence of splits on the two
: variables individually). Hence decorrelation could be useful
: to optimise the BDT performance.
:
: ␛[1m--- Performance tuning via configuration options:␛[0m
:
: The two most important parameters in the configuration are the
: minimal number of events requested by a leaf node as percentage of the
: number of training events (option "MinNodeSize" replacing the actual number
: of events "nEventsMin" as given in earlier versions
: If this number is too large, detailed features
: in the parameter space are hard to be modelled. If it is too small,
: the risk to overtrain rises and boosting seems to be less effective
: typical values from our current experience for best performance
: are between 0.5(%) and 10(%)
:
: The default minimal number is currently set to
: max(20, (N_training_events / N_variables^2 / 10))
: and can be changed by the user.
:
: The other crucial parameter, the pruning strength ("PruneStrength"),
: is also related to overtraining. It is a regularisation parameter
: that is used when determining after the training which splits
: are considered statistically insignificant and are removed. The
: user is advised to carefully watch the BDT screen output for
: the comparison between efficiencies obtained on the training and
: the independent test sample. They should be equal within statistical
: errors, in order to minimize statistical fluctuations in different samples.
:
: <Suppress this message by specifying "!H" in the booking option>
: ␛[1m================================================================␛[0m
:
BDTG : #events: (reweighted) sig: 1600 bkg: 1600
: #events: (unweighted) sig: 1600 bkg: 1600
: Training 100 Decision Trees ... patience please
: Elapsed time for training with 3200 events: 1.65 sec
BDTG : [dataset] : Evaluation of BDTG on training sample (3200 events)
: Elapsed time for evaluation of 3200 events: 0.0198 sec
: Creating xml weight file: ␛[0;36mdataset/weights/TMVAClassification_BDTG.weights.xml␛[0m
: Creating standalone class: ␛[0;36mdataset/weights/TMVAClassification_BDTG.class.C␛[0m
: data_RNN_CPU.root:/dataset/Method_BDT/BDTG
Factory : Training finished
:
: Ranking input variables (method specific)...
: No variable ranking supplied by classifier: TMVA_LSTM
: No variable ranking supplied by classifier: TMVA_DNN
: No variable ranking supplied by classifier: PyKeras_LSTM
BDTG : Ranking result (top variable is best ranked)
: --------------------------------------------
: Rank : Variable : Variable Importance
: --------------------------------------------
: 1 : vars_time9 : 2.341e-02
: 2 : vars_time8 : 2.214e-02
: 3 : vars_time8 : 2.164e-02
: 4 : vars_time6 : 2.081e-02
: 5 : vars_time9 : 2.020e-02
: 6 : vars_time7 : 1.997e-02
: 7 : vars_time6 : 1.992e-02
: 8 : vars_time8 : 1.924e-02
: 9 : vars_time9 : 1.891e-02
: 10 : vars_time6 : 1.865e-02
: 11 : vars_time7 : 1.818e-02
: 12 : vars_time9 : 1.728e-02
: 13 : vars_time8 : 1.689e-02
: 14 : vars_time9 : 1.686e-02
: 15 : vars_time7 : 1.643e-02
: 16 : vars_time5 : 1.613e-02
: 17 : vars_time7 : 1.555e-02
: 18 : vars_time7 : 1.351e-02
: 19 : vars_time6 : 1.343e-02
: 20 : vars_time7 : 1.311e-02
: 21 : vars_time8 : 1.288e-02
: 22 : vars_time0 : 1.271e-02
: 23 : vars_time7 : 1.259e-02
: 24 : vars_time7 : 1.257e-02
: 25 : vars_time9 : 1.220e-02
: 26 : vars_time7 : 1.210e-02
: 27 : vars_time8 : 1.204e-02
: 28 : vars_time8 : 1.174e-02
: 29 : vars_time6 : 1.127e-02
: 30 : vars_time6 : 1.113e-02
: 31 : vars_time9 : 1.112e-02
: 32 : vars_time9 : 1.072e-02
: 33 : vars_time1 : 1.057e-02
: 34 : vars_time5 : 1.049e-02
: 35 : vars_time9 : 1.034e-02
: 36 : vars_time6 : 1.030e-02
: 37 : vars_time5 : 1.013e-02
: 38 : vars_time8 : 1.001e-02
: 39 : vars_time6 : 9.981e-03
: 40 : vars_time0 : 9.965e-03
: 41 : vars_time5 : 9.948e-03
: 42 : vars_time0 : 9.789e-03
: 43 : vars_time6 : 9.760e-03
: 44 : vars_time5 : 9.442e-03
: 45 : vars_time8 : 9.356e-03
: 46 : vars_time9 : 9.014e-03
: 47 : vars_time0 : 8.981e-03
: 48 : vars_time8 : 8.757e-03
: 49 : vars_time1 : 8.757e-03
: 50 : vars_time0 : 8.151e-03
: 51 : vars_time7 : 8.116e-03
: 52 : vars_time0 : 7.844e-03
: 53 : vars_time1 : 7.838e-03
: 54 : vars_time4 : 7.816e-03
: 55 : vars_time9 : 7.815e-03
: 56 : vars_time9 : 7.767e-03
: 57 : vars_time7 : 7.614e-03
: 58 : vars_time7 : 7.590e-03
: 59 : vars_time0 : 7.439e-03
: 60 : vars_time9 : 7.435e-03
: 61 : vars_time1 : 7.068e-03
: 62 : vars_time9 : 7.012e-03
: 63 : vars_time6 : 6.848e-03
: 64 : vars_time7 : 6.837e-03
: 65 : vars_time0 : 6.786e-03
: 66 : vars_time5 : 6.728e-03
: 67 : vars_time7 : 6.714e-03
: 68 : vars_time9 : 6.661e-03
: 69 : vars_time9 : 6.586e-03
: 70 : vars_time5 : 6.519e-03
: 71 : vars_time9 : 6.497e-03
: 72 : vars_time2 : 6.331e-03
: 73 : vars_time8 : 6.330e-03
: 74 : vars_time1 : 6.197e-03
: 75 : vars_time8 : 6.171e-03
: 76 : vars_time5 : 5.941e-03
: 77 : vars_time7 : 5.918e-03
: 78 : vars_time6 : 5.722e-03
: 79 : vars_time4 : 5.697e-03
: 80 : vars_time8 : 5.516e-03
: 81 : vars_time3 : 5.509e-03
: 82 : vars_time7 : 5.496e-03
: 83 : vars_time0 : 5.436e-03
: 84 : vars_time2 : 5.132e-03
: 85 : vars_time1 : 5.111e-03
: 86 : vars_time6 : 5.067e-03
: 87 : vars_time8 : 5.059e-03
: 88 : vars_time8 : 5.034e-03
: 89 : vars_time6 : 4.913e-03
: 90 : vars_time1 : 4.894e-03
: 91 : vars_time2 : 4.820e-03
: 92 : vars_time9 : 4.771e-03
: 93 : vars_time0 : 4.754e-03
: 94 : vars_time5 : 4.603e-03
: 95 : vars_time1 : 4.398e-03
: 96 : vars_time2 : 4.305e-03
: 97 : vars_time8 : 3.972e-03
: 98 : vars_time8 : 3.865e-03
: 99 : vars_time5 : 3.837e-03
: 100 : vars_time1 : 3.818e-03
: 101 : vars_time4 : 3.806e-03
: 102 : vars_time1 : 3.756e-03
: 103 : vars_time3 : 3.615e-03
: 104 : vars_time7 : 3.182e-03
: 105 : vars_time1 : 2.735e-03
: 106 : vars_time3 : 1.944e-03
: 107 : vars_time1 : 1.732e-03
: 108 : vars_time0 : 0.000e+00
: 109 : vars_time0 : 0.000e+00
: 110 : vars_time0 : 0.000e+00
: 111 : vars_time0 : 0.000e+00
: 112 : vars_time0 : 0.000e+00
: 113 : vars_time0 : 0.000e+00
: 114 : vars_time0 : 0.000e+00
: 115 : vars_time0 : 0.000e+00
: 116 : vars_time0 : 0.000e+00
: 117 : vars_time0 : 0.000e+00
: 118 : vars_time0 : 0.000e+00
: 119 : vars_time0 : 0.000e+00
: 120 : vars_time0 : 0.000e+00
: 121 : vars_time0 : 0.000e+00
: 122 : vars_time0 : 0.000e+00
: 123 : vars_time0 : 0.000e+00
: 124 : vars_time0 : 0.000e+00
: 125 : vars_time0 : 0.000e+00
: 126 : vars_time0 : 0.000e+00
: 127 : vars_time0 : 0.000e+00
: 128 : vars_time1 : 0.000e+00
: 129 : vars_time1 : 0.000e+00
: 130 : vars_time1 : 0.000e+00
: 131 : vars_time1 : 0.000e+00
: 132 : vars_time1 : 0.000e+00
: 133 : vars_time1 : 0.000e+00
: 134 : vars_time1 : 0.000e+00
: 135 : vars_time1 : 0.000e+00
: 136 : vars_time1 : 0.000e+00
: 137 : vars_time1 : 0.000e+00
: 138 : vars_time1 : 0.000e+00
: 139 : vars_time1 : 0.000e+00
: 140 : vars_time1 : 0.000e+00
: 141 : vars_time1 : 0.000e+00
: 142 : vars_time1 : 0.000e+00
: 143 : vars_time1 : 0.000e+00
: 144 : vars_time1 : 0.000e+00
: 145 : vars_time1 : 0.000e+00
: 146 : vars_time2 : 0.000e+00
: 147 : vars_time2 : 0.000e+00
: 148 : vars_time2 : 0.000e+00
: 149 : vars_time2 : 0.000e+00
: 150 : vars_time2 : 0.000e+00
: 151 : vars_time2 : 0.000e+00
: 152 : vars_time2 : 0.000e+00
: 153 : vars_time2 : 0.000e+00
: 154 : vars_time2 : 0.000e+00
: 155 : vars_time2 : 0.000e+00
: 156 : vars_time2 : 0.000e+00
: 157 : vars_time2 : 0.000e+00
: 158 : vars_time2 : 0.000e+00
: 159 : vars_time2 : 0.000e+00
: 160 : vars_time2 : 0.000e+00
: 161 : vars_time2 : 0.000e+00
: 162 : vars_time2 : 0.000e+00
: 163 : vars_time2 : 0.000e+00
: 164 : vars_time2 : 0.000e+00
: 165 : vars_time2 : 0.000e+00
: 166 : vars_time2 : 0.000e+00
: 167 : vars_time2 : 0.000e+00
: 168 : vars_time2 : 0.000e+00
: 169 : vars_time2 : 0.000e+00
: 170 : vars_time2 : 0.000e+00
: 171 : vars_time2 : 0.000e+00
: 172 : vars_time3 : 0.000e+00
: 173 : vars_time3 : 0.000e+00
: 174 : vars_time3 : 0.000e+00
: 175 : vars_time3 : 0.000e+00
: 176 : vars_time3 : 0.000e+00
: 177 : vars_time3 : 0.000e+00
: 178 : vars_time3 : 0.000e+00
: 179 : vars_time3 : 0.000e+00
: 180 : vars_time3 : 0.000e+00
: 181 : vars_time3 : 0.000e+00
: 182 : vars_time3 : 0.000e+00
: 183 : vars_time3 : 0.000e+00
: 184 : vars_time3 : 0.000e+00
: 185 : vars_time3 : 0.000e+00
: 186 : vars_time3 : 0.000e+00
: 187 : vars_time3 : 0.000e+00
: 188 : vars_time3 : 0.000e+00
: 189 : vars_time3 : 0.000e+00
: 190 : vars_time3 : 0.000e+00
: 191 : vars_time3 : 0.000e+00
: 192 : vars_time3 : 0.000e+00
: 193 : vars_time3 : 0.000e+00
: 194 : vars_time3 : 0.000e+00
: 195 : vars_time3 : 0.000e+00
: 196 : vars_time3 : 0.000e+00
: 197 : vars_time3 : 0.000e+00
: 198 : vars_time3 : 0.000e+00
: 199 : vars_time4 : 0.000e+00
: 200 : vars_time4 : 0.000e+00
: 201 : vars_time4 : 0.000e+00
: 202 : vars_time4 : 0.000e+00
: 203 : vars_time4 : 0.000e+00
: 204 : vars_time4 : 0.000e+00
: 205 : vars_time4 : 0.000e+00
: 206 : vars_time4 : 0.000e+00
: 207 : vars_time4 : 0.000e+00
: 208 : vars_time4 : 0.000e+00
: 209 : vars_time4 : 0.000e+00
: 210 : vars_time4 : 0.000e+00
: 211 : vars_time4 : 0.000e+00
: 212 : vars_time4 : 0.000e+00
: 213 : vars_time4 : 0.000e+00
: 214 : vars_time4 : 0.000e+00
: 215 : vars_time4 : 0.000e+00
: 216 : vars_time4 : 0.000e+00
: 217 : vars_time4 : 0.000e+00
: 218 : vars_time4 : 0.000e+00
: 219 : vars_time4 : 0.000e+00
: 220 : vars_time4 : 0.000e+00
: 221 : vars_time4 : 0.000e+00
: 222 : vars_time4 : 0.000e+00
: 223 : vars_time4 : 0.000e+00
: 224 : vars_time4 : 0.000e+00
: 225 : vars_time4 : 0.000e+00
: 226 : vars_time5 : 0.000e+00
: 227 : vars_time5 : 0.000e+00
: 228 : vars_time5 : 0.000e+00
: 229 : vars_time5 : 0.000e+00
: 230 : vars_time5 : 0.000e+00
: 231 : vars_time5 : 0.000e+00
: 232 : vars_time5 : 0.000e+00
: 233 : vars_time5 : 0.000e+00
: 234 : vars_time5 : 0.000e+00
: 235 : vars_time5 : 0.000e+00
: 236 : vars_time5 : 0.000e+00
: 237 : vars_time5 : 0.000e+00
: 238 : vars_time5 : 0.000e+00
: 239 : vars_time5 : 0.000e+00
: 240 : vars_time5 : 0.000e+00
: 241 : vars_time5 : 0.000e+00
: 242 : vars_time5 : 0.000e+00
: 243 : vars_time5 : 0.000e+00
: 244 : vars_time5 : 0.000e+00
: 245 : vars_time5 : 0.000e+00
: 246 : vars_time6 : 0.000e+00
: 247 : vars_time6 : 0.000e+00
: 248 : vars_time6 : 0.000e+00
: 249 : vars_time6 : 0.000e+00
: 250 : vars_time6 : 0.000e+00
: 251 : vars_time6 : 0.000e+00
: 252 : vars_time6 : 0.000e+00
: 253 : vars_time6 : 0.000e+00
: 254 : vars_time6 : 0.000e+00
: 255 : vars_time6 : 0.000e+00
: 256 : vars_time6 : 0.000e+00
: 257 : vars_time6 : 0.000e+00
: 258 : vars_time6 : 0.000e+00
: 259 : vars_time6 : 0.000e+00
: 260 : vars_time6 : 0.000e+00
: 261 : vars_time6 : 0.000e+00
: 262 : vars_time6 : 0.000e+00
: 263 : vars_time7 : 0.000e+00
: 264 : vars_time7 : 0.000e+00
: 265 : vars_time7 : 0.000e+00
: 266 : vars_time7 : 0.000e+00
: 267 : vars_time7 : 0.000e+00
: 268 : vars_time7 : 0.000e+00
: 269 : vars_time7 : 0.000e+00
: 270 : vars_time7 : 0.000e+00
: 271 : vars_time7 : 0.000e+00
: 272 : vars_time7 : 0.000e+00
: 273 : vars_time7 : 0.000e+00
: 274 : vars_time7 : 0.000e+00
: 275 : vars_time7 : 0.000e+00
: 276 : vars_time8 : 0.000e+00
: 277 : vars_time8 : 0.000e+00
: 278 : vars_time8 : 0.000e+00
: 279 : vars_time8 : 0.000e+00
: 280 : vars_time8 : 0.000e+00
: 281 : vars_time8 : 0.000e+00
: 282 : vars_time8 : 0.000e+00
: 283 : vars_time8 : 0.000e+00
: 284 : vars_time8 : 0.000e+00
: 285 : vars_time8 : 0.000e+00
: 286 : vars_time8 : 0.000e+00
: 287 : vars_time8 : 0.000e+00
: 288 : vars_time8 : 0.000e+00
: 289 : vars_time9 : 0.000e+00
: 290 : vars_time9 : 0.000e+00
: 291 : vars_time9 : 0.000e+00
: 292 : vars_time9 : 0.000e+00
: 293 : vars_time9 : 0.000e+00
: 294 : vars_time9 : 0.000e+00
: 295 : vars_time9 : 0.000e+00
: 296 : vars_time9 : 0.000e+00
: 297 : vars_time9 : 0.000e+00
: 298 : vars_time9 : 0.000e+00
: 299 : vars_time9 : 0.000e+00
: 300 : vars_time9 : 0.000e+00
: --------------------------------------------
TH1.Print Name = TrainingHistory_TMVA_LSTM_trainingError, Entries= 0, Total sum= 6.59106
TH1.Print Name = TrainingHistory_TMVA_LSTM_valError, Entries= 0, Total sum= 6.58005
TH1.Print Name = TrainingHistory_TMVA_DNN_trainingError, Entries= 0, Total sum= 13.103
TH1.Print Name = TrainingHistory_TMVA_DNN_valError, Entries= 0, Total sum= 13.2645
TH1.Print Name = TrainingHistory_PyKeras_LSTM_'accuracy', Entries= 0, Total sum= 6.45977
TH1.Print Name = TrainingHistory_PyKeras_LSTM_'loss', Entries= 0, Total sum= 6.25652
TH1.Print Name = TrainingHistory_PyKeras_LSTM_'val_accuracy', Entries= 0, Total sum= 6.61719
TH1.Print Name = TrainingHistory_PyKeras_LSTM_'val_loss', Entries= 0, Total sum= 6.14208
Factory : === Destroy and recreate all methods via weight files for testing ===
:
: Reading weight file: ␛[0;36mdataset/weights/TMVAClassification_TMVA_LSTM.weights.xml␛[0m
: Reading weight file: ␛[0;36mdataset/weights/TMVAClassification_TMVA_DNN.weights.xml␛[0m
: Reading weight file: ␛[0;36mdataset/weights/TMVAClassification_PyKeras_LSTM.weights.xml␛[0m
: Reading weight file: ␛[0;36mdataset/weights/TMVAClassification_BDTG.weights.xml␛[0m
Factory : ␛[1mTest all methods␛[0m
Factory : Test method: TMVA_LSTM for Classification performance
:
: Evaluate deep neural network on CPU using batches with size = 800
:
TMVA_LSTM : [dataset] : Evaluation of TMVA_LSTM on testing sample (800 events)
: Elapsed time for evaluation of 800 events: 0.0481 sec
Factory : Test method: TMVA_DNN for Classification performance
:
: Evaluate deep neural network on CPU using batches with size = 800
:
TMVA_DNN : [dataset] : Evaluation of TMVA_DNN on testing sample (800 events)
: Elapsed time for evaluation of 800 events: 0.0202 sec
Factory : Test method: PyKeras_LSTM for Classification performance
:
: Setting up tf.keras
: Using TensorFlow version 2
: Use Keras version from TensorFlow : tf.keras
: Applying GPU option: gpu_options.allow_growth=True
: Disabled TF eager execution when evaluating model
: Loading Keras Model
: Loaded model from file: trained_model_LSTM.h5
PyKeras_LSTM : [dataset] : Evaluation of PyKeras_LSTM on testing sample (800 events)
: Elapsed time for evaluation of 800 events: 0.236 sec
Factory : Test method: BDTG for Classification performance
:
BDTG : [dataset] : Evaluation of BDTG on testing sample (800 events)
: Elapsed time for evaluation of 800 events: 0.00581 sec
Factory : ␛[1mEvaluate all methods␛[0m
Factory : Evaluate classifier: TMVA_LSTM
:
TMVA_LSTM : [dataset] : Loop over test events and fill histograms with classifier response...
:
: Evaluate deep neural network on CPU using batches with size = 1000
:
: Dataset[dataset] : variable plots are not produces ! The number of variables is 300 , it is larger than 200
Factory : Evaluate classifier: TMVA_DNN
:
TMVA_DNN : [dataset] : Loop over test events and fill histograms with classifier response...
:
: Evaluate deep neural network on CPU using batches with size = 1000
:
: Dataset[dataset] : variable plots are not produces ! The number of variables is 300 , it is larger than 200
Factory : Evaluate classifier: PyKeras_LSTM
:
PyKeras_LSTM : [dataset] : Loop over test events and fill histograms with classifier response...
:
: Dataset[dataset] : variable plots are not produces ! The number of variables is 300 , it is larger than 200
Factory : Evaluate classifier: BDTG
:
BDTG : [dataset] : Loop over test events and fill histograms with classifier response...
:
: Dataset[dataset] : variable plots are not produces ! The number of variables is 300 , it is larger than 200
:
: Evaluation results ranked by best signal efficiency and purity (area)
: -------------------------------------------------------------------------------------------------------------------
: DataSet MVA
: Name: Method: ROC-integ
: dataset BDTG : 0.840
: dataset PyKeras_LSTM : 0.800
: dataset TMVA_DNN : 0.688
: dataset TMVA_LSTM : 0.685
: -------------------------------------------------------------------------------------------------------------------
:
: Testing efficiency compared to training efficiency (overtraining check)
: -------------------------------------------------------------------------------------------------------------------
: DataSet MVA Signal efficiency: from test sample (from training sample)
: Name: Method: @B=0.01 @B=0.10 @B=0.30
: -------------------------------------------------------------------------------------------------------------------
: dataset BDTG : 0.165 (0.295) 0.563 (0.677) 0.808 (0.861)
: dataset PyKeras_LSTM : 0.175 (0.140) 0.460 (0.467) 0.748 (0.753)
: dataset TMVA_DNN : 0.074 (0.065) 0.335 (0.316) 0.550 (0.540)
: dataset TMVA_LSTM : 0.042 (0.085) 0.263 (0.327) 0.550 (0.583)
: -------------------------------------------------------------------------------------------------------------------
:
Dataset:dataset : Created tree 'TestTree' with 800 events
:
Dataset:dataset : Created tree 'TrainTree' with 3200 events
:
Factory : ␛[1mThank you for using TMVA!␛[0m
: ␛[1mFor citation information, please visit: http://tmva.sf.net/citeTMVA.html␛[0m
nthreads = 4
# TMVA Classification Example Using a Recurrent Neural Network
# This is an example of using a RNN in TMVA.
# We do the classification using a toy data set containing a time series of data sample ntimes
# and with dimension ndim that is generated when running the provided function `MakeTimeData (nevents, ntime, ndim)`
import ROOT
num_threads = 4 # use max 4 threads
# do enable MT running
if "imt" in ROOT.gROOT.GetConfigFeatures():
ROOT.EnableImplicitMT(num_threads)
# switch off MT in OpenBLAS to avoid conflict with tbb
ROOT.gSystem.Setenv("OMP_NUM_THREADS", "1")
print("Running with nthreads = {}".format(ROOT.GetThreadPoolSize()))
else:
print("Running in serial mode since ROOT does not support MT")
TMVA = ROOT.TMVA
TFile = ROOT.TFile
import os
import importlib
## Helper function to generate the time data set
## make some time data but not of fixed length.
## use a poisson with mu = 5 and truncated at 10
def MakeTimeData(n, ntime, ndim):
# ntime = 10;
# ndim = 30; // number of dim/time
fname = "time_data_t" + str(ntime) + "_d" + str(ndim) + ".root"
v1 = []
v2 = []
for i in range(ntime):
v1.append(ROOT.TH1D("h1_" + str(i), "h1", ndim, 0, 10))
v2.append(ROOT.TH1D("h2_" + str(i), "h2", ndim, 0, 10))
f1 = ROOT.TF1("f1", "gaus")
f2 = ROOT.TF1("f2", "gaus")
sgn = ROOT.TTree("sgn", "sgn")
bkg = ROOT.TTree("bkg", "bkg")
f = TFile(fname, "RECREATE")
x1 = []
x2 = []
for i in range(ntime):
x1.append(ROOT.std.vector["float"](ndim))
x2.append(ROOT.std.vector["float"](ndim))
for i in range(ntime):
bkg.Branch("vars_time" + str(i), "std::vector<float>", x1[i])
sgn.Branch("vars_time" + str(i), "std::vector<float>", x2[i])
sgn.SetDirectory(f)
bkg.SetDirectory(f)
ROOT.gRandom.SetSeed(0)
mean1 = ROOT.std.vector["double"](ntime)
mean2 = ROOT.std.vector["double"](ntime)
sigma1 = ROOT.std.vector["double"](ntime)
sigma2 = ROOT.std.vector["double"](ntime)
for j in range(ntime):
mean1[j] = 5.0 + 0.2 * ROOT.TMath.Sin(ROOT.TMath.Pi() * j / float(ntime))
mean2[j] = 5.0 + 0.2 * ROOT.TMath.Cos(ROOT.TMath.Pi() * j / float(ntime))
sigma1[j] = 4 + 0.3 * ROOT.TMath.Sin(ROOT.TMath.Pi() * j / float(ntime))
sigma2[j] = 4 + 0.3 * ROOT.TMath.Cos(ROOT.TMath.Pi() * j / float(ntime))
for i in range(n):
if i % 1000 == 0:
print("Generating event ... %d", i)
for j in range(ntime):
h1 = v1[j]
h2 = v2[j]
h1.Reset()
h2.Reset()
f1.SetParameters(1, mean1[j], sigma1[j])
f2.SetParameters(1, mean2[j], sigma2[j])
h1.FillRandom("f1", 1000)
h2.FillRandom("f2", 1000)
for k in range(ntime):
# std::cout << j*10+k << " ";
x1[j][k] = h1.GetBinContent(k + 1) + ROOT.gRandom.Gaus(0, 10)
x2[j][k] = h2.GetBinContent(k + 1) + ROOT.gRandom.Gaus(0, 10)
sgn.Fill()
bkg.Fill()
if n == 1:
c1 = ROOT.TCanvas()
c1.Divide(ntime, 2)
for j in range(ntime):
c1.cd(j + 1)
v1[j].Draw()
for j in range(ntime):
c1.cd(ntime + j + 1)
v2[j].Draw()
ROOT.gPad.Update()
if n > 1:
sgn.Write()
bkg.Write()
sgn.Print()
bkg.Print()
f.Close()
## macro for performing a classification using a Recurrent Neural Network
## @param use_type
## use_type = 0 use Simple RNN network
## use_type = 1 use LSTM network
## use_type = 2 use GRU
## use_type = 3 build 3 different networks with RNN, LSTM and GRU
use_type = 1
ninput = 30
ntime = 10
batchSize = 100
maxepochs = 10
nTotEvts = 2000 # total events to be generated for signal or background
useKeras = True
useTMVA_RNN = True
useTMVA_DNN = True
useTMVA_BDT = False
tf_spec = importlib.util.find_spec("tensorflow")
if tf_spec is None:
useKeras = False
ROOT.Warning("TMVA_RNN_Classificaton","Skip using Keras since tensorflow is not installed")
rnn_types = ["RNN", "LSTM", "GRU"]
use_rnn_type = [1, 1, 1]
if 0 <= use_type < 3:
use_rnn_type = [0, 0, 0]
use_rnn_type[use_type] = 1
useGPU = True # use GPU for TMVA if available
useGPU = "tmva-gpu" in ROOT.gROOT.GetConfigFeatures()
useTMVA_RNN = ("tmva-cpu" in ROOT.gROOT.GetConfigFeatures()) or useGPU
if useTMVA_RNN:
ROOT.Warning(
"TMVA_RNN_Classification",
"TMVA is not build with GPU or CPU multi-thread support. Cannot use TMVA Deep Learning for RNN",
)
archString = "GPU" if useGPU else "CPU"
writeOutputFile = True
rnn_type = "RNN"
if "tmva-pymva" in ROOT.gROOT.GetConfigFeatures():
else:
useKeras = False
inputFileName = "time_data_t10_d30.root"
fileDoesNotExist = ROOT.gSystem.AccessPathName(inputFileName)
# if file does not exists create it
if fileDoesNotExist:
MakeTimeData(nTotEvts, ntime, ninput)
inputFile = TFile.Open(inputFileName)
if inputFile is None:
raise ROOT.Error("Error opening input file %s - exit", inputFileName.Data())
print("--- RNNClassification : Using input file: {}".format(inputFile.GetName()))
# Create a ROOT output file where TMVA will store ntuples, histograms, etc.
outfileName = "data_RNN_" + archString + ".root"
outputFile = None
if writeOutputFile:
outputFile = TFile.Open(outfileName, "RECREATE")
## Declare Factory
# Create the Factory class. Later you can choose the methods
# whose performance you'd like to investigate.
# The factory is the major TMVA object you have to interact with. Here is the list of parameters you need to
# pass
# - The first argument is the base of the name of all the output
# weightfiles in the directory weight/ that will be created with the
# method parameters
# - The second argument is the output file for the training results
#
# - The third argument is a string option defining some general configuration for the TMVA session.
# For example all TMVA output can be suppressed by removing the "!" (not) in front of the "Silent" argument in
# the option string
# // Creating the factory object
factory = TMVA.Factory(
"TMVAClassification",
outputFile,
V=False,
Silent=False,
Color=True,
DrawProgressBar=True,
Transformations=None,
Correlations=False,
AnalysisType="Classification",
ModelPersistence=True,
)
dataloader = TMVA.DataLoader("dataset")
signalTree = inputFile.Get("sgn")
background = inputFile.Get("bkg")
nvar = ninput * ntime
## add variables - use new AddVariablesArray function
for i in range(ntime):
dataloader.AddVariablesArray("vars_time" + str(i), ninput)
dataloader.AddSignalTree(signalTree, 1.0)
dataloader.AddBackgroundTree(background, 1.0)
# check given input
datainfo = dataloader.GetDataSetInfo()
vars = datainfo.GetListOfVariables()
print("number of variables is {}".format(vars.size()))
for v in vars:
print(v)
nTrainSig = 0.8 * nTotEvts
nTrainBkg = 0.8 * nTotEvts
# Apply additional cuts on the signal and background samples (can be different)
mycuts = "" # for example: TCut mycuts = "abs(var1)<0.5 && abs(var2-0.5)<1";
mycutb = ""
# build the string options for DataLoader::PrepareTrainingAndTestTree
dataloader.PrepareTrainingAndTestTree(
mycuts,
mycutb,
nTrain_Signal=nTrainSig,
nTrain_Background=nTrainBkg,
SplitMode="Random",
SplitSeed=100,
NormMode="NumEvents",
V=False,
CalcCorrelations=False,
)
print("prepared DATA LOADER ")
## Book TMVA recurrent models
# Book the different types of recurrent models in TMVA (SimpleRNN, LSTM or GRU)
if useTMVA_RNN:
for i in range(3):
if not use_rnn_type[i]:
continue
rnn_type = rnn_types[i]
## Define RNN layer layout
## it should be LayerType (RNN or LSTM or GRU) | number of units | number of inputs | time steps | remember output (typically no=0 | return full sequence
rnnLayout = str(rnn_type) + "|10|" + str(ninput) + "|" + str(ntime) + "|0|1,RESHAPE|FLAT,DENSE|64|TANH,LINEAR"
## Defining Training strategies. Different training strings can be concatenate. Use however only one
trainingString1 = "LearningRate=1e-3,Momentum=0.0,Repetitions=1,ConvergenceSteps=5,BatchSize=" + str(batchSize)
trainingString1 += ",TestRepetitions=1,WeightDecay=1e-2,Regularization=None,MaxEpochs=" + str(maxepochs)
trainingString1 += "Optimizer=ADAM,DropConfig=0.0+0.+0.+0."
## define the inputlayout string for RNN
## the input data should be organize as following:
##/ input layout for RNN: time x ndim
## add after RNN a reshape layer (needed top flatten the output) and a dense layer with 64 units and a last one
## Note the last layer is linear because when using Crossentropy a Sigmoid is applied already
## Define the full RNN Noption string adding the final options for all network
rnnName = "TMVA_" + str(rnn_type)
factory.BookMethod(
dataloader,
TMVA.Types.kDL,
rnnName,
H=False,
V=True,
ErrorStrategy="CROSSENTROPY",
VarTransform=None,
WeightInitialization="XAVIERUNIFORM",
ValidationSize=0.2,
RandomSeed=1234,
InputLayout=str(ntime) + "|" + str(ninput),
Layout=rnnLayout,
TrainingStrategy=trainingString1,
Architecture=archString
)
## Book TMVA fully connected dense layer models
if useTMVA_DNN:
# Method DL with Dense Layer
# Training strategies.
trainingString1 = ROOT.TString(
"LearningRate=1e-3,Momentum=0.0,Repetitions=1,"
"ConvergenceSteps=10,BatchSize=256,TestRepetitions=1,"
"WeightDecay=1e-4,Regularization=None,MaxEpochs=20"
"DropConfig=0.0+0.+0.+0.,Optimizer=ADAM:"
) # + "|" + trainingString2
# General Options.
trainingString1.Append(archString)
dnnName = "TMVA_DNN"
factory.BookMethod(
dataloader,
TMVA.Types.kDL,
dnnName,
H=False,
V=True,
ErrorStrategy="CROSSENTROPY",
VarTransform=None,
WeightInitialization="XAVIER",
RandomSeed=0,
InputLayout="1|1|" + str(ntime * ninput),
Layout="DENSE|64|TANH,DENSE|TANH|64,DENSE|TANH|64,LINEAR",
TrainingStrategy=trainingString1
)
## Book Keras recurrent models
# Book the different types of recurrent models in Keras (SimpleRNN, LSTM or GRU)
if useKeras:
for i in range(3):
if use_rnn_type[i]:
modelName = "model_" + rnn_types[i] + ".h5"
trainedModelName = "trained_" + modelName
print("Building recurrent keras model using a", rnn_types[i], "layer")
# create python script which can be executed
# create 2 conv2d layer + maxpool + dense
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam
# from keras.initializers import TruncatedNormal
# from keras import initializations
from tensorflow.keras.layers import Input, Dense, Dropout, Flatten, SimpleRNN, GRU, LSTM, Reshape, BatchNormalization
model = Sequential()
model.add(Reshape((10, 30), input_shape=(10 * 30,)))
# add recurrent neural network depending on type / Use option to return the full output
if rnn_types[i] == "LSTM":
model.add(LSTM(units=10, return_sequences=True))
elif rnn_types[i] == "GRU":
model.add(GRU(units=10, return_sequences=True))
else:
model.add(SimpleRNN(units=10, return_sequences=True))
# m.AddLine("model.add(BatchNormalization())");
model.add(Flatten()) # needed if returning the full time output sequence
model.add(Dense(64, activation="tanh"))
model.add(Dense(2, activation="sigmoid"))
model.compile(loss="binary_crossentropy", optimizer=Adam(learning_rate=0.001), weighted_metrics=["accuracy"])
model.save(modelName)
model.summary()
print("saved recurrent model", modelName)
if not os.path.exists(modelName):
useKeras = False
print("Error creating Keras recurrent model file - Skip using Keras")
else:
# book PyKeras method only if Keras model could be created
print("Booking Keras model ", rnn_types[i])
factory.BookMethod(
dataloader,
TMVA.Types.kPyKeras,
"PyKeras_" + rnn_types[i],
H=True,
V=False,
VarTransform=None,
FilenameModel=modelName,
FilenameTrainedModel="trained_" + modelName,
NumEpochs=maxepochs,
BatchSize=batchSize,
GpuOptions="allow_growth=True",
)
# use BDT in case not using Keras or TMVA DL
if not useKeras or not useTMVA_BDT:
useTMVA_BDT = True
## Book TMVA BDT
if useTMVA_BDT:
factory.BookMethod(
dataloader,
TMVA.Types.kBDT,
"BDTG",
H=True,
V=False,
NTrees=100,
MinNodeSize="2.5%",
BoostType="Grad",
Shrinkage=0.10,
UseBaggedBoost=True,
BaggedSampleFraction=0.5,
nCuts=20,
MaxDepth=2,
)
## Train all methods
factory.TrainAllMethods()
print("nthreads = {}".format(ROOT.GetThreadPoolSize()))
# ---- Evaluate all MVAs using the set of test events
factory.TestAllMethods()
# ----- Evaluate and compare performance of all configured MVAs
factory.EvaluateAllMethods()
# check method
# plot ROC curve
c1 = factory.GetROCCurve(dataloader)
c1.Draw()
if outputFile:
outputFile.Close()
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 format
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
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.
Definition TFile.cxx:4089
static Config & Instance()
static function: returns TMVA instance
Definition Config.cxx:98
This is the main MVA steering class.
Definition Factory.h:80
static void PyInitialize()
Initialize Python interpreter.
static Tools & Instance()
Definition Tools.cxx:71
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition TROOT.cxx:539
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
Definition TROOT.cxx:577
th1 Draw()
Author
Harshal Shende

Definition in file TMVA_RNN_Classification.py.