ATLAS Offline Software
InputPreprocessor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 namespace lwtDev {
8  // ______________________________________________________________________
9  // Input preprocessors
10 
11  // simple feed-forwared version
12  InputPreprocessor::InputPreprocessor(const std::vector<Input>& inputs):
13  m_offsets(inputs.size()),
14  m_scales(inputs.size())
15  {
16  size_t in_num = 0;
17  for (const auto& input: inputs) {
18  m_offsets(in_num) = input.offset;
19  m_scales(in_num) = input.scale;
20  m_names.push_back(input.name);
21  in_num++;
22  }
23  }
24  VectorXd InputPreprocessor::operator()(const ValueMap& in) const {
25  VectorXd invec(m_names.size());
26  size_t input_number = 0;
27  for (const auto& in_name: m_names) {
28  if (!in.count(in_name)) {
29  throw NNEvaluationException("can't find input: " + in_name);
30  }
31  invec(input_number) = in.at(in_name);
32  input_number++;
33  }
34  return (invec + m_offsets).cwiseProduct(m_scales);
35  }
36 
37 
38  // Input vector preprocessor
40  const std::vector<Input>& inputs):
41  m_offsets(inputs.size()),
42  m_scales(inputs.size())
43  {
44  size_t in_num = 0;
45  for (const auto& input: inputs) {
46  m_offsets(in_num) = input.offset;
47  m_scales(in_num) = input.scale;
48  m_names.push_back(input.name);
49  in_num++;
50  }
51  // require at least one input at configuration, since we require
52  // at least one for evaluation
53  if (in_num == 0) {
54  throw NNConfigurationException("need at least one input");
55  }
56  }
57  MatrixXd InputVectorPreprocessor::operator()(const VectorMap& in) const {
58  using namespace Eigen;
59  if (in.size() == 0) {
60  throw NNEvaluationException("Empty input map");
61  }
62  size_t n_cols = in.begin()->second.size();
63  MatrixXd inmat(m_names.size(), n_cols);
64  size_t in_num = 0;
65  for (const auto& in_name: m_names) {
66  if (!in.count(in_name)) {
67  throw NNEvaluationException("can't find input: " + in_name);
68  }
69  const auto& invec = in.at(in_name);
70  if (invec.size() != n_cols) {
71  throw NNEvaluationException("Input vector size mismatch");
72  }
73  inmat.row(in_num) = Map<const VectorXd>(invec.data(), invec.size());
74  in_num++;
75  }
76  if (n_cols == 0) {
77  return MatrixXd(m_names.size(), 0);
78  }
79  return m_scales.asDiagonal() * (inmat.colwise() + m_offsets);
80  }
81 
82 }
lwtDev::InputVectorPreprocessor::operator()
MatrixXd operator()(const VectorMap &) const
Definition: InputPreprocessor.cxx:57
lwtDev::ValueMap
std::map< std::string, double > ValueMap
Definition: InputPreprocessor.h:22
lwtDev::VectorMap
std::map< std::string, std::vector< double > > VectorMap
Definition: InputPreprocessor.h:24
lwtDev::InputVectorPreprocessor::m_names
std::vector< std::string > m_names
Definition: InputPreprocessor.h:50
lwtDev::InputVectorPreprocessor::m_scales
VectorXd m_scales
Definition: InputPreprocessor.h:49
lwtDev::InputPreprocessor::m_scales
VectorXd m_scales
Definition: InputPreprocessor.h:37
lwtDev::InputVectorPreprocessor::m_offsets
VectorXd m_offsets
Definition: InputPreprocessor.h:48
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
lwtDev::NNConfigurationException
Definition: Reconstruction/tauRecTools/tauRecTools/lwtnn/Exceptions.h:21
lwtDev::InputPreprocessor::InputPreprocessor
InputPreprocessor(const std::vector< Input > &inputs)
Definition: InputPreprocessor.cxx:12
lwtDev::InputVectorPreprocessor::InputVectorPreprocessor
InputVectorPreprocessor(const std::vector< Input > &inputs)
Definition: InputPreprocessor.cxx:39
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
lwtDev::InputPreprocessor::m_names
std::vector< std::string > m_names
Definition: InputPreprocessor.h:38
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
InputPreprocessor.h
lwtDev
Definition: Reconstruction/tauRecTools/Root/lwtnn/Exceptions.cxx:8
lwtDev::InputPreprocessor::m_offsets
VectorXd m_offsets
Definition: InputPreprocessor.h:36
lwtDev::NNEvaluationException
Definition: Reconstruction/tauRecTools/tauRecTools/lwtnn/Exceptions.h:27
lwtDev::InputPreprocessor::operator()
VectorXd operator()(const ValueMap &) const
Definition: InputPreprocessor.cxx:24