Belle II Software development
GRLNeuro.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 GRLNEURO_H
10#define GRLNEURO_H
11
12#include <trg/grl/dataobjects/GRLMLP.h>
13#include <framework/datastore/StoreArray.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/database/DBObjPtr.h>
16
17
18namespace Belle2 {
23
34 class GRLNeuro {
35 public:
40 struct Parameters {
46 unsigned nMLP;
51 std::vector<std::vector<float>> nHidden;
53 int targetresult = 10;
55 std::vector<unsigned> nOutput;
57 std::vector<std::vector<float>> nn_thres;
59 bool multiplyHidden = false;
61 std::vector<std::vector<float>> outputScale = {{ -1., 1.}};
62
63
65 unsigned n_cdc_sector;
66 std::vector<float> i_cdc_sector;
68 unsigned n_ecl_sector;
69 std::vector<float> i_ecl_sector;
70
72 std::vector<std::vector<int>> total_bit_bias;
73 std::vector<std::vector<int>> int_bit_bias;
74 std::vector<std::vector<bool>> is_signed_bias;
75 std::vector<std::vector<int>> rounding_bias;
76 std::vector<std::vector<int>> saturation_bias;
77 std::vector<std::vector<int>> total_bit_accum;
78 std::vector<std::vector<int>> int_bit_accum;
79 std::vector<std::vector<bool>> is_signed_accum;
80 std::vector<std::vector<int>> rounding_accum;
81 std::vector<std::vector<int>> saturation_accum;
82 std::vector<std::vector<int>> total_bit_weight;
83 std::vector<std::vector<int>> int_bit_weight;
84 std::vector<std::vector<bool>> is_signed_weight;
85 std::vector<std::vector<int>> rounding_weight;
86 std::vector<std::vector<int>> saturation_weight;
87 std::vector<std::vector<int>> total_bit_relu;
88 std::vector<std::vector<int>> int_bit_relu;
89 std::vector<std::vector<bool>> is_signed_relu;
90 std::vector<std::vector<int>> rounding_relu;
91 std::vector<std::vector<int>> saturation_relu;
92 std::vector<std::vector<int>> total_bit;
93 std::vector<std::vector<int>> int_bit;
94 std::vector<std::vector<bool>> is_signed;
95 std::vector<std::vector<int>> rounding;
96 std::vector<std::vector<int>> saturation;
97 std::vector<std::vector<std::vector<int>>> W_input;
98 std::vector<std::vector<std::vector<int>>> I_input;
100 std::vector<std::vector<std::vector<int>>> W_input_layer;
101 std::vector<std::vector<std::vector<int>>> I_input_layer;
102 };
103
104
105
108
110 virtual ~GRLNeuro() {}
111
113 void initialize(const Parameters& p);
114
116 GRLMLP& operator[](unsigned index) { return m_MLPs[index]; }
118 const GRLMLP& operator[](unsigned index) const { return m_MLPs[index]; }
120 unsigned nSectors() const { return m_MLPs.size(); }
121
126 void save(const std::string& filename, const std::string& arrayname = "MLPs");
133 bool load(unsigned isector, const std::string& wfilename, const std::string& bfilename);
134
135 bool load(unsigned isector, std::vector<float> warray, std::vector<float> barray);//add
140 std::vector<float> runMLP(unsigned isector, const std::vector<float>& input);
141
142 private:
144 std::vector<GRLMLP> m_MLPs = {};
145
146 };
147
148}
149#endif
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition GRLMLP.h:21
GRLMLP & operator[](unsigned index)
return reference to a neural network
Definition GRLNeuro.h:116
void initialize(const Parameters &p)
Set parameters and get some network independent parameters.
Definition GRLNeuro.cc:251
virtual ~GRLNeuro()
Default destructor.
Definition GRLNeuro.h:110
bool load(unsigned isector, const std::string &wfilename, const std::string &bfilename)
Load MLPs from file.
Definition GRLNeuro.cc:569
void save(const std::string &filename, const std::string &arrayname="MLPs")
Save MLPs to file.
GRLNeuro()
Default constructor.
Definition GRLNeuro.h:107
const GRLMLP & operator[](unsigned index) const
return const reference to a neural network
Definition GRLNeuro.h:118
std::vector< GRLMLP > m_MLPs
List of networks.
Definition GRLNeuro.h:144
std::vector< float > runMLP(unsigned isector, const std::vector< float > &input)
Run an expert MLP.
Definition GRLNeuro.cc:423
unsigned nSectors() const
return number of neural networks
Definition GRLNeuro.h:120
Abstract base class for different kinds of events.
Struct to keep neurotrigger parameters.
Definition GRLNeuro.h:40
std::vector< std::vector< std::vector< int > > > W_input_layer
Input layer quantization: per-input W and I bit widths for the first dense layer.
Definition GRLNeuro.h:100
std::vector< std::vector< int > > total_bit_bias
bit width etc.
Definition GRLNeuro.h:72
std::vector< std::vector< float > > outputScale
Output scale for all networks.
Definition GRLNeuro.h:61
int targetresult
train result as output
Definition GRLNeuro.h:53
bool multiplyHidden
If true, multiply nHidden with number of input nodes.
Definition GRLNeuro.h:59
std::vector< unsigned > nOutput
Number of output nodes.
Definition GRLNeuro.h:55
unsigned nMLP
Number of networks.
Definition GRLNeuro.h:46
unsigned n_ecl_sector
Number of ECL sectors.
Definition GRLNeuro.h:68
std::vector< std::vector< float > > nn_thres
Threshold of output nodes.
Definition GRLNeuro.h:57
std::vector< std::vector< float > > nHidden
Number of nodes in each hidden layer for all networks or factor to multiply with number of inputs.
Definition GRLNeuro.h:51
unsigned n_cdc_sector
Number of CDC sectors.
Definition GRLNeuro.h:65