Belle II Software light-2406-ragdoll
TMVAExpert Class Referenceabstract

Expert for the TMVA MVA method. More...

#include <TMVA.h>

Inheritance diagram for TMVAExpert:
Collaboration diagram for TMVAExpert:

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()

virtual std::vector< float > apply ( Dataset test_data) const
pure virtualinherited

◆ 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 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 385 of file TMVA.cc.

386 {
387
388 // Initialize TMVA and ROOT stuff
389 TMVA::Tools::Instance();
390
391 m_expert = std::make_unique<TMVA::Reader>("!Color:Silent");
392
393 GeneralOptions general_options;
394 weightfile.getOptions(general_options);
395 m_input_cache.resize(general_options.m_variables.size(), 0);
396 for (unsigned int i = 0; i < general_options.m_variables.size(); ++i) {
397 m_expert->AddVariable(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_variables[i]), &m_input_cache[i]);
398 }
399 m_spectators_cache.resize(general_options.m_spectators.size(), 0);
400 for (unsigned int i = 0; i < general_options.m_spectators.size(); ++i) {
401 m_expert->AddSpectator(Belle2::MakeROOTCompatible::makeROOTCompatible(general_options.m_spectators[i]), &m_spectators_cache[i]);
402 }
403
404 if (weightfile.containsElement("TMVA_Logfile")) {
405 std::string custom_weightfile = weightfile.generateFileName("logfile");
406 weightfile.getFile("TMVA_Logfile", custom_weightfile);
407 }
408
409 }
std::vector< float > m_input_cache
Input Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply call.
Definition: TMVA.h:296
std::unique_ptr< TMVA::Reader > m_expert
TMVA::Reader pointer.
Definition: TMVA.h:294
std::vector< float > m_spectators_cache
Spectators Cache for TMVA::Reader: Otherwise we would have to set the branch addresses in each apply ...
Definition: TMVA.h:298
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: