Belle II Software development
FANNOptions Class Reference

Options for the FANN MVA method. More...

#include <FANN.h>

Inheritance diagram for FANNOptions:
SpecificOptions Options

Public Member Functions

virtual void load (const boost::property_tree::ptree &pt) override
 Load mechanism to load Options from a xml tree.
 
virtual void save (boost::property_tree::ptree &pt) const override
 Save mechanism to store Options in a xml tree.
 
virtual po::options_description getDescription () override
 Returns a program options description for all available options.
 
virtual std::string getMethod () const override
 Return method name.
 
std::vector< unsigned int > getHiddenLayerNeurons (unsigned int nf) const
 Returns the internal vector parameter with the number of hidden neurons per layer.
 

Public Attributes

unsigned int m_max_epochs = 10000
 Maximum number of epochs.
 
bool m_verbose_mode = true
 Sets to report training status or not.
 
std::string m_hidden_layers_architecture = "3*N"
 String containing the architecture of hidden neurons.
 
std::string m_hidden_activiation_function = "FANN_SIGMOID_SYMMETRIC"
 Activation function in hidden layer.
 
std::string m_output_activiation_function = "FANN_SIGMOID_SYMMETRIC"
 Activation function in output layer.
 
std::string m_error_function = "FANN_ERRORFUNC_LINEAR"
 Loss function.
 
std::string m_training_method = "FANN_TRAIN_RPROP"
 Training method for back propagation.
 
double m_validation_fraction = 0.5
 Fraction of training sample used for validation in order to avoid overtraining.
 
unsigned int m_random_seeds
 Number of times the training is repeated with a new weight random seed.
 
unsigned int m_test_rate
 Error on validation is compared with the one before.
 
unsigned int m_number_of_threads = 8
 Number of threads for parallel training.
 
bool m_scale_features = true
 Scale features before training.
 
bool m_scale_target = true
 Scale target before training.
 

Detailed Description

Options for the FANN MVA method.

Definition at line 29 of file FANN.h.

Member Function Documentation

◆ getDescription()

po::options_description getDescription ( )
overridevirtual

Returns a program options description for all available options.

Implements Options.

Definition at line 69 of file FANNOptions.cc.

70 {
71 po::options_description description("FANN options");
72 description.add_options()
73 ("max_epochs", po::value<unsigned int>(&m_max_epochs), "Number of iEpochs")
74 ("verbose_mode", po::value<bool>(&m_verbose_mode), "Prints out the training status or not")
75 ("hidden_layers_architecture", po::value<std::string>(&m_hidden_layers_architecture),
76 "Architecture with number of neurons in each hidden layer")
77 ("hidden_activiation_function", po::value<std::string>(&m_hidden_activiation_function),
78 "Name of acitvation function used for hidden layers")
79 ("output_activiation_function", po::value<std::string>(&m_output_activiation_function),
80 "Name of acitvation function used for output layer")
81 ("error_function", po::value<std::string>(&m_error_function), "Name of error function")
82 ("training_method", po::value<std::string>(&m_training_method), "Method used for backpropagation")
83 ("validation_fraction", po::value<double>(&m_validation_fraction), "Fraction of training sample used for validation.")
84 ("random_seeds", po::value<unsigned int>(&m_random_seeds),
85 "Number of times the training is repeated with a new weight random seed.")
86 ("test_rate", po::value<unsigned int>(&m_test_rate), "Rate of iEpochs to check the validation error")
87 ("number_of_threads", po::value<unsigned int>(&m_number_of_threads), "Number of threads for parallel training")
88 ("scale_features", po::value<bool>(&m_scale_features), "Boolean indicating if features should be scaled or not")
89 ("scale_target", po::value<bool>(&m_scale_target), "Boolean indicating if target should be scaled or not");
90 return description;
91 }
double m_validation_fraction
Fraction of training sample used for validation in order to avoid overtraining.
Definition: FANN.h:69
std::string m_hidden_layers_architecture
String containing the architecture of hidden neurons.
Definition: FANN.h:62
bool m_scale_features
Scale features before training.
Definition: FANN.h:77
bool m_verbose_mode
Sets to report training status or not.
Definition: FANN.h:61
unsigned int m_random_seeds
Number of times the training is repeated with a new weight random seed.
Definition: FANN.h:70
std::string m_error_function
Loss function.
Definition: FANN.h:66
unsigned int m_number_of_threads
Number of threads for parallel training.
Definition: FANN.h:74
unsigned int m_test_rate
Error on validation is compared with the one before.
Definition: FANN.h:72
std::string m_hidden_activiation_function
Activation function in hidden layer.
Definition: FANN.h:64
bool m_scale_target
Scale target before training.
Definition: FANN.h:78
std::string m_training_method
Training method for back propagation.
Definition: FANN.h:67
std::string m_output_activiation_function
Activation function in output layer.
Definition: FANN.h:65
unsigned int m_max_epochs
Maximum number of epochs.
Definition: FANN.h:60

◆ getHiddenLayerNeurons()

std::vector< unsigned int > getHiddenLayerNeurons ( unsigned int  nf) const

Returns the internal vector parameter with the number of hidden neurons per layer.

Parameters
nfnumber of features (input nodes).

Definition at line 93 of file FANNOptions.cc.

