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 bool targetresult = true;
55 bool multiplyHidden = false;
57 std::vector<std::vector<float>> outputScale = {{ -1., 1.}};
58
59
61 unsigned n_cdc_sector;
62 std::vector<float> i_cdc_sector;
64 unsigned n_ecl_sector;
65 std::vector<float> i_ecl_sector;
66
68 std::vector<std::vector<int>> total_bit_bias;
69 std::vector<std::vector<int>> int_bit_bias;
70 std::vector<std::vector<bool>> is_signed_bias;
71 std::vector<std::vector<int>> rounding_bias;
72 std::vector<std::vector<int>> saturation_bias;
73 std::vector<std::vector<int>> total_bit_accum;
74 std::vector<std::vector<int>> int_bit_accum;
75 std::vector<std::vector<bool>> is_signed_accum;
76 std::vector<std::vector<int>> rounding_accum;
77 std::vector<std::vector<int>> saturation_accum;
78 std::vector<std::vector<int>> total_bit_weight;
79 std::vector<std::vector<int>> int_bit_weight;
80 std::vector<std::vector<bool>> is_signed_weight;
81 std::vector<std::vector<int>> rounding_weight;
82 std::vector<std::vector<int>> saturation_weight;
83 std::vector<std::vector<int>> total_bit_relu;
84 std::vector<std::vector<int>> int_bit_relu;
85 std::vector<std::vector<bool>> is_signed_relu;
86 std::vector<std::vector<int>> rounding_relu;
87 std::vector<std::vector<int>> saturation_relu;
88 std::vector<std::vector<int>> total_bit;
89 std::vector<std::vector<int>> int_bit;
90 std::vector<std::vector<bool>> is_signed;
91 std::vector<std::vector<int>> rounding;
92 std::vector<std::vector<int>> saturation;
93 std::vector<std::vector<std::vector<int>>> W_input;
94 std::vector<std::vector<std::vector<int>>> I_input;
95 };
96
97
98
101
103 virtual ~GRLNeuro() {}
104
106 void initialize(const Parameters& p);
107
109 GRLMLP& operator[](unsigned index) { return m_MLPs[index]; }
111 const GRLMLP& operator[](unsigned index) const { return m_MLPs[index]; }
113 unsigned nSectors() const { return m_MLPs.size(); }
114
119 void save(const std::string& filename, const std::string& arrayname = "MLPs");
126 bool load(unsigned isector, const std::string& wfilename, const std::string& bfilename);
127
128 bool load(unsigned isector, std::vector<float> warray, std::vector<float> barray);//add
133 float runMLP(unsigned isector, const std::vector<float>& input);
134
135 private:
137 std::vector<GRLMLP> m_MLPs = {};
138
139 };
140
141}
142#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:109
void initialize(const Parameters &p)
Set parameters and get some network independent parameters.
Definition GRLNeuro.cc:248
virtual ~GRLNeuro()
Default destructor.
Definition GRLNeuro.h:103
bool load(unsigned isector, const std::string &wfilename, const std::string &bfilename)
Load MLPs from file.
Definition GRLNeuro.cc:559
void save(const std::string &filename, const std::string &arrayname="MLPs")
Save MLPs to file.
float runMLP(unsigned isector, const std::vector< float > &input)
Run an expert MLP.
Definition GRLNeuro.cc:422
GRLNeuro()
Default constructor.
Definition GRLNeuro.h:100
const GRLMLP & operator[](unsigned index) const
return const reference to a neural network
Definition GRLNeuro.h:111
std::vector< GRLMLP > m_MLPs
List of networks.
Definition GRLNeuro.h:137
unsigned nSectors() const
return number of neural networks
Definition GRLNeuro.h:113
Abstract base class for different kinds of events.
Struct to keep neurotrigger parameters.
Definition GRLNeuro.h:40
std::vector< std::vector< int > > total_bit_bias
bit width etc.
Definition GRLNeuro.h:68
std::vector< std::vector< float > > outputScale
Output scale for all networks.
Definition GRLNeuro.h:57
bool multiplyHidden
If true, multiply nHidden with number of input nodes.
Definition GRLNeuro.h:55
unsigned nMLP
Number of networks.
Definition GRLNeuro.h:46
bool targetresult
train result as output
Definition GRLNeuro.h:53
unsigned n_ecl_sector
Number of ECL sectors.
Definition GRLNeuro.h:64
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:61