import ROOT
from ROOT import TFile, TMVA, TCut
ValueErrorTraceback (most recent call last) <ipython-input-1-2fba2a3c1dd1> in <module>() ----> 1 import ROOT 2 from ROOT import TFile, TMVA, TCut /home/qati/.usr/root/lib/ROOT.py in <module>() 589 ip = get_ipython() 590 if hasattr(ip,"kernel"): --> 591 import JupyROOT 592 import JsMVA 593 /home/qati/.usr/root/lib/ROOT.py in _importhook(name, *args, **kwds) 301 except Exception: 302 pass --> 303 return _orig_ihook( name, *args, **kwds ) 304 305 __builtin__.__import__ = _importhook /home/qati/.usr/root/lib/JupyROOT/__init__.py in <module>() 2 3 if '__IPYTHON__' in __builtins__ and __IPYTHON__: ----> 4 utils.iPythonize() /home/qati/.usr/root/lib/JupyROOT/utils.py in iPythonize() 504 def iPythonize(): 505 setStyle() --> 506 loadExtensionsAndCapturers() 507 enableCppHighlighting() 508 enhanceROOTModule() /home/qati/.usr/root/lib/JupyROOT/utils.py in loadExtensionsAndCapturers() 486 extMgr.load_extension(extName) 487 cppcompleter.load_ipython_extension(ip) --> 488 captures.append(StreamCapture()) 489 captures.append(CaptureDrawnPrimitives()) 490 /home/qati/.usr/root/lib/JupyROOT/utils.py in __init__(self, ip) 249 self.errString = "" 250 --> 251 self.asyncCapturer = handlers.Runner(self.syncCapture) 252 253 def syncCapture(self, defout = ''): /home/qati/.usr/root/lib/JupyROOT/handlers.py in __init__(self, function) 89 self.function = function 90 if platform != 'darwin': ---> 91 setrlimit(RLIMIT_STACK,(RLIM_INFINITY,RLIM_INFINITY)) 92 self.thread = None 93 ValueError: current limit exceeds maximum limit
%jsmva on
TMVA.Tools.Instance()
factory = TMVA.Factory(JobName="TMVAClassification",
V=False, Transformations=["I", "D", "P", "G", "D"],
AnalysisType="Classification")
Factory | You are running ROOT Version: 6.07/07, Apr 1, 2016 |
if ROOT.gSystem.AccessPathName( "tmva_class_example.root" ) != 0:
ROOT.gSystem.Exec( "wget https://root.cern.ch/files/tmva_class_example.root")
dataset = "tmva_class_example" #the dataset name
loader = TMVA.DataLoader(dataset)
loader.AddVariable( "myvar1 := var1+var2", 'F' )
loader.AddVariable( "myvar2 := var1-var2", "Expression 2", 'F' )
loader.AddVariable( "var3", "Variable 3", 'F' )
loader.AddVariable( "var4", "Variable 4", 'F' )
loader.AddSpectator( "spec1:=var1*2", "Spectator 1", 'F' )
loader.AddSpectator( "spec2:=var1*3", "Spectator 2", 'F' )
input = TFile.Open( "tmva_class_example.root" )
# Get the signal and background trees for training
signal = input.Get( "TreeS" )
background = input.Get( "TreeB" )
# Global event weights (see below for setting event-wise weights)
signalWeight = 1.0
backgroundWeight = 1.0
loader.AddSignalTree(signal, signalWeight)
loader.AddBackgroundTree(background, backgroundWeight)
loader.fSignalWeight = signalWeight
loader.fBackgroundWeight = backgroundWeight
loader.fTreeS = signal
loader.fTreeB = background
DataSetInfo |
| |||
Add Tree TreeS of type Signal with 6000 events | ||||
DataSetInfo |
| |||
Add Tree TreeB of type Background with 6000 events |
mycuts = TCut("")
mycutb = TCut("")
loader.PrepareTrainingAndTestTree(SigCut=mycuts, BkgCut=mycutb,
nTrain_Signal=0, nTrain_Background=0, SplitMode="Random", NormMode="NumEvents", V=False)
factory.BookDNN(loader)
trainingStrategy = [{
"LearningRate": 1e-1,
"Momentum": 0.0,
"Repetitions": 1,
"ConvergenceSteps": 300,
"BatchSize": 20,
"TestRepetitions": 15,
"WeightDecay": 0.001,
"Regularization": "NONE",
"DropConfig": "0.0+0.5+0.5+0.5",
"DropRepetitions": 1,
"Multithreading": True
}, {
"LearningRate": 1e-2,
"Momentum": 0.5,
"Repetitions": 1,
"ConvergenceSteps": 300,
"BatchSize": 30,
"TestRepetitions": 7,
"WeightDecay": 0.001,
"Regularization": "L2",
"DropConfig": "0.0+0.1+0.1+0.1",
"DropRepetitions": 1,
"Multithreading": True
}, {
"LearningRate": 1e-2,
"Momentum": 0.3,
"Repetitions": 1,
"ConvergenceSteps": 300,
"BatchSize": 40,
"TestRepetitions": 7,
"WeightDecay": 0.001,
"Regularization": "L2",
"Multithreading": True
},{
"LearningRate": 1e-3,
"Momentum": 0.1,
"Repetitions": 1,
"ConvergenceSteps": 200,
"BatchSize": 70,
"TestRepetitions": 7,
"WeightDecay": 0.001,
"Regularization": "NONE",
"Multithreading": True
}]
#factory.BookMethod(DataLoader=loader, Method=TMVA.Types.kDNN, MethodTitle="DNN", H = False, V=False,
# VarTransform="Normalize", ErrorStrategy="CROSSENTROPY", Layout=["TANH|100", "TANH|50", "TANH|10", "LINEAR"],
# TrainingStrategy=trainingStrategy)
<ROOT.TMVA::MethodDNN object ("DNN") at 0x5985e90>
Factory | Booking method: DNN | |||
DNN |
| |||
Norm | Transformation, Variable selection : | |||
Input : variable 'myvar1' <---> Output : variable 'myvar1' | ||||
Input : variable 'myvar2' <---> Output : variable 'myvar2' | ||||
Input : variable 'var3' <---> Output : variable 'var3' | ||||
Input : variable 'var4' <---> Output : variable 'var4' |
factory.BookMethod( DataLoader=loader, Method=TMVA.Types.kMLP, MethodTitle="MLP",
H=False, V=False, NeuronType="tanh", VarTransform="N", NCycles=600, HiddenLayers="N+5",
TestRate=5, UseRegulator=False )
<ROOT.TMVA::MethodMLP object ("MLP") at 0x5a79860>
Factory | Booking method: MLP | |||
MLP |
| |||
Norm | Transformation, Variable selection : | |||
Input : variable 'myvar1' <---> Output : variable 'myvar1' | ||||
Input : variable 'myvar2' <---> Output : variable 'myvar2' | ||||
Input : variable 'var3' <---> Output : variable 'var3' | ||||
Input : variable 'var4' <---> Output : variable 'var4' | ||||
MLP | Building Network. | |||
Initializing weights |
factory.BookMethod(DataLoader= loader, Method=TMVA.Types.kBDT, MethodTitle="BDT",
H=False,V=False,NTrees=850,MinNodeSize="2.5%",MaxDepth=3,BoostType="AdaBoost", AdaBoostBeta=0.5,
UseBaggedBoost=True,BaggedSampleFraction=0.5, SeparationType="GiniIndex", nCuts=20 )
<ROOT.TMVA::MethodBDT object ("BDT") at 0x5b219a0>
Factory | Booking method: BDT | ||||||||||||||||||||||
DataSetFactory |
| ||||||||||||||||||||||
| |||||||||||||||||||||||
DataSetInfo | Correlation matrix (Signal) | ||||||||||||||||||||||
DataSetInfo | Correlation matrix (Background) | ||||||||||||||||||||||
DataSetFactory |
|
factory.TrainAllMethods()
TFHandler_DNN |
| ||||||||||||||||||||||||||||||
TFHandler_DNN |
| ||||||||||||||||||||||||||||||
TFHandler_DNN |
| ||||||||||||||||||||||||||||||
Add Layer with 100 nodes. | |||||||||||||||||||||||||||||||
Add Layer with 50 nodes. | |||||||||||||||||||||||||||||||
Add Layer with 10 nodes. | |||||||||||||||||||||||||||||||
Add Layer with 1 nodes. | |||||||||||||||||||||||||||||||
Total number of Synapses = 6010 | |||||||||||||||||||||||||||||||
Training with learning rate = 0.1, momentum = 0, repetitions = 1 | |||||||||||||||||||||||||||||||
Drop configuration | |||||||||||||||||||||||||||||||
drop repetitions = 1 | |||||||||||||||||||||||||||||||
Layer 0 = 0 | |||||||||||||||||||||||||||||||
Layer 1 = 0.5 | |||||||||||||||||||||||||||||||
Layer 2 = 0.5 | |||||||||||||||||||||||||||||||
Layer 3 = 0.5 | |||||||||||||||||||||||||||||||
Training with learning rate = 0.01, momentum = 0.5, repetitions = 1 | |||||||||||||||||||||||||||||||
Drop configuration | |||||||||||||||||||||||||||||||
drop repetitions = 1 | |||||||||||||||||||||||||||||||
Layer 0 = 0 | |||||||||||||||||||||||||||||||
Layer 1 = 0.1 | |||||||||||||||||||||||||||||||
Layer 2 = 0.1 | |||||||||||||||||||||||||||||||
Layer 3 = 0.1 | |||||||||||||||||||||||||||||||
Training with learning rate = 0.01, momentum = 0.3, repetitions = 1 | |||||||||||||||||||||||||||||||
Training with learning rate = 0.001, momentum = 0.1, repetitions = 1 | |||||||||||||||||||||||||||||||
Elapsed time for training with 6000 events: 11 sec | |||||||||||||||||||||||||||||||
DNN |
| ||||||||||||||||||||||||||||||
Elapsed time for evaluation of 6000 events: 0.199 sec | |||||||||||||||||||||||||||||||
Creating xml weight file: tmva_class_example/weights/TMVAClassification_DNN.weights.xml | |||||||||||||||||||||||||||||||
Creating standalone class: tmva_class_example/weights/TMVAClassification_DNN.class.C | |||||||||||||||||||||||||||||||
TFHandler_MLP |
| ||||||||||||||||||||||||||||||
Training Network | |||||||||||||||||||||||||||||||
Elapsed time for training with 6000 events: 5.91 sec | |||||||||||||||||||||||||||||||
MLP |
| ||||||||||||||||||||||||||||||
Elapsed time for evaluation of 6000 events: 0.0109 sec | |||||||||||||||||||||||||||||||
Creating xml weight file: tmva_class_example/weights/TMVAClassification_MLP.weights.xml | |||||||||||||||||||||||||||||||
Creating standalone class: tmva_class_example/weights/TMVAClassification_MLP.class.C | |||||||||||||||||||||||||||||||
BDT | #events: (reweighted) sig: 3000 bkg: 3000 | ||||||||||||||||||||||||||||||
#events: (unweighted) sig: 3000 bkg: 3000 | |||||||||||||||||||||||||||||||
Training 850 Decision Trees ... patience please | |||||||||||||||||||||||||||||||
Elapsed time for training with 6000 events: 2.31 sec | |||||||||||||||||||||||||||||||
BDT |
| ||||||||||||||||||||||||||||||
Elapsed time for evaluation of 6000 events: 0.764 sec | |||||||||||||||||||||||||||||||
Creating xml weight file: tmva_class_example/weights/TMVAClassification_BDT.weights.xml | |||||||||||||||||||||||||||||||
Creating standalone class: tmva_class_example/weights/TMVAClassification_BDT.class.C |
factory.DrawNeuralNetwork(dataset, "MLP")
factory.DrawNeuralNetwork(dataset, "DNN")
factory.DrawDecisionTree(dataset, "BDT") #11