Belle II Software development
GRLMLP.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 <trg/grl/dataobjects/GRLMLP.h>
10#include <cmath>
11
12using namespace Belle2;
13
15 m_n_nodes{24, 24, 24, 24, 1}, m_trained(false), m_target_vars(1), m_output_scale{ 0., 1.}
16{
17 m_weights.assign(n_weights_cal(), 0.);
18 m_bias.assign(n_bias_cal(), 0.);
19}
20
21GRLMLP::GRLMLP(std::vector<unsigned short>& nodes,
22 unsigned short targets,
23 const std::vector<float>& outputscale
24 ):
25 m_n_nodes(nodes), m_trained(false), m_target_vars(targets), m_output_scale(outputscale)
26{
27 m_weights.assign(n_weights_cal(), 0.);
28 m_bias.assign(n_bias_cal(), 0.);
29}
30
31unsigned
33{
34 unsigned n_weights = 0;
35 if (get_number_of_layers() > 1) {
36 n_weights = m_n_nodes[0] * m_n_nodes[1];
37 for (unsigned il = 1; il < get_number_of_layers() - 1; ++il) {
38 n_weights += m_n_nodes[il] * m_n_nodes[il + 1];
39 }
40 }
41 return n_weights;
42}
43
44unsigned
46{
47 unsigned nbias = 0;
48 if (get_number_of_layers() > 1) {
49 for (unsigned il = 1; il < get_number_of_layers(); ++il) {
50 nbias += m_n_nodes[il] ;
51 }
52 }
53 return nbias;
54}
55
unsigned get_number_of_layers() const
get number of layers
Definition GRLMLP.h:39
std::vector< float > m_weights
Weights of the network.
Definition GRLMLP.h:122
GRLMLP()
default constructor.
Definition GRLMLP.cc:14
unsigned short m_target_vars
output variables: 1: z, 2: theta, 3: (z, theta)
Definition GRLMLP.h:159
std::vector< unsigned short > m_n_nodes
Number of nodes in each layer, not including bias nodes.
Definition GRLMLP.h:120
unsigned n_weights_cal() const
calculate number of weights from number of nodes
Definition GRLMLP.cc:32
unsigned n_bias_cal() const
calculate number of weights from number of nodes
Definition GRLMLP.cc:45
std::vector< float > m_output_scale
Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
Definition GRLMLP.h:162
std::vector< float > m_bias
bias of the network.
Definition GRLMLP.h:124
bool m_trained
Indicator whether the weights are just default values or have been set by some trainer (set to true w...
Definition GRLMLP.h:156
Abstract base class for different kinds of events.