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_nNodes{19, 20, 20, 1}, m_trained(false), m_targetVars(1), m_outputScale{ 0., 1.}
16{
17 m_weights.assign(nWeightsCal(), 0.);
18 m_bias.assign(nBiasCal(), 0.);
19}
20
21GRLMLP::GRLMLP(std::vector<unsigned short>& nodes,
22 unsigned short targets,
23 const std::vector<float>& outputscale
24 ):
25 m_nNodes(nodes), m_trained(false), m_targetVars(targets), m_outputScale(outputscale)
26{
27 m_weights.assign(nWeightsCal(), 0.);
28 m_bias.assign(nBiasCal(), 0.);
29}
30
31unsigned
33{
34 unsigned nWeights = 0;
35 if (getNumberOfLayers() > 1) {
36 nWeights = m_nNodes[0] * m_nNodes[1];
37 for (unsigned il = 1; il < getNumberOfLayers() - 1; ++il) {
38 nWeights += m_nNodes[il] * m_nNodes[il + 1];
39 }
40 }
41 return nWeights;
42}
43
44unsigned
46{
47 unsigned nbias = 0;
48 if (getNumberOfLayers() > 1) {
49 for (unsigned il = 1; il < getNumberOfLayers(); ++il) {
50 nbias += m_nNodes[il] ;
51 }
52 }
53 return nbias;
54}
55
std::vector< float > m_weights
Weights of the network.
Definition: GRLMLP.h:64
GRLMLP()
default constructor.
Definition: GRLMLP.cc:14
unsigned nWeightsCal() const
calculate number of weights from number of nodes
Definition: GRLMLP.cc:32
unsigned getNumberOfLayers() const
get number of layers
Definition: GRLMLP.h:39
std::vector< unsigned short > m_nNodes
Number of nodes in each layer, not including bias nodes.
Definition: GRLMLP.h:62
std::vector< float > m_bias
bias of the network.
Definition: GRLMLP.h:66
unsigned nBiasCal() const
calculate number of weights from number of nodes
Definition: GRLMLP.cc:45
Abstract base class for different kinds of events.