Belle II Software development
PDFTeacher Class Reference

Teacher for the PDF MVA method. More...

#include <PDF.h>

Inheritance diagram for PDFTeacher:
Teacher

Public Member Functions

 PDFTeacher (const GeneralOptions &general_options, const PDFOptions &specific_options)
 Constructs a new teacher using the GeneralOptions and PDFoptions for this training.
 
virtual Weightfile train (Dataset &training_data) const override
 Train PDF method using the given dataset returning a Weightfile.
 

Protected Attributes

GeneralOptions m_general_options
 GeneralOptions containing all shared options.
 

Private Attributes

PDFOptions m_specific_options
 Specific options of the PDF method.
 

Detailed Description

Teacher for the PDF MVA method.

Definition at line 63 of file PDF.h.

Constructor & Destructor Documentation

◆ PDFTeacher()

PDFTeacher ( const GeneralOptions general_options,
const PDFOptions specific_options 
)

Constructs a new teacher using the GeneralOptions and PDFoptions for this training.

Parameters
general_optionsdefining all shared options
specific_optionsdefining all options unique to the PDFTeacher

Definition at line 51 of file PDF.cc.

51 : Teacher(general_options),
52 m_specific_options(specific_options) { }
PDFOptions m_specific_options
Specific options of the PDF method.
Definition: PDF.h:80
Teacher(const GeneralOptions &general_options)
Constructs a new teacher using the GeneralOptions for this training.
Definition: Teacher.cc:18

Member Function Documentation

◆ train()

Weightfile train ( Dataset training_data) const
overridevirtual

Train PDF method using the given dataset returning a Weightfile.

Parameters
training_dataused to train the method

Implements Teacher.

Definition at line 54 of file PDF.cc.

55 {
56
57 unsigned int numberOfFeatures = training_data.getNumberOfFeatures();
58 if (numberOfFeatures != 1) {
59 B2ERROR("PDF method only supports exactly one feature!");
60 throw std::runtime_error("PDF method only supports exactly one feature!");
61 }
62 unsigned int numberOfEvents = training_data.getNumberOfEvents();
63
64 std::vector<float> data(numberOfEvents);
65 std::vector<float> weights(numberOfEvents);
66 std::vector<bool> isSignal(numberOfEvents);
67 for (unsigned int iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
68 training_data.loadEvent(iEvent);
69 data[iEvent] = training_data.m_input[0];
70 weights[iEvent] = training_data.m_weight;
71 isSignal[iEvent] = training_data.m_isSignal;
72 }
73
74 unsigned int nBins = m_specific_options.m_nBins;
75
76 Binning binning;
77 if (m_specific_options.m_binning == "frequency")
78 binning = Binning::CreateEqualFrequency(data, weights, isSignal, nBins);
79 else if (m_specific_options.m_binning == "equidistant")
80 binning = Binning::CreateEquidistant(data, weights, isSignal, nBins);
81 else {
82 B2ERROR("Unknown binning in PDF Teacher named " << m_specific_options.m_binning);
83 throw std::runtime_error("Unknown binning in PDF Teacher named " + m_specific_options.m_binning);
84 }
85
86 Weightfile weightfile;
87 std::string custom_weightfile = weightfile.generateFileName();
88 std::fstream file(custom_weightfile, std::ios_base::out | std::ios_base::trunc);
89
90 std::vector<double> value(nBins, 0);
91 if (m_specific_options.m_mode == "probability") {
92 for (unsigned int iBin = 0; iBin < nBins; ++iBin) {
93 if (binning.m_signal_pdf[iBin] > 0)
94 value[iBin] = binning.m_signal_pdf[iBin] / (binning.m_signal_pdf[iBin] + binning.m_bckgrd_pdf[iBin]);
95 }
96 } else {
97 B2ERROR("Unknown mode in PDF Teacher named " << m_specific_options.m_mode);
98 throw std::runtime_error("Unknown mode in PDF Teacher named " + m_specific_options.m_mode);
99 }
100
101 file << nBins << std::endl;
102 for (unsigned int iBin = 0; iBin < nBins; ++iBin) {
103 file << value[iBin] << " " << binning.m_boundaries[iBin] << std::endl;
104 }
105 file << binning.m_boundaries[nBins];
106
107 file.close();
108
109 weightfile.addOptions(m_general_options);
110 weightfile.addOptions(m_specific_options);
111 weightfile.addFile("PDF_Weightfile", custom_weightfile);
112 weightfile.addSignalFraction(training_data.getSignalFraction());
113
114 return weightfile;
115
116 }
unsigned int m_nBins
number of bins used to bin the data
Definition: PDF.h:56
std::string m_binning
which type of binning is performed e.g.
Definition: PDF.h:54
std::string m_mode
mode which defines the final output e.g.
Definition: PDF.h:55
GeneralOptions m_general_options
GeneralOptions containing all shared options.
Definition: Teacher.h:49
std::vector< std::pair< double, double > > Binning
Bin holder as vector for bin limit pairs: [energy limits, theta limits, phi limits].

Member Data Documentation

◆ m_general_options

GeneralOptions m_general_options
protectedinherited

GeneralOptions containing all shared options.

Definition at line 49 of file Teacher.h.

◆ m_specific_options

PDFOptions m_specific_options
private

Specific options of the PDF method.

Definition at line 80 of file PDF.h.


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