Belle II Software development
TMVAExpert Class Referenceabstract

Expert for the TMVA MVA method. More...

#include <TMVA.h>

Inheritance diagram for TMVAExpert:
Expert TMVAExpertClassification TMVAExpertMulticlass TMVAExpertRegression

Public Member Functions

virtual void load (Weightfile &weightfile) override
 Load the expert from a Weightfile.
 
virtual std::vector< float > apply (Dataset &test_data) const =0
 Apply this expert onto a dataset.
 
virtual std::vector< std::vector< float > > applyMulticlass (Dataset &test_data) const
 Apply this m_expert onto a dataset.
 

Protected Attributes

std::unique_ptr< TMVA::Reader > m_expert
 TMVA::Reader pointer.
 
std::vector< float > m_input_cache
 Input Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.
 
std::vector< float > m_spectators_cache
 Spectators Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.
 
GeneralOptions m_general_options
 General options loaded from the weightfile.
 

Detailed Description

Expert for the TMVA MVA method.

Definition at line 284 of file TMVA.h.

Member Function Documentation

◆ apply()

◆ applyMulticlass()

virtual std::vector< std::vector< float > > applyMulticlass ( Dataset & test_data) const
inlinevirtualinherited

Apply this m_expert onto a dataset.

Multiclass mode. Not pure virtual, since not all derived classes to re-implement this.

Parameters
test_datadataset.
Returns
vector of size N=test_data.getNumberOfEvents() with N=m_classes.size() scores for each event in the dataset.

Reimplemented in ONNXExpert, PythonExpert, TMVAExpertMulticlass, and TrivialExpert.

Definition at line 56 of file Expert.h.

57 {
58
59 B2ERROR("Attempted to call applyMulticlass() of the abstract base class MVA::Expert. All methods that support multiclass classification should override this definition.");
60 (void) test_data;
61
62 return std::vector<std::vector<float>>();
63 };

◆ load()

void load ( Weightfile & weightfile)
overridevirtual

Load the expert from a Weightfile.

Parameters
weightfilecontaining all information necessary to build the expert

Implements Expert.

Reimplemented in TMVAExpertClassification, TMVAExpertMulticlass, and TMVAExpertRegression.

Definition at line 383 of file TMVA.cc.

384 {
385
386 // Initialize TMVA and ROOT stuff
387 TMVA::Tools::Instance();
388
389 m_expert = std::make_unique<TMVA::Reader>("!Color:Silent");
390
391 GeneralOptions general_options;
392 weightfile.getOptions(general_options);
393 m_input_cache.resize(general_options.m_variables.size(), 0);
394 for (unsigned int i = 0; i < general_options.m_variables.size(); ++i) {
395 m_expert->AddVariable(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_variables[i]), &m_input_cache[i]);
396 }
397 m_spectators_cache.resize(general_options.m_spectators.size(), 0);
398 for (unsigned int i = 0; i < general_options.m_spectators.size(); ++i) {
399 m_expert->AddSpectator(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_spectators[i]), &m_spectators_cache[i]);
400 }
401
402 if (weightfile.containsElement("TMVA_Logfile")) {
403 std::string custom_weightfile = weightfile.generateFileName("logfile");
404 weightfile.getFile("TMVA_Logfile", custom_weightfile);
405 }
406
407 }
static std::string makeROOTCompatible(std::string str)
Remove special characters that ROOT dislikes in branch names, e.g.

Member Data Documentation

◆ m_expert

std::unique_ptr<TMVA::Reader> m_expert
protected

TMVA::Reader pointer.

Definition at line 294 of file TMVA.h.

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

General options loaded from the weightfile.

Definition at line 70 of file Expert.h.

◆ m_input_cache

std::vector<float> m_input_cache
mutableprotected

Input Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.

Definition at line 296 of file TMVA.h.

◆ m_spectators_cache

std::vector<float> m_spectators_cache
mutableprotected

Spectators Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.

Definition at line 298 of file TMVA.h.


The documentation for this class was generated from the following files: