10#include <analysis/modules/PIDNeuralNetworkParametersCreator/PIDNeuralNetworkParametersCreatorModule.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <framework/database/DBImportObjPtr.h>
15#include <framework/logging/Logger.h>
17#define FDEEP_FLOAT_TYPE float
18#include <fdeep/fdeep.hpp>
27 setDescription(R
"DOC(Module that creates PID neural network parameters and uploads them to the DB)DOC");
36 "List of PDG codes of the hypotheses that correspond to the neural network output probabilities");
37 addParam(
"meanValues",
m_meanValues,
"List of mean values of input variables for normalization");
40 "List of indices and values set if the variable defined by the index is NaN");
41 addParam(
"inputsToCut",
m_inputsToCut,
"List of input values that are cut if another input value is in a given range");
58 const auto inputShapes = model.get_input_shapes();
59 size_t nModelInputs = 0;
60 for (
const auto& shape : inputShapes) {
61 if (shape.rank() != 1) {
62 std::cout <<
"Can handle only rank=1 inputs, but input has rank " << shape.rank() << std::endl;
66 nModelInputs += shape.minimal_volume();
68 if (nModelInputs != nInputs) {
69 std::cout <<
"Model requires " << nModelInputs <<
" inputs, but parameters have only " << nInputs <<
" inputs!" << std::endl;
73 const auto outputShapes = model.get_output_shapes();
74 size_t nModelOutputs = 0;
75 for (
const auto& shape : outputShapes) {
76 if (shape.rank() != 1) {
77 std::cout <<
"Can handle only rank=1 outputs, but output has rank " << shape.rank() << std::endl;
81 nModelOutputs += shape.minimal_volume();
83 if (nModelOutputs != nOutputs) {
84 std::cout <<
"Model has " << nModelOutputs <<
" outputs, but parameters have only " << nOutputs <<
" outputs!" << std::endl;
89 std::cout <<
"Parameters have " <<
m_meanValues.size() <<
" mean values, but " << nInputs <<
" inputs!";
94 std::cout <<
"Parameters have " <<
m_standardDeviations.size() <<
" standard deviations, but " << nInputs <<
" inputs!";
99 const auto [index, _] = index_value;
100 if (index >= nInputs) {
101 std::cout <<
"Index " << index <<
" of handleMissingInputs out of range!" << std::endl;
107 const size_t inputSetIndex = std::get<0>(inputToCut);
108 const size_t inputCutIndex = std::get<1>(inputToCut);
109 if (inputSetIndex >= nInputs) {
110 std::cout <<
"inputSetIndex " << inputSetIndex <<
" of handleMissingInputs out of range!" << std::endl;
113 if (inputCutIndex >= nInputs) {
114 std::cout <<
"inputCutIndex " << inputCutIndex <<
" of handleMissingInputs out of range!" << std::endl;
120 B2ERROR(
"The given neural-network parameters are invalid!");
Class for importing a single object to the database.
A class that describes the interval of experiments/runs for which an object in the database is valid.
void setDescription(const std::string &description)
Sets the description of the module.
PIDNNInputsToCut m_inputsToCut
overwrite certain input variables
void initialize() override
Initialize the module.
std::vector< float > m_standardDeviations
standard deviations of inputs
PIDNeuralNetworkParametersCreatorModule()
Constructor: Sets the description, the properties and the parameters of the module.
PIDNNMissingInputs m_handleMissingInputs
handling of NaN inputs
int m_runLow
Lowest valid run #.
std::vector< std::string > m_inputNames
list of input names
std::string m_neuralNetworkParametersName
Name of the set of parameters.
std::string m_modelDefinition
neural network string for frugally-deep
std::vector< float > m_meanValues
mean values of inputs
std::vector< int > m_outputSpeciesPdg
PDG codes of hypotheses of neural-network output.
int m_experimentLow
Lowest valid experiment #.
std::string m_description
description of neural network parameters
int m_experimentHigh
Highest valid experiment #.
int m_runHigh
Highest valid run #.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.