Belle II Software  release-05-01-25
FANN.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 and Fernando Abudinen *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #ifndef INCLUDE_GUARD_BELLE2_MVA_FANN_HEADER
13 #define INCLUDE_GUARD_BELLE2_MVA_FANN_HEADER
14 
15 #include <mva/interface/Options.h>
16 #include <mva/interface/Teacher.h>
17 #include <mva/interface/Expert.h>
18 
19 #include <fann.h>
20 
21 namespace Belle2 {
26  namespace MVA {
27 
31  class FANNOptions : public SpecificOptions {
32 
33  public:
38  virtual void load(const boost::property_tree::ptree& pt) override;
39 
44  virtual void save(boost::property_tree::ptree& pt) const override;
45 
49  virtual po::options_description getDescription() override;
50 
54  virtual std::string getMethod() const override { return "FANN"; }
55 
60  std::vector<unsigned int> getHiddenLayerNeurons(unsigned int nf) const;
61 
62  unsigned int m_max_epochs = 10000;
63  bool m_verbose_mode = true;
64  std::string m_hidden_layers_architecture = "3*N";
66  std::string m_hidden_activiation_function = "FANN_SIGMOID_SYMMETRIC";
67  std::string m_output_activiation_function = "FANN_SIGMOID_SYMMETRIC";
68  std::string m_error_function = "FANN_ERRORFUNC_LINEAR";
69  std::string m_training_method = "FANN_TRAIN_RPROP";
71  double m_validation_fraction = 0.5;
72  unsigned int m_random_seeds =
73  3;
74  unsigned int m_test_rate =
75  500;
76  unsigned int m_number_of_threads = 8;
79  bool m_scale_features = true;
80  bool m_scale_target = true;
82  };
83 
87  class FANNTeacher : public Teacher {
88 
89  public:
95  FANNTeacher(const GeneralOptions& general_options, const FANNOptions& specific_options);
96 
101  virtual Weightfile train(Dataset& training_data) const override;
102 
103  private:
105  };
106 
107 
111  class FANNExpert : public MVA::Expert {
112 
113  public:
114 
118  virtual ~FANNExpert();
119 
124  virtual void load(Weightfile& weightfile) override;
125 
130  virtual std::vector<float> apply(Dataset& test_data) const override;
131 
132  private:
134  struct fann* m_ann = nullptr;
135  };
136 
137  }
139 }
140 #endif
Belle2::MVA::FANNOptions::m_random_seeds
unsigned int m_random_seeds
Number of times the training is repeated with a new weight random seed.
Definition: FANN.h:72
Belle2::MVA::FANNTeacher::FANNTeacher
FANNTeacher(const GeneralOptions &general_options, const FANNOptions &specific_options)
Constructs a new teacher using the GeneralOptions and specific options of this training.
Definition: FANN.cc:36
Belle2::MVA::FANNOptions
Options for the FANN MVA method.
Definition: FANN.h:31
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::FANNExpert::~FANNExpert
virtual ~FANNExpert()
Destructor of FANN Expert.
Definition: FANN.cc:322
Belle2::MVA::Weightfile
The Weightfile class serializes all information about a training into an xml tree.
Definition: Weightfile.h:40
Belle2::MVA::FANNOptions::m_training_method
std::string m_training_method
Training method for back propagation.
Definition: FANN.h:69
Belle2::MVA::FANNExpert::load
virtual void load(Weightfile &weightfile) override
Load the expert from a Weightfile.
Definition: FANN.cc:329
Belle2::MVA::FANNOptions::save
virtual void save(boost::property_tree::ptree &pt) const override
Save mechanism to store Options in a xml tree.
Definition: FANNOptions.cc:58
Belle2::MVA::FANNOptions::m_hidden_activiation_function
std::string m_hidden_activiation_function
Activation function in hidden layer.
Definition: FANN.h:66
Belle2::MVA::FANNOptions::getMethod
virtual std::string getMethod() const override
Return method name.
Definition: FANN.h:54
Belle2::MVA::FANNOptions::m_validation_fraction
double m_validation_fraction
Fraction of training sample used for validation in order to avoid overtraining.
Definition: FANN.h:71
Belle2::MVA::SpecificOptions
Specific Options, all mehtod Options have to inherit from this class.
Definition: Options.h:99
Belle2::MVA::FANNOptions::load
virtual void load(const boost::property_tree::ptree &pt) override
Load mechanism to load Options from a xml tree.
Definition: FANNOptions.cc:31
Belle2::MVA::FANNOptions::m_test_rate
unsigned int m_test_rate
Error on validation is compared with the one before.
Definition: FANN.h:74
Belle2::MVA::FANNOptions::m_verbose_mode
bool m_verbose_mode
Sets to report training status or not.
Definition: FANN.h:63
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MVA::FANNOptions::m_number_of_threads
unsigned int m_number_of_threads
Number of threads for parallel training.
Definition: FANN.h:76
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::FANNTeacher
Teacher for the FANN MVA method.
Definition: FANN.h:87
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::FANNExpert
Expert for the FANN MVA method.
Definition: FANN.h:111
Belle2::MVA::FANNOptions::m_output_activiation_function
std::string m_output_activiation_function
Activation function in output layer.
Definition: FANN.h:67
Belle2::MVA::FANNOptions::m_hidden_layers_architecture
std::string m_hidden_layers_architecture
String containing the architecture of hidden neurons.
Definition: FANN.h:64
Belle2::MVA::FANNOptions::m_scale_features
bool m_scale_features
Scale features before training.
Definition: FANN.h:79
Belle2::MVA::FANNOptions::m_scale_target
bool m_scale_target
Scale target before training.
Definition: FANN.h:80
Belle2::MVA::FANNExpert::apply
virtual std::vector< float > apply(Dataset &test_data) const override
Apply this expert onto a dataset.
Definition: FANN.cc:343
Belle2::MVA::FANNOptions::m_max_epochs
unsigned int m_max_epochs
Maximum number of epochs.
Definition: FANN.h:62
Belle2::MVA::FANNTeacher::train
virtual Weightfile train(Dataset &training_data) const override
Train a mva method using the given dataset returning a Weightfile.
Definition: FANN.cc:40
Belle2::MVA::FANNOptions::m_error_function
std::string m_error_function
Loss function.
Definition: FANN.h:68
Belle2::MVA::FANNExpert::m_specific_options
FANNOptions m_specific_options
Method specific options.
Definition: FANN.h:133
Belle2::MVA::FANNExpert::m_ann
struct fann * m_ann
Pointer to FANN expert.
Definition: FANN.h:134
Belle2::MVA::FANNOptions::getDescription
virtual po::options_description getDescription() override
Returns a program options description for all available options.
Definition: FANNOptions.cc:79
Belle2::MVA::FANNTeacher::m_specific_options
FANNOptions m_specific_options
Method specific options.
Definition: FANN.h:104
Belle2::MVA::FANNOptions::getHiddenLayerNeurons
std::vector< unsigned int > getHiddenLayerNeurons(unsigned int nf) const
Returns the internal vector parameter with the number of hidden neurons per layer.
Definition: FANNOptions.cc:103