Belle II Software  release-05-01-25
FastBDT.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Keck *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #ifndef INCLUDE_GUARD_BELLE2_MVA_FASTBDT_HEADER
13 #define INCLUDE_GUARD_BELLE2_MVA_FASTBDT_HEADER
14 
15 #include <mva/interface/Options.h>
16 #include <mva/interface/Teacher.h>
17 #include <mva/interface/Expert.h>
18 
19 #include <FastBDT.h>
20 
21 #if FastBDT_VERSION_MAJOR >= 3
22 #include <FastBDT_IO.h>
23 #else
24 #include <IO.h>
25 #endif
26 
27 #if FastBDT_VERSION_MAJOR >= 5
28 #include <Classifier.h>
29 #endif
30 
31 // Template specialization to fix NAN sort bug of FastBDT in upto Version 3.2
32 #if FastBDT_VERSION_MAJOR <= 3 && FastBDT_VERSION_MINOR <= 2
33 namespace FastBDT {
34  template<>
35  bool compareIncludingNaN(float i, float j);
36 }
37 #endif
38 
39 namespace Belle2 {
44  namespace MVA {
45 
46 
50  bool isValidSignal(const std::vector<bool>& Signals);
51 
56 
57  public:
62  virtual void load(const boost::property_tree::ptree& pt) override;
63 
68  virtual void save(boost::property_tree::ptree& pt) const override;
69 
73  virtual po::options_description getDescription() override;
74 
78  virtual std::string getMethod() const override { return "FastBDT"; }
79 
80  unsigned int m_nTrees = 200;
81  unsigned int m_nCuts = 8;
82  unsigned int m_nLevels = 3;
83  double m_shrinkage = 0.1;
84  double m_randRatio = 0.5;
85 #if FastBDT_VERSION_MAJOR >= 5
86  std::vector<unsigned int>
87  m_individual_nCuts;
88  double m_flatnessLoss = -1.0;
89  bool m_sPlot = false;
90  bool m_purityTransformation = false;
91  std::vector<bool>
92  m_individualPurityTransformation;
93 #endif
94  };
95 
96 
100  class FastBDTTeacher : public Teacher {
101 
102  public:
108  FastBDTTeacher(const GeneralOptions& general_options, const FastBDTOptions& specific_options);
109 
114  virtual Weightfile train(Dataset& training_data) const override;
115 
116  private:
118  };
119 
120 
124  class FastBDTExpert : public MVA::Expert {
125 
126  public:
131  virtual void load(Weightfile& weightfile) override;
132 
137  virtual std::vector<float> apply(Dataset& test_data) const override;
138 
139  private:
141 #if FastBDT_VERSION_MAJOR >= 3
142 #if FastBDT_VERSION_MAJOR >= 5
143  bool m_use_simplified_interface = false;
144  FastBDT::Classifier m_classifier;
145 #endif
146  FastBDT::Forest<float> m_expert_forest;
147 #else
148  FastBDT::Forest m_expert_forest;
149  std::vector<FastBDT::FeatureBinning<float>> m_expert_feature_binning;
150 #endif
151  };
152 
153  }
155 }
156 #endif
Belle2::MVA::FastBDTOptions
Options for the FANN MVA method.
Definition: FastBDT.h:55
Belle2::MVA::FastBDTTeacher::train
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition: FastBDT.cc:162
Belle2::MVA::FastBDTOptions::load
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition: FastBDT.cc:55
Belle2::MVA::FastBDTTeacher
Teacher for the FastBDT MVA method.
Definition: FastBDT.h:100
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::FastBDTExpert::m_expert_forest
FastBDT::Forest m_expert_forest
Forest Expert.
Definition: FastBDT.h:148
Belle2::MVA::FastBDTOptions::save
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition: FastBDT.cc:101
Belle2::MVA::FastBDTExpert
Expert for the FastBDT MVA method.
Definition: FastBDT.h:124
Belle2::MVA::Weightfile
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:40
Belle2::MVA::FastBDTOptions::getDescription
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: FastBDT.cc:128
Belle2::MVA::FastBDTExpert::apply
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this expert onto a dataset.
Definition: FastBDT.cc:414
Belle2::MVA::FastBDTExpert::load
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition: FastBDT.cc:321
Belle2::MVA::FastBDTOptions::m_randRatio
double m_randRatio
Fraction of data to use in the stochastic training.
Definition: FastBDT.h:84
Belle2::MVA::SpecificOptions
Specific Options, all mehtod Options have to inherit from this class.
Definition: Options.h:99
Belle2::MVA::FastBDTExpert::m_specific_options
FastBDTOptions m_specific_options
Method specific options.
Definition: FastBDT.h:140
Belle2::MVA::FastBDTExpert::m_expert_feature_binning
std::vector< FastBDT::FeatureBinning< float > > m_expert_feature_binning
Forest feature binning.
Definition: FastBDT.h:149
Belle2::MVA::FastBDTOptions::m_nCuts
unsigned int m_nCuts
Number of cut Levels = log_2(Number of Cuts)
Definition: FastBDT.h:81
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::FastBDTTeacher::m_specific_options
FastBDTOptions m_specific_options
Method specific options.
Definition: FastBDT.h:117
Belle2::MVA::FastBDTOptions::m_nTrees
unsigned int m_nTrees
Number of trees.
Definition: FastBDT.h:80
Belle2::MVA::FastBDTOptions::getMethod
virtual std::string getMethod() const override
Return method name.
Definition: FastBDT.h:78
Belle2::MVA::Expert
Abstract base class of all Expert Each MVA library has its own implementation of this class,...
Definition: Expert.h:33
Belle2::MVA::GeneralOptions
General options which are shared by all MVA trainings.
Definition: Options.h:64
Belle2::MVA::FastBDTTeacher::FastBDTTeacher
FastBDTTeacher(const GeneralOptions &general_options, const FastBDTOptions &specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition: FastBDT.cc:158
Belle2::MVA::FastBDTOptions::m_nLevels
unsigned int m_nLevels
Depth of tree.
Definition: FastBDT.h:82
Belle2::MVA::FastBDTOptions::m_shrinkage
double m_shrinkage
Shrinkage during the boosting step.
Definition: FastBDT.h:83