Belle II Software prerelease-11-00-00a
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)
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 ):
23 m_n_nodes(nodes), m_trained(false)
24{
25 m_weights.assign(n_weights_cal(), 0.);
26 m_bias.assign(n_bias_cal(), 0.);
27}
28
29unsigned
31{
32 unsigned n_weights = 0;
33 if (get_number_of_layers() > 1) {
34 n_weights = m_n_nodes[0] * m_n_nodes[1];
35 for (unsigned il = 1; il < get_number_of_layers() - 1; ++il) {
36 n_weights += m_n_nodes[il] * m_n_nodes[il + 1];
37 }
38 }
39 return n_weights;
40}
41
42unsigned
44{
45 unsigned nbias = 0;
46 if (get_number_of_layers() > 1) {
47 for (unsigned il = 1; il < get_number_of_layers(); ++il) {
48 nbias += m_n_nodes[il] ;
49 }
50 }
51 return nbias;
52}
53
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:129
GRLMLP()
default constructor.
Definition GRLMLP.cc:14
std::vector< unsigned short > m_n_nodes
Number of nodes in each layer, not including bias nodes.
Definition GRLMLP.h:125
unsigned n_weights_cal() const
calculate number of weights from number of nodes
Definition GRLMLP.cc:30
unsigned n_bias_cal() const
calculate number of weights from number of nodes
Definition GRLMLP.cc:43
std::vector< float > m_bias
bias of the network.
Definition GRLMLP.h:131
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:163
Abstract base class for different kinds of events.