94 {
95 std::vector<unsigned int> hiddenLayers;
96 std::stringstream iLayers(m_hidden_layers_architecture);
97 std::string layer;
98 while (std::getline(iLayers, layer, ',')) {
99 for (auto& character : layer) {
100 if (character == 'N') character = 'x';
101 }
102 auto* iLayerSize = new TFormula("iLayerSize", layer.c_str());
103 hiddenLayers.push_back(iLayerSize->Eval(nf));
104 }
105 return hiddenLayers;
106 }

◆ getMethod()

virtual std::string getMethod ( ) const
inlineoverridevirtual

Return method name.

Implements SpecificOptions.

Definition at line 52 of file FANN.h.

52{ return "FANN"; }

◆ load()

void load ( const boost::property_tree::ptree &  pt)
overridevirtual

Load mechanism to load Options from a xml tree.

Parameters
ptxml tree

Implements Options.

Definition at line 21 of file FANNOptions.cc.

22 {
23
24 int version = pt.get<int>("FANN_version");
25 if (version != 1) {
26 B2ERROR("Unknown weightfile version " << std::to_string(version));
27 throw std::runtime_error("Unknown weightfile version " + std::to_string(version));
28 }
29 m_max_epochs = pt.get<unsigned int>("FANN_max_epochs");
30 m_verbose_mode = pt.get<bool>("FANN_verbose_mode");
31
32 m_hidden_layers_architecture = pt.get<std::string>("FANN_hidden_layers_architecture");
33
34 m_hidden_activiation_function = pt.get<std::string>("FANN_hidden_activation_function");
35 m_output_activiation_function = pt.get<std::string>("FANN_output_activation_function");
36 m_error_function = pt.get<std::string>("FANN_error_function");
37 m_training_method = pt.get<std::string>("FANN_training_method");
38 m_validation_fraction = pt.get<double>("FANN_validation_fraction");
39 m_random_seeds = pt.get<unsigned int>("FANN_random_seeds");
40 m_test_rate = pt.get<unsigned int>("FANN_test_rate");
41 m_number_of_threads = pt.get<unsigned int>("FANN_number_of_threads");
42
43 m_scale_features = pt.get<bool>("FANN_scale_features");
44 m_scale_target = pt.get<bool>("FANN_scale_target");
45
46 }

◆ save()

void save ( boost::property_tree::ptree &  pt) const
overridevirtual

Save mechanism to store Options in a xml tree.

Parameters
ptxml tree

Implements Options.

Definition at line 48 of file FANNOptions.cc.

49 {
50 pt.put("FANN_version", 1);
51 pt.put("FANN_max_epochs", m_max_epochs);
52 pt.put("FANN_verbose_mode", m_verbose_mode);
53 pt.put("FANN_hidden_layers_architecture", m_hidden_layers_architecture);
54 pt.put("FANN_hidden_activation_function", m_hidden_activiation_function);
55 pt.put("FANN_output_activation_function", m_output_activiation_function);
56 pt.put("FANN_error_function", m_error_function);
57 pt.put("FANN_training_method", m_training_method);
58 pt.put("FANN_validation_fraction", m_validation_fraction);
59 pt.put("FANN_random_seeds", m_random_seeds);
60 pt.put("FANN_test_rate", m_test_rate);
61 pt.put("FANN_number_of_threads", m_number_of_threads);
62
63 pt.put("FANN_scale_features", m_scale_features);
64 pt.put("FANN_scale_target", m_scale_target);
65
66
67 }

Member Data Documentation

◆ m_error_function

std::string m_error_function = "FANN_ERRORFUNC_LINEAR"

Loss function.

Definition at line 66 of file FANN.h.

◆ m_hidden_activiation_function

std::string m_hidden_activiation_function = "FANN_SIGMOID_SYMMETRIC"

Activation function in hidden layer.

Definition at line 64 of file FANN.h.

◆ m_hidden_layers_architecture

std::string m_hidden_layers_architecture = "3*N"

String containing the architecture of hidden neurons.

Ex. "3,3*N,3*(N-1)

Definition at line 62 of file FANN.h.

◆ m_max_epochs

unsigned int m_max_epochs = 10000

Maximum number of epochs.

Definition at line 60 of file FANN.h.

◆ m_number_of_threads

unsigned int m_number_of_threads = 8

Number of threads for parallel training.

Definition at line 74 of file FANN.h.

◆ m_output_activiation_function

std::string m_output_activiation_function = "FANN_SIGMOID_SYMMETRIC"

Activation function in output layer.

Definition at line 65 of file FANN.h.

◆ m_random_seeds

unsigned int m_random_seeds
Initial value:
=
3

Number of times the training is repeated with a new weight random seed.

The one with the best result is saved.

Definition at line 70 of file FANN.h.

◆ m_scale_features

bool m_scale_features = true

Scale features before training.

Definition at line 77 of file FANN.h.

◆ m_scale_target

bool m_scale_target = true

Scale target before training.

Definition at line 78 of file FANN.h.

◆ m_test_rate

unsigned int m_test_rate
Initial value:
=
500

Error on validation is compared with the one before.

The number of epochs before is given by this parameter.

Definition at line 72 of file FANN.h.

◆ m_training_method

std::string m_training_method = "FANN_TRAIN_RPROP"

Training method for back propagation.

Definition at line 67 of file FANN.h.

◆ m_validation_fraction

double m_validation_fraction = 0.5

Fraction of training sample used for validation in order to avoid overtraining.

Definition at line 69 of file FANN.h.

◆ m_verbose_mode

bool m_verbose_mode = true

Sets to report training status or not.

Definition at line 61 of file FANN.h.


The documentation for this class was generated from the following files: