11 #include <mva/methods/PDF.h>
12 #include <framework/logging/Logger.h>
23 int version = pt.get<
int>(
"PDF_version");
25 B2ERROR(
"Unkown weightfile version " << std::to_string(version));
26 throw std::runtime_error(
"Unkown weightfile version " + std::to_string(version));
28 m_binning = pt.get<std::string>(
"PDF_binning");
29 m_mode = pt.get<std::string>(
"PDF_mode");
30 m_nBins = pt.get<
unsigned int>(
"PDF_nBins");
36 pt.put(
"PDF_version", 1);
38 pt.put(
"PDF_mode",
m_mode);
44 po::options_description description(
"PDF options");
45 description.add_options()
46 (
"binning", po::value<std::string>(&
m_binning),
"Binning used to bin the data (frequency|equidistant)")
47 (
"nBins", po::value<unsigned int>(&
m_nBins),
"Number of bins used to bin the data")
48 (
"mode", po::value<std::string>(&
m_mode),
"Mode used to calculate return value of expert");
54 m_specific_options(specific_options) { }
59 unsigned int numberOfFeatures = training_data.getNumberOfFeatures();
60 if (numberOfFeatures != 1) {
61 B2ERROR(
"PDF method only supports exactly one feature!");
62 throw std::runtime_error(
"PDF method only supports exactly one feature!");
64 unsigned int numberOfEvents = training_data.getNumberOfEvents();
66 std::vector<float> data(numberOfEvents);
67 std::vector<float> weights(numberOfEvents);
68 std::vector<bool> isSignal(numberOfEvents);
69 for (
unsigned int iEvent = 0; iEvent < numberOfEvents; ++iEvent) {
70 training_data.loadEvent(iEvent);
71 data[iEvent] = training_data.m_input[0];
72 weights[iEvent] = training_data.m_weight;
73 isSignal[iEvent] = training_data.m_isSignal;
88 Weightfile weightfile;
89 std::string custom_weightfile = weightfile.generateFileName();
90 std::fstream file(custom_weightfile, std::ios_base::out | std::ios_base::trunc);
92 std::vector<double> value(nBins, 0);
94 for (
unsigned int iBin = 0; iBin < nBins; ++iBin) {
103 file << nBins << std::endl;
104 for (
unsigned int iBin = 0; iBin < nBins; ++iBin) {
105 file << value[iBin] <<
" " << binning.
m_boundaries[iBin] << std::endl;
113 weightfile.addFile(
"PDF_Weightfile", custom_weightfile);
114 weightfile.addSignalFraction(training_data.getSignalFraction());
123 std::string custom_weightfile = weightfile.generateFileName();
124 weightfile.getFile(
"PDF_Weightfile", custom_weightfile);
125 std::fstream file(custom_weightfile, std::ios_base::in);
127 unsigned int nBins = 0;
131 std::vector<float> boundaries(nBins + 1, 0);
133 for (
unsigned int iBin = 0; iBin < nBins; ++iBin) {
134 file >>
m_value[iBin] >> boundaries[iBin];
136 file >> boundaries[nBins];
147 std::vector<float> probabilities(test_data.getNumberOfEvents(), 0);
148 for (
unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
149 test_data.loadEvent(iEvent);
151 probabilities[iEvent] =
m_value[bin];
153 return probabilities;