Belle II Software development
ReweighterExpert Class Reference

Expert for the Reweighter MVA method. More...

#include <Reweighter.h>

Inheritance diagram for ReweighterExpert:
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

ReweighterOptions m_specific_options
 Method specific options.
 
GeneralOptions m_expert_options
 Method general options of the expert.
 
std::unique_ptr< Expertm_expert
 Experts used to reweight.
 
double m_norm = 0.0
 Norm for the weights.
 

Detailed Description

Expert for the Reweighter MVA method.

Definition at line 84 of file Reweighter.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 176 of file Reweighter.cc.

177 {
178 auto prediction = m_expert->apply(test_data);
179
180 if (m_specific_options.m_variable != "") {
181 auto variable = test_data.getSpectator(test_data.getSpectatorIndex(m_specific_options.m_variable));
182
183 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
184 if (variable[iEvent] != 1.0) {
185 prediction[iEvent] = 1.0;
186 } else {
187 if (prediction[iEvent] > 0.995)
188 prediction[iEvent] = 0.995;
189 if (prediction[iEvent] < 0.005)
190 prediction[iEvent] = 0.005;
191
192 prediction[iEvent] = (prediction[iEvent]) / (1 - prediction[iEvent]);
193 prediction[iEvent] /= m_norm;
194 }
195 }
196 } else {
197 for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
198 if (prediction[iEvent] > 0.995)
199 prediction[iEvent] = 0.995;
200 if (prediction[iEvent] < 0.005)
201 prediction[iEvent] = 0.005;
202
203 prediction[iEvent] = (prediction[iEvent]) / (1 - prediction[iEvent]);
204 prediction[iEvent] /= m_norm;
205 }
206 }
207
208 return prediction;
209
210 }
std::unique_ptr< Expert > m_expert
Experts used to reweight.
Definition: Reweighter.h:102
ReweighterOptions m_specific_options
Method specific options.
Definition: Reweighter.h:100
double m_norm
Norm for the weights.
Definition: Reweighter.h:103
std::string m_variable
Variable which decides if the reweighter is applied or not.
Definition: Reweighter.h:54

◆ 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 154 of file Reweighter.cc.

155 {
156
157 weightfile.getOptions(m_specific_options);
158
159 std::string sub_weightfile_name = weightfile.generateFileName(".xml");
160 weightfile.getFile("Reweighter_Weightfile", sub_weightfile_name);
161 auto sub_weightfile = Weightfile::load(sub_weightfile_name);
162 sub_weightfile.getOptions(m_expert_options);
163
165 auto supported_interfaces = AbstractInterface::getSupportedInterfaces();
166 if (supported_interfaces.find(m_expert_options.m_method) == supported_interfaces.end()) {
167 B2ERROR("Couldn't find method named " + m_expert_options.m_method);
168 throw std::runtime_error("Couldn't find method named " + m_expert_options.m_method);
169 }
170 m_expert = supported_interfaces[m_expert_options.m_method]->getExpert();
171 m_expert->load(sub_weightfile);
172
173 m_norm = weightfile.getElement<float>("Reweighter_norm");
174 }
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
std::string m_method
Name of the MVA method to use.
Definition: Options.h:82
GeneralOptions m_expert_options
Method general options of the expert.
Definition: Reweighter.h:101
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

std::unique_ptr<Expert> m_expert
private

Experts used to reweight.

Definition at line 102 of file Reweighter.h.

◆ m_expert_options

GeneralOptions m_expert_options
private

Method general options of the expert.

Definition at line 101 of file Reweighter.h.

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

General options loaded from the weightfile.

Definition at line 70 of file Expert.h.

◆ m_norm

double m_norm = 0.0
private

Norm for the weights.

Definition at line 103 of file Reweighter.h.

◆ m_specific_options

ReweighterOptions m_specific_options
private

Method specific options.

Definition at line 100 of file Reweighter.h.


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