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//#include <trg/cdc/dbobjects/CDCTriggerNeuroConfig.h>
17//#include <framework/dataobjects/BinnedEventT0.h>
18
19namespace Belle2 {
35 class GRLNeuro {
36 public:
41 struct Parameters {
47 unsigned nMLP;
52 std::vector<std::vector<float>> nHidden;
54 bool targetresult = true;
56 bool multiplyHidden = false;
58 std::vector<std::vector<float>> outputScale = {{ -1., 1.}};
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 };
67
68
69
72
74 virtual ~GRLNeuro() {}
75
77 void initialize(const Parameters& p);
79 //void initialize(const std::vector<float>& nodes);
80
82 GRLMLP& operator[](unsigned index) { return m_MLPs[index]; }
84 const GRLMLP& operator[](unsigned index) const { return m_MLPs[index]; }
86 unsigned nSectors() const { return m_MLPs.size(); }
87
89 float relu(float x);
90
92 float float_to_fixed(float num, int m, int n);
93
95 float mysigmiod(float num);
100 void save(const std::string& filename, const std::string& arrayname = "MLPs");
107 bool load(unsigned isector, const std::string& wfilename, const std::string& bfilename);
108
113 float runMLP(unsigned isector, const std::vector<float>& input);
114
115 private:
117 std::vector<GRLMLP> m_MLPs = {};
118
119 };
121}
122#endif
Class to keep all parameters of an expert MLP for the neuro trigger.
Definition: GRLMLP.h:21
Class to represent the GRL Neuro.
Definition: GRLNeuro.h:35
GRLMLP & operator[](unsigned index)
Set parameters and get some network independent parameters.
Definition: GRLNeuro.h:82
void initialize(const Parameters &p)
Set parameters and get some network independent parameters.
Definition: GRLNeuro.cc:29
virtual ~GRLNeuro()
Default destructor.
Definition: GRLNeuro.h:74
bool load(unsigned isector, const std::string &wfilename, const std::string &bfilename)
Load MLPs from file.
Definition: GRLNeuro.cc:154
float mysigmiod(float num)
discrete sigmoid activation function (1024 bins)
Definition: GRLNeuro.cc:245
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:87
GRLNeuro()
Default constructor.
Definition: GRLNeuro.h:71
const GRLMLP & operator[](unsigned index) const
return const reference to a neural network
Definition: GRLNeuro.h:84
std::vector< GRLMLP > m_MLPs
List of networks.
Definition: GRLNeuro.h:117
float relu(float x)
ReLu activation function.
Definition: GRLNeuro.cc:79
float float_to_fixed(float num, int m, int n)
change the percision of number, m = number of integer bits, n = number of decimal
Definition: GRLNeuro.cc:216
unsigned nSectors() const
return number of neural networks
Definition: GRLNeuro.h:86
Abstract base class for different kinds of events.
Struct to keep neurotrigger parameters.
Definition: GRLNeuro.h:41
std::vector< std::vector< float > > outputScale
Output scale for all networks.
Definition: GRLNeuro.h:58
bool multiplyHidden
If true, multiply nHidden with number of input nodes.
Definition: GRLNeuro.h:56
unsigned nMLP
Number of networks.
Definition: GRLNeuro.h:47
bool targetresult
train result as output
Definition: GRLNeuro.h:54
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:52
unsigned n_cdc_sector
Number of CDC sectors.
Definition: GRLNeuro.h:61