Belle II Software light-2406-ragdoll
TMVAExpertMulticlass Class Reference

Expert for the TMVA Multiclass MVA method. More...

#include <TMVA.h>

Inheritance diagram for TMVAExpertMulticlass:
Collaboration diagram for TMVAExpertMulticlass:

Public Member Functions

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

Protected Attributes

TMVAOptionsMulticlass specific_options
 Method specific options.
 
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 Multiclass MVA method.

Definition at line 328 of file TMVA.h.

Member Function Documentation

◆ apply()

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

Apply this m_expert onto a dataset.

Parameters
test_datadataset

Implements Expert.

Definition at line 341 of file TMVA.h.

342 {
343 (void) test_data;
344 return std::vector<float>();
345 };

◆ applyMulticlass()

std::vector< std::vector< float > > applyMulticlass ( Dataset test_data) const
overridevirtual

Apply this m_expert onto a dataset.

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

Reimplemented from Expert.

Definition at line 526 of file TMVA.cc.

527 {
528
529 std::vector<std::vector<float>> probabilities(test_data.getNumberOfEvents());
530
531 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
532 test_data.loadEvent(iEvent);
533 for (unsigned int i = 0; i < m_input_cache.size(); ++i)
534 m_input_cache[i] = test_data.m_input[i];
535 for (unsigned int i = 0; i < m_spectators_cache.size(); ++i)
536 m_spectators_cache[i] = test_data.m_spectators[i];
537 probabilities[iEvent] = m_expert->EvaluateMulticlass(specific_options.m_method);
538 }
539 return probabilities;
540 }
TMVAOptionsMulticlass specific_options
Method specific options.
Definition: TMVA.h:355
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
std::string m_method
tmva method name
Definition: TMVA.h:60

◆ load()

void load ( Weightfile weightfile)
overridevirtual

Load the expert from a Weightfile.

Parameters
weightfilecontaining all information necessary to build the m_expert

Reimplemented from TMVAExpert.

Definition at line 445 of file TMVA.cc.

446 {
447
448 weightfile.getOptions(specific_options);
449
450 // TMVA parses the method type for plugins out of the weightfile name, so we must ensure that it has the expected format
451 std::string custom_weightfile = weightfile.generateFileName(std::string("_") + specific_options.m_method + ".weights.xml");
452 weightfile.getFile("TMVA_Weightfile", custom_weightfile);
453
454 TMVAExpert::load(weightfile);
455
456 if (specific_options.m_type == "Plugins") {
457 auto base = std::string("TMVA@@MethodBase");
458 auto regexp1 = std::string(".*_") + specific_options.m_method + std::string(".*");
459 auto regexp2 = std::string(".*") + specific_options.m_method + std::string(".*");
460 auto className = std::string("TMVA::Method") + specific_options.m_method;
461 auto ctor1 = std::string("Method") + specific_options.m_method + std::string("(TMVA::DataSetInfo&,TString)");
462 auto ctor2 = std::string("Method") + specific_options.m_method + std::string("(TString&,TString&,TMVA::DataSetInfo&,TString&)");
463 auto pluginName = std::string("TMVA") + specific_options.m_method;
464
465 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp1.c_str(), className.c_str(), pluginName.c_str(), ctor1.c_str());
466 gROOT->GetPluginManager()->AddHandler(base.c_str(), regexp2.c_str(), className.c_str(), pluginName.c_str(), ctor2.c_str());
467 B2INFO("Registered new TMVA Plugin named " << pluginName);
468 }
469
470 if (!m_expert->BookMVA(specific_options.m_method, custom_weightfile)) {
471 B2FATAL("Could not set up expert! Please see preceding error message from TMVA!");
472 }
473
474 }
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition: TMVA.cc:385
std::string m_type
tmva method type
Definition: TMVA.h:61

Member Data Documentation

◆ m_expert

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

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
mutableprotectedinherited

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
mutableprotectedinherited

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.

◆ specific_options

TMVAOptionsMulticlass specific_options
protected

Method specific options.

Definition at line 355 of file TMVA.h.


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