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