ATLAS Offline Software
Loading...
Searching...
No Matches
LightweightGraph.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef LIGHTWEIGHT_GRAPH_HH_TAURECTOOLS
6#define LIGHTWEIGHT_GRAPH_HH_TAURECTOOLS
7
8/* Lightweight Graph
9
10 The lightweightGraph class is a more flexible version of the
11 LightweightNeuralNetwork class. This flexibility comes from the
12 ability to read from multiple inputs, merge them, and then expose
13 multiple outputs.
14
15 For example, a conventional feed-forward network may be structured
16 as follows:
17
18 I <-- simple input vector
19 |
20 D <-- dense feed-forward layer
21 |
22 O <-- output activation function
23
24 A graph is more flexible, allowing structures like the following:
25
26 I_s <-- sequential input
27 |
28 GRU I_v <-- simple input vector
29 \ /
30 M <-- merge layer
31 |
32 D <-- dense layer
33 / \
34 D2 D3
35 | |
36 | O_c <-- multiclass output (softmax activation)
37 |
38 O_r <-- regression output (linnear output)
39
40 i.e. a graph can combine any number of sequential and "standard"
41 rank-1 inputs, and can use the same internal features to infer many
42 different attributes from the input pattern.
43
44 Like the LightweightNeuralNetwork, it contains no Eigen code: it
45 only serves as a high-level wrapper to convert std::map objects to
46 Eigen objects and Eigen objects back to std::maps. For the
47 underlying implementation, see Graph.h. */
48
50
51namespace lwtDev {
52
53 class Graph;
56
57 // We currently allow several input types
58 // The "ValueMap" is for simple rank-1 inputs
59 typedef std::map<std::string, double> ValueMap;
60 // The "VectorMap" is for sequence inputs
61 typedef std::map<std::string, std::vector<double> > VectorMap;
62
63 // Graph class
65 {
66 public:
67 // Since a graph has multiple input nodes, we actually call
68 typedef std::map<std::string, ValueMap> NodeMap;
69 typedef std::map<std::string, VectorMap> SeqNodeMap;
70
71 // In cases where the graph has multiple outputs, we have to
72 // define a "default" output, so that calling "compute" with no
73 // output specified doesn't lead to ambiguity.
75 const std::string& default_output = "");
76
80
81 // The simpler "compute" function
82 ValueMap compute(const NodeMap&, const SeqNodeMap& = {}) const;
83
84 // More complicated version, only needed when you have multiple
85 // output nodes and need to specify the non-default ones
86 ValueMap compute(const NodeMap&, const SeqNodeMap&,
87 const std::string& output) const;
88
89 // The simpler "scan" function
90 VectorMap scan(const NodeMap&, const SeqNodeMap& = {}) const;
91
92 // More complicated version, only needed when you have multiple
93 // output nodes and need to specify the non-default ones
94 VectorMap scan(const NodeMap&, const SeqNodeMap&,
95 const std::string& output) const;
96
97 private:
100 typedef std::vector<std::pair<std::string, IP*> > Preprocs;
101 typedef std::vector<std::pair<std::string, IVP*> > VecPreprocs;
102
103 ValueMap compute(const NodeMap&, const SeqNodeMap&, size_t) const;
104 VectorMap scan(const NodeMap&, const SeqNodeMap&, size_t) const;
108 std::vector<std::pair<size_t, std::vector<std::string> > > m_outputs;
109 std::map<std::string, size_t> m_output_indices;
111 };
112}
113
114#endif
std::map< std::string, std::vector< double > > VectorMap
LightweightGraph & operator=(LightweightGraph &)=delete
LightweightGraph(LightweightGraph &)=delete
LightweightGraph(const GraphConfig &config, const std::string &default_output="")
std::vector< std::pair< std::string, IP * > > Preprocs
VectorMap scan(const NodeMap &, const SeqNodeMap &={}) const
std::map< std::string, ValueMap > NodeMap
std::map< std::string, size_t > m_output_indices
std::vector< std::pair< std::string, IVP * > > VecPreprocs
std::map< std::string, VectorMap > SeqNodeMap
ValueMap compute(const NodeMap &, const SeqNodeMap &={}) const
InputVectorPreprocessor IVP
std::vector< std::pair< size_t, std::vector< std::string > > > m_outputs
std::map< std::string, std::vector< double > > VectorMap
std::map< std::string, double > ValueMap
LightweightGraph::NodeMap NodeMap