Belle II Software  release-08-01-10
GRLMLP.h
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 #ifndef GRLMLP_H
10 #define GRLMLP_H
11 
12 #include <TObject.h>
13 #include <framework/logging/Logger.h>
14 
15 namespace Belle2 {
21  class GRLMLP : public TObject {
22 
23  // weights etc. are set only by the trainer
24  friend class GRLNeuroTrainerModule;
25 
26  public:
28  GRLMLP();
29 
31  GRLMLP(std::vector<unsigned short>& nodes, unsigned short targets, const std::vector<float>& outputscale);
32 
34  ~GRLMLP() { }
35 
37  bool isTrained() const { return m_trained; }
39  unsigned getNumberOfLayers() const { return m_nNodes.size(); }
41  unsigned getNumberOfNodesLayer(unsigned iLayer) const { return m_nNodes[iLayer]; }
43  unsigned getNumberOfWeights() const { return m_weights.size(); }
45  unsigned nWeightsCal() const;
47  unsigned nBiasCal() const;
49  std::vector<float> getWeights() const { return m_weights; }
51  std::vector<float> getBias() const { return m_bias; }
53  void setWeights(std::vector<float>& weights) { m_weights = weights; }
55  void setBias(std::vector<float>& bias) { m_bias = bias; }
56 
58  void Trained(bool trained) { m_trained = trained; }
59 
60  private:
62  std::vector<unsigned short> m_nNodes;
64  std::vector<float> m_weights;
66  std::vector<float> m_bias;
69  bool m_trained;
70 
72  unsigned short m_targetVars;
75  std::vector<float> m_outputScale;
76 
79  };
81 }
82 #endif
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: GRLMLP.h:21
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
bool isTrained() const
check if weights are default values or set by some trainer
Definition: GRLMLP.h:37
unsigned getNumberOfLayers() const
get number of layers
Definition: GRLMLP.h:39
std::vector< float > m_outputScale
Output[i] of the MLP is scaled from [-1, 1] to [outputScale[2i], outputScale[2i+1]].
Definition: GRLMLP.h:75
unsigned getNumberOfWeights() const
get number of weights from length of weights vector
Definition: GRLMLP.h:43
void Trained(bool trained)
check if weights are default values or set by some trainer
Definition: GRLMLP.h:58
ClassDef(GRLMLP, 2)
Needed to make the ROOT object storable.
std::vector< unsigned short > m_nNodes
Number of nodes in each layer, not including bias nodes.
Definition: GRLMLP.h:62
void setWeights(std::vector< float > &weights)
set weights vector
Definition: GRLMLP.h:53
std::vector< float > m_bias
bias of the network.
Definition: GRLMLP.h:66
void setBias(std::vector< float > &bias)
set bias vector
Definition: GRLMLP.h:55
unsigned getNumberOfNodesLayer(unsigned iLayer) const
get number of nodes in a layer
Definition: GRLMLP.h:41
std::vector< float > getBias() const
get bias vector
Definition: GRLMLP.h:51
unsigned nBiasCal() const
calculate number of weights from number of nodes
Definition: GRLMLP.cc:45
unsigned short m_targetVars
output variables: 1: z, 2: theta, 3: (z, theta)
Definition: GRLMLP.h:72
~GRLMLP()
destructor, empty because we don't allocate memory anywhere.
Definition: GRLMLP.h:34
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:69
std::vector< float > getWeights() const
get weights vector
Definition: GRLMLP.h:49
The trainer module for the neural networks of the CDC trigger.
Abstract base class for different kinds of events.