Belle II Software development
CombinationExpert Class Reference

Expert for the Combination MVA method. More...

#include <Combination.h>

Inheritance diagram for CombinationExpert:
Expert

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 expert onto a dataset.
 
virtual std::vector< std::vector< float > > applyMulticlass (Dataset &test_data) const
 Apply this m_expert onto a dataset.
 

Protected Attributes

GeneralOptions m_general_options
 General options loaded from the weightfile.
 

Private Attributes

CombinationOptions m_specific_options
 Method specific options.
 
std::vector< std::unique_ptr< Expert > > m_experts
 Experts of the methods to combine.
 
std::vector< std::vector< std::string > > m_expert_variables
 Results of the experts to combine.
 

Detailed Description

Expert for the Combination MVA method.

Definition at line 83 of file Combination.h.

Member Function Documentation

◆ apply()

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

Apply this expert onto a dataset.

Parameters
test_datadataset

Implements Expert.

Definition at line 105 of file Combination.cc.

106 {
107 std::vector<float> probabilities(test_data.getNumberOfEvents(), 0);
108 std::vector<std::vector<float>> expert_probabilities;
109
110 for (unsigned int iExpert = 0; iExpert < m_experts.size(); ++iExpert) {
111 GeneralOptions sub_general_options = m_general_options;
112 sub_general_options.m_variables = m_expert_variables[iExpert];
113 SubDataset sub_dataset(sub_general_options, {}, test_data);
114 expert_probabilities.push_back(m_experts[iExpert]->apply(sub_dataset));
115 }
116
117 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
118 double a = 1.0;
119 double b = 1.0;
120 for (unsigned int iExpert = 0; iExpert < m_experts.size(); ++iExpert) {
121 a *= expert_probabilities[iExpert][iEvent];
122 b *= (1.0 - expert_probabilities[iExpert][iEvent]);
123 }
124 probabilities[iEvent] = a / (a + b);
125 }
126 return probabilities;
127 }
std::vector< std::unique_ptr< Expert > > m_experts
Experts of the methods to combine.
Definition: Combination.h:100
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this expert onto a dataset.
Definition: Combination.cc:105
std::vector< std::vector< std::string > > m_expert_variables
Results of the experts to combine.
Definition: Combination.h:101
GeneralOptions m_general_options
General options loaded from the weightfile.
Definition: Expert.h:70
std::vector< std::string > m_variables
Vector of all variables (branch names) used in the training.
Definition: Options.h:86

◆ 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.

Definition at line 77 of file Combination.cc.

78 {
79
80 weightfile.getOptions(m_specific_options);
81
82 m_experts.clear();
83 m_expert_variables.clear();
84
85 for (unsigned int i = 0; i < m_specific_options.m_weightfiles.size(); ++i) {
86 std::string sub_weightfile_name = weightfile.generateFileName(".xml");
87 weightfile.getFile("Combination_Weightfile" + std::to_string(i), sub_weightfile_name);
88 auto sub_weightfile = Weightfile::load(sub_weightfile_name);
89 GeneralOptions general_options;
90 sub_weightfile.getOptions(general_options);
91
93 auto supported_interfaces = AbstractInterface::getSupportedInterfaces();
94 if (supported_interfaces.find(general_options.m_method) == supported_interfaces.end()) {
95 B2ERROR("Couldn't find method named " + general_options.m_method);
96 throw std::runtime_error("Couldn't find method named " + general_options.m_method);
97 }
98 auto expert = supported_interfaces[general_options.m_method]->getExpert();
99 expert->load(sub_weightfile);
100 m_experts.emplace_back(std::move(expert));
101 m_expert_variables.push_back(general_options.m_variables);
102 }
103 }
static void initSupportedInterfaces()
Static function which initliazes all supported interfaces, has to be called once before getSupportedI...
Definition: Interface.cc:45
static std::map< std::string, AbstractInterface * > getSupportedInterfaces()
Returns interfaces supported by the MVA Interface.
Definition: Interface.h:53
CombinationOptions m_specific_options
Method specific options.
Definition: Combination.h:99
std::vector< std::string > m_weightfiles
Weightfiles of all methods we want to combine.
Definition: Combination.h:53
static Weightfile load(const std::string &filename, const Belle2::EventMetaData &emd=Belle2::EventMetaData(0, 0, 0))
Static function which loads a Weightfile from a file or from the database.
Definition: Weightfile.cc:195

Member Data Documentation

◆ m_expert_variables

std::vector<std::vector<std::string> > m_expert_variables
private

Results of the experts to combine.

Definition at line 101 of file Combination.h.

◆ m_experts

std::vector<std::unique_ptr<Expert> > m_experts
private

Experts of the methods to combine.

Definition at line 100 of file Combination.h.

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

General options loaded from the weightfile.

Definition at line 70 of file Expert.h.

◆ m_specific_options

CombinationOptions m_specific_options
private

Method specific options.

Definition at line 99 of file Combination.h.


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