42useLikelihoodKDE =
False
49if ROOT.gSystem.GetFromPipe(
"root-config --has-tmva-pymva") ==
"yes":
58 ROOT.Warning(
"TMVA_Higgs_Classification",
"Skip using Keras since tensorflow is not available")
61outputFile =
TFile.Open(
"Higgs_ClassificationOutput.root",
"RECREATE")
63 "TMVA_Higgs_Classification", outputFile, V=
False, ROC=
True, Silent=
False, Color=
True, AnalysisType=
"Classification"
71inputFileName =
"Higgs_data.root"
72inputFileLink =
"http://root.cern.ch/files/" + inputFileName
75if ROOT.gSystem.AccessPathName(inputFileName):
77 ROOT.Info(
"TMVA_Higgs_Classification",
"Download Higgs_data.root file")
79 inputFile =
TFile.Open(inputFileLink,
"CACHEREAD")
81 raise FileNotFoundError(
"Input file cannot be downloaded - exit")
87signalTree = inputFile.Get(
"sig_tree")
88backgroundTree = inputFile.Get(
"bkg_tree")
98loader.AddVariable(
"m_jj")
99loader.AddVariable(
"m_jjj")
100loader.AddVariable(
"m_lv")
101loader.AddVariable(
"m_jlv")
102loader.AddVariable(
"m_bb")
103loader.AddVariable(
"m_wbb")
104loader.AddVariable(
"m_wwbb")
109backgroundWeight = 1.0
111loader.AddSignalTree(signalTree, signalWeight)
112loader.AddBackgroundTree(backgroundTree, backgroundWeight)
121mycuts = ROOT.TCut(
"")
122mycutb = ROOT.TCut(
"")
131loader.PrepareTrainingAndTestTree(
132 mycuts, mycutb, nTrain_Signal=7000, nTrain_Background=7000, SplitMode=
"Random", NormMode=
"NumEvents", V=
False
143 TMVA.Types.kLikelihood,
147 TransformOutput=
True,
148 PDFInterpol=
"Spline2:NSmoothSig[0]=20:NSmoothBkg[0]=20:NSmoothBkg[1]=10",
157 TMVA.Types.kLikelihood,
161 TransformOutput=
False,
181 PDFInterpolMVAPdf=
"Spline2",
196 BoostType=
"AdaBoost",
199 BaggedSampleFraction=0.5,
200 SeparationType=
"GiniIndex",
280 useDLGPU = ROOT.gSystem.GetFromPipe(
"root-config --has-tmva-gpu") ==
"yes"
285 training1 = ROOT.TString(
286 "LearningRate=1e-3,Momentum=0.9,"
287 "ConvergenceSteps=10,BatchSize=128,TestRepetitions=1,"
288 "MaxEpochs=20,WeightDecay=1e-4,Regularization=None,"
289 "Optimizer=ADAM,ADAM_beta1=0.9,ADAM_beta2=0.999,ADAM_eps=1.E-7,"
290 "DropConfig=0.0+0.0+0.0+0."
298 dnnMethodName = ROOT.TString(
"DNN_CPU")
302 dnnMethodName =
"DNN_GPU"
312 ErrorStrategy=
"CROSSENTROPY",
314 WeightInitialization=
"XAVIER",
316 BatchLayout=
"1|128|7",
317 Layout=
"DENSE|64|TANH,DENSE|64|TANH,DENSE|64|TANH,DENSE|64|TANH,DENSE|1|LINEAR",
318 TrainingStrategy=training1,
324 ROOT.Info(
"TMVA_Higgs_Classification",
"Building Deep Learning keras model")
327 from tensorflow.keras.models
import Sequential
328 from tensorflow.keras.optimizers
import Adam
329 from tensorflow.keras.layers
import Input, Dense
332 model.add(Dense(64, activation=
'relu',input_dim=7))
333 model.add(Dense(64, activation=
'relu'))
334 model.add(Dense(64, activation=
'relu'))
335 model.add(Dense(64, activation=
'relu'))
336 model.add(Dense(2, activation=
'sigmoid'))
337 model.compile(loss =
'binary_crossentropy', optimizer = Adam(learning_rate = 0.001), weighted_metrics = [
'accuracy'])
338 model.save(
'model_higgs.h5')
341 if not os.path.exists(
"model_higgs.h5"):
342 raise FileNotFoundError(
"Error creating Keras model file - skip using Keras")
345 ROOT.Info(
"TMVA_Higgs_Classification",
"Booking Deep Learning keras model")
353 FilenameModel=
"model_higgs.h5",
354 FilenameTrainedModel=
"trained_model_higgs.h5",
365factory.TrainAllMethods()
369factory.TestAllMethods()
371factory.EvaluateAllMethods()
375c1 = factory.GetROCCurve(loader)
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.
This is the main MVA steering class.
static void PyInitialize()
Initialize Python interpreter.