Belle II Software  release-06-00-14
Trivial.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <mva/methods/Trivial.h>
10 
11 #include <framework/logging/Logger.h>
12 
13 namespace Belle2 {
18  namespace MVA {
19 
20  void TrivialOptions::load(const boost::property_tree::ptree& pt)
21  {
22  int version = pt.get<int>("Trivial_version");
23  if (version != 1) {
24  B2ERROR("Unknown weightfile version " << std::to_string(version));
25  throw std::runtime_error("Unknown weightfile version " + std::to_string(version));
26  }
27  m_output = pt.get<double>("Trivial_output");
28  }
29 
30  void TrivialOptions::save(boost::property_tree::ptree& pt) const
31  {
32  pt.put("Trivial_version", 1);
33  pt.put("Trivial_output", m_output);
34  }
35 
36  po::options_description TrivialOptions::getDescription()
37  {
38  po::options_description description("Trivial options");
39  description.add_options()
40  ("output", po::value<double>(&m_output), "Outputs allows this given floating point number");
41  return description;
42  }
43 
44 
46  const TrivialOptions& specific_options) : Teacher(general_options),
47  m_specific_options(specific_options) { }
48 
50  {
51  Weightfile weightfile;
52  weightfile.addOptions(m_general_options);
53  weightfile.addOptions(m_specific_options);
54  weightfile.addSignalFraction(training_data.getSignalFraction());
55  return weightfile;
56  }
57 
58  void TrivialExpert::load(Weightfile& weightfile)
59  {
60  weightfile.getOptions(m_specific_options);
61  }
62 
63  std::vector<float> TrivialExpert::apply(Dataset& test_data) const
64  {
65 
66  std::vector<float> probabilities(test_data.getNumberOfEvents());
67  for (unsigned int iEvent = 0; iEvent < test_data.getNumberOfEvents(); ++iEvent) {
68  test_data.loadEvent(iEvent);
69  probabilities[iEvent] = m_specific_options.m_output;
70  }
71 
72  return probabilities;
73 
74  }
75 
76  }
78 }
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
Definition: Dataset.h:31
General options which are shared by all MVA trainings.
Definition: Options.h:62
Abstract base class of all Teachers Each MVA library has its own implementation of this class,...
Definition: Teacher.h:29
GeneralOptions m_general_options
GeneralOptions containing all shared options.
Definition: Teacher.h:49
TrivialOptions m_specific_options
Method specific options.
Definition: Trivial.h:100
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this expert onto a dataset.
Definition: Trivial.cc:63
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition: Trivial.cc:58
Options for the Trivial MVA method.
Definition: Trivial.h:28
double m_output
Output of the trivial method.
Definition: Trivial.h:53
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: Trivial.cc:36
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition: Trivial.cc:20
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition: Trivial.cc:30
TrivialTeacher(const GeneralOptions &general_options, const TrivialOptions &specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition: Trivial.cc:45
TrivialOptions m_specific_options
Method specific options.
Definition: Trivial.h:77
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition: Trivial.cc:49
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:38
void addOptions(const Options &options)
Add an Option object to the xml tree.
Definition: Weightfile.cc:61
void getOptions(Options &options) const
Fills an Option object from the xml tree.
Definition: Weightfile.cc:66
void addSignalFraction(float signal_fraction)
Saves the signal fraction in the xml tree.
Definition: Weightfile.cc:94
Abstract base class for different kinds of events.