Belle II Software light-2406-ragdoll
RegressionExpert< BaseClassifierExpert, RegressionClassifierOptions > Class Template Reference

Generic expert for the regression applications. More...

#include <Regression.h>

Inheritance diagram for RegressionExpert< BaseClassifierExpert, RegressionClassifierOptions >:
Collaboration diagram for RegressionExpert< BaseClassifierExpert, RegressionClassifierOptions >:

Public Member Functions

void load (Weightfile &weightfile) override
 Load the expert from the weightfile by loading each stored single classifier one ofter the other.
 
std::vector< float > apply (Dataset &test_data) const override
 Apply the loaded experts by averaging over the single expert decisions.
 
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

std::vector< BaseClassifierExpert > m_baseClassifierExperts
 The list of single experts.
 

Detailed Description

template<class BaseClassifierExpert, class RegressionClassifierOptions>
class Belle2::MVA::RegressionExpert< BaseClassifierExpert, RegressionClassifierOptions >

Generic expert for the regression applications.

For each trained base classifier (for each bin, see the teacher for how this is done), one weight file is written as part into the full weight file. This expert reads all of them, instantiates a base expert for each bin and applies all of them to the dataset.

The result of the calculation is given by

 probability = sum(expert probability for each expert) / # of experts
Template Parameters
BaseClassifierExpertAnother expert that is related to the teacher you used for training
RegressionClassifierOptionsThe options of the classifier (probably inheriting from RegressionOptions)

Definition at line 179 of file Regression.h.

Member Function Documentation

◆ apply()

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

Apply the loaded experts by averaging over the single expert decisions.

Implements Expert.

Definition at line 290 of file Regression.h.

292{
293 std::vector<float> sum;
294 for (const auto& expert : m_baseClassifierExperts) {
295 if (sum.empty()) {
296 // First time we do not need to add something, but just replace
297 sum = expert.apply(test_data);
298 continue;
299 }
300
301 const auto& expertResult = expert.apply(test_data);
302 if (sum.size() != expertResult.size()) {
303 B2FATAL("There is one expert in the list that returned not the same number of results than the others!");
304 }
305
306 for (unsigned int index = 0; index < sum.size(); index++) {
307 sum[index] += expertResult[index];
308 }
309 }
310
311 for (unsigned int index = 0; index < sum.size(); index++) {
312 sum[index] /= m_baseClassifierExperts.size();
313 }
314
315 return sum;
316}
std::vector< BaseClassifierExpert > m_baseClassifierExperts
The list of single experts.
Definition: Regression.h:189

◆ 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 the weightfile by loading each stored single classifier one ofter the other.

Implements Expert.

Definition at line 274 of file Regression.h.

275{
276 RegressionClassifierOptions specific_options;
277 weightfile.getOptions(specific_options);
278
279 m_baseClassifierExperts.resize(specific_options.getMaximalBinNumber());
280 for (unsigned int binNumber = 1; binNumber < specific_options.getMaximalBinNumber(); binNumber++) {
281 std::string file = weightfile.generateFileName();
282 weightfile.getFile("BaseClassifier_WeightFile_" + std::to_string(binNumber), file);
283
284 auto specificWeightFile = Weightfile::loadFromXMLFile(file);
285 m_baseClassifierExperts[binNumber].load(specificWeightFile);
286 }
287}
static Weightfile loadFromXMLFile(const std::string &filename)
Static function which loads a Weightfile from a XML file.
Definition: Weightfile.cc:240

Member Data Documentation

◆ m_baseClassifierExperts

std::vector<BaseClassifierExpert> m_baseClassifierExperts
private

The list of single experts.

Definition at line 189 of file Regression.h.

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

General options loaded from the weightfile.

Definition at line 70 of file Expert.h.


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