ATLAS Offline Software
Classes | Typedefs | Enumerations | Functions
lwtDev Namespace Reference

Classes

struct  ActivationConfig
 
class  BiasLayer
 
class  BidirectionalLayer
 bidirectional unit /// More...
 
class  ConcatenateNode
 
struct  DenseComponents
 
class  DummyLayer
 
class  DummySource
 
class  ELU
 
struct  EmbeddingConfig
 
class  EmbeddingLayer
 
class  FeedForwardNode
 
class  Graph
 
struct  GraphConfig
 
class  GRULayer
 
struct  GRUState
 
class  HighwayLayer
 
class  ILayer
 
class  INode
 
struct  Input
 
class  InputNode
 
struct  InputNodeConfig
 
class  InputPreprocessor
 
class  InputSequenceNode
 
class  InputVectorPreprocessor
 
class  IRecurrentLayer
 
class  ISequenceNode
 
class  ISource
 
struct  JSONConfig
 
struct  LayerConfig
 
class  LeakyReLU
 
class  LightweightGraph
 
class  LightweightNNException
 
class  LSTMLayer
 
struct  LSTMState
 
class  MatrixLayer
 
class  MaxoutLayer
 
class  NNConfigurationException
 
class  NNEvaluationException
 
struct  NodeConfig
 
class  NormalizationLayer
 Normalization layer /// https://arxiv.org/abs/1502.03167 ///. More...
 
struct  OutputNodeConfig
 
class  OutputRankException
 
class  RecurrentStack
 
class  ReductionStack
 
class  SequenceNode
 
class  SoftmaxLayer
 
class  Stack
 
class  SumNode
 
class  Swish
 
class  TimeDistributedNode
 
class  UnaryActivationLayer
 
class  VectorSource
 

Typedefs

typedef LightweightGraph::NodeMap NodeMap
 
typedef std::map< std::string, double > ValueMap
 
typedef std::vector< std::pair< std::string, double > > ValueVector
 
typedef std::map< std::string, std::vector< double > > VectorMap
 

Enumerations

enum  Activation {
  Activation::NONE, Activation::LINEAR, Activation::SIGMOID, Activation::RECTIFIED,
  Activation::SOFTMAX, Activation::TANH, Activation::HARD_SIGMOID, Activation::ELU,
  Activation::LEAKY_RELU, Activation::SWISH, Activation::ABS
}
 
enum  Architecture {
  Architecture::NONE, Architecture::DENSE, Architecture::NORMALIZATION, Architecture::MAXOUT,
  Architecture::HIGHWAY, Architecture::LSTM, Architecture::GRU, Architecture::BIDIRECTIONAL,
  Architecture::EMBEDDING
}
 
enum  Component {
  Component::I, Component::O, Component::C, Component::F,
  Component::Z, Component::R, Component::H, Component::T,
  Component::CARRY
}
 

Functions

JSONConfig parse_json (std::istream &json)
 
GraphConfig parse_json_graph (std::istream &json)
 
ILayerget_raw_activation_layer (ActivationConfig activation)
 
std::function< double(double)> get_activation (lwtDev::ActivationConfig act)
 
double nn_sigmoid (double x)
 
double nn_hard_sigmoid (double x)
 
double nn_tanh (double x)
 
double nn_relu (double x)
 
MatrixXd build_matrix (const std::vector< double > &weights, size_t n_inputs)
 
VectorXd build_vector (const std::vector< double > &bias)
 
void throw_if_not_maxout (const LayerConfig &layer)
 
void throw_if_not_dense (const LayerConfig &layer)
 
void throw_if_not_normalization (const LayerConfig &layer)
 
DenseComponents get_component (const lwtDev::LayerConfig &layer, size_t n_in)
 

Typedef Documentation

◆ NodeMap

Definition at line 67 of file LightweightGraph.cxx.

◆ ValueMap

typedef std::map< std::string, double > lwtDev::ValueMap

Definition at line 22 of file InputPreprocessor.h.

◆ ValueVector

typedef std::vector<std::pair<std::string, double> > lwtDev::ValueVector

Definition at line 23 of file InputPreprocessor.h.

◆ VectorMap

typedef std::map< std::string, std::vector< double > > lwtDev::VectorMap

Definition at line 24 of file InputPreprocessor.h.

Enumeration Type Documentation

◆ Activation

enum lwtDev::Activation
strong
Enumerator
NONE 
LINEAR 
SIGMOID 
RECTIFIED 
SOFTMAX 
TANH 
HARD_SIGMOID 
ELU 
LEAKY_RELU 
SWISH 
ABS 

Definition at line 20 of file NNLayerConfig.h.

◆ Architecture

enum lwtDev::Architecture
strong
Enumerator
NONE 
DENSE 
NORMALIZATION 
MAXOUT 
HIGHWAY 
LSTM 
GRU 
BIDIRECTIONAL 
EMBEDDING 

Definition at line 22 of file NNLayerConfig.h.

◆ Component

enum lwtDev::Component
strong
Enumerator
CARRY 

Definition at line 25 of file NNLayerConfig.h.

25  {
26  I, O, C, F, // LSTM
27  Z, R, H, // GRU
28  T, CARRY}; // Highway

Function Documentation

◆ build_matrix()

MatrixXd lwtDev::build_matrix ( const std::vector< double > &  weights,
size_t  n_inputs 
)

Definition at line 741 of file Stack.cxx.

742  {
743  size_t n_elements = weights.size();
744  if ((n_elements % n_inputs) != 0) {
745  std::string problem = "matrix elements not divisible by number"
746  " of columns. Elements: " + std::to_string(n_elements) +
747  ", Inputs: " + std::to_string(n_inputs);
748  throw lwtDev::NNConfigurationException(problem);
749  }
750  size_t n_outputs = n_elements / n_inputs;
751  MatrixXd matrix(n_outputs, n_inputs);
752  for (size_t row = 0; row < n_outputs; row++) {
753  for (size_t col = 0; col < n_inputs; col++) {
754  double element = weights.at(col + row * n_inputs);
755  matrix(row, col) = element;
756  }
757  }
758  return matrix;
759  }

◆ build_vector()

VectorXd lwtDev::build_vector ( const std::vector< double > &  bias)

Definition at line 760 of file Stack.cxx.

760  {
761  VectorXd out(bias.size());
762  size_t idx = 0;
763  for (const auto& val: bias) {
764  out(idx) = val;
765  idx++;
766  }
767  return out;
768  }

◆ get_activation()

std::function< double(double)> lwtDev::get_activation ( lwtDev::ActivationConfig  act)

Definition at line 671 of file Stack.cxx.

671  {
672  using namespace lwtDev;
673  switch (act.function) {
674  case Activation::SIGMOID: return nn_sigmoid;
676  case Activation::SWISH: return Swish(act.alpha);
677  case Activation::TANH: return nn_tanh;
678  case Activation::RECTIFIED: return nn_relu;
679  case Activation::ELU: return ELU(act.alpha);
680  case Activation::LEAKY_RELU: return LeakyReLU(act.alpha);
681  case Activation::LINEAR: return [](double x){return x;};
682  case Activation::ABS: return [](double x){return std::abs(x);};
683  default: {
684  throw NNConfigurationException("Got undefined activation function");
685  }
686  }
687  }

◆ get_component()

DenseComponents lwtDev::get_component ( const lwtDev::LayerConfig layer,
size_t  n_in 
)

Definition at line 792 of file Stack.cxx.

792  {
793  using namespace Eigen;
794  using namespace lwtDev;
795  MatrixXd weights = build_matrix(layer.weights, n_in);
796  size_t n_out = weights.rows();
797  VectorXd bias = build_vector(layer.bias);
798 
799  // the u element is optional
800  size_t u_el = layer.U.size();
801  MatrixXd U = u_el ? build_matrix(layer.U, n_out) : MatrixXd::Zero(0,0);
802 
803  size_t u_out = U.rows();
804  size_t b_out = bias.rows();
805  bool u_mismatch = (u_out != n_out) && (u_out > 0);
806  if ( u_mismatch || b_out != n_out) {
808  "Output dims mismatch, W: " + std::to_string(n_out) +
809  ", U: " + std::to_string(u_out) + ", b: " + std::to_string(b_out));
810  }
811  return {weights, U, bias};
812  }

◆ get_raw_activation_layer()

ILayer * lwtDev::get_raw_activation_layer ( ActivationConfig  activation)

Definition at line 661 of file Stack.cxx.

661  {
662  // Check for special cases. If it's not one, use
663  // UnaryActivationLayer
664  switch (activation.function) {
665  case Activation::SOFTMAX: return new SoftmaxLayer;
666  default: return new UnaryActivationLayer(activation);
667  }
668  }

◆ nn_hard_sigmoid()

double lwtDev::nn_hard_sigmoid ( double  x)

Definition at line 697 of file Stack.cxx.

697  {
698  //github.com/Theano/Theano/blob/master/theano/tensor/nnet/sigm.py#L279
699  double out = 0.2*x + 0.5;
700  if (out < 0) return 0.0;
701  if (out > 1) return 1.0;
702  return out;
703  }

◆ nn_relu()

double lwtDev::nn_relu ( double  x)

Definition at line 716 of file Stack.cxx.

716  {
717  if (std::isnan(x)) return x;
718  else return x > 0 ? x : 0;
719  }

◆ nn_sigmoid()

double lwtDev::nn_sigmoid ( double  x)

Definition at line 690 of file Stack.cxx.

690  {
691  //github.com/Theano/Theano/blob/master/theano/tensor/nnet/sigm.py#L35
692  if (x < -30.0) return 0.0;
693  if (x > 30.0) return 1.0;
694  return 1.0 / (1.0 + std::exp(-1.0*x));
695  }

◆ nn_tanh()

double lwtDev::nn_tanh ( double  x)

Definition at line 712 of file Stack.cxx.

712  {
713  return std::tanh(x);
714  }

◆ parse_json()

JSONConfig lwtDev::parse_json ( std::istream &  json)

Definition at line 42 of file parse_json.cxx.

43  {
45  boost::property_tree::read_json(json, pt);
46 
48  for (const auto& v: pt.get_child("inputs")) {
49  cfg.inputs.push_back(get_input(v));
50  }
51  for (const auto& v: pt.get_child("layers")) {
52  cfg.layers.push_back(get_layer(v));
53  }
54  for (const auto& v: pt.get_child("outputs"))
55  {
56  assert(v.first.empty()); // array elements have no names
57  cfg.outputs.push_back(v.second.data());
58  }
59  cfg.defaults = get_defaults(pt);
60  const std::string mname = "miscellaneous";
61  if (pt.count(mname)) {
62  for (const auto& misc: pt.get_child(mname)) {
63  cfg.miscellaneous.emplace(
64  misc.first, misc.second.get_value<std::string>());
65  }
66  }
67  return cfg;
68  }

◆ parse_json_graph()

GraphConfig lwtDev::parse_json_graph ( std::istream &  json)

Definition at line 71 of file parse_json.cxx.

71  {
73  boost::property_tree::read_json(json, pt);
74 
76  for (const auto& v: pt.get_child("inputs")) {
77  cfg.inputs.push_back(get_input_node(v));
78  }
79  for (const auto& v: pt.get_child("input_sequences")) {
80  cfg.input_sequences.push_back(get_input_node(v));
81  }
82  for (const auto& v: pt.get_child("nodes")) {
83  cfg.nodes.push_back(get_node(v));
84  }
85  for (const auto& v: pt.get_child("layers")) {
86  cfg.layers.push_back(get_layer(v));
87  }
88  for (const auto& v: pt.get_child("outputs")) {
89  cfg.outputs.emplace(v.first, get_output_node(v));
90  }
91  return cfg;
92  }

◆ throw_if_not_dense()

void lwtDev::throw_if_not_dense ( const LayerConfig layer)

Definition at line 779 of file Stack.cxx.

779  {
780  if (layer.sublayers.size() > 0) {
781  throw NNConfigurationException("sublayers in dense layer");
782  }
783  }

◆ throw_if_not_maxout()

void lwtDev::throw_if_not_maxout ( const LayerConfig layer)

Definition at line 771 of file Stack.cxx.

771  {
772  bool wt_ok = layer.weights.size() == 0;
773  bool bias_ok = layer.bias.size() == 0;
774  bool maxout_ok = layer.sublayers.size() > 0;
775  bool act_ok = layer.activation.function == Activation::NONE;
776  if (wt_ok && bias_ok && maxout_ok && act_ok) return;
777  throw NNConfigurationException("layer has wrong info for maxout");
778  }

◆ throw_if_not_normalization()

void lwtDev::throw_if_not_normalization ( const LayerConfig layer)

Definition at line 785 of file Stack.cxx.

785  {
786  if (layer.sublayers.size() > 0) {
787  throw NNConfigurationException("sublayers in normalization layer");
788  }
789  }
NONE
@ NONE
Definition: sTGCenumeration.h:13
lwtDev::Architecture::DENSE
@ DENSE
query_example.row
row
Definition: query_example.py:24
lwtDev::Activation::LINEAR
@ LINEAR
lwtDev::Activation::RECTIFIED
@ RECTIFIED
lwtDev::ActivationConfig::alpha
double alpha
Definition: NNLayerConfig.h:41
lwtDev::build_matrix
MatrixXd build_matrix(const std::vector< double > &weights, size_t n_inputs)
Definition: Stack.cxx:741
lwtDev::Activation::LEAKY_RELU
@ LEAKY_RELU
lwtDev::nn_sigmoid
double nn_sigmoid(double x)
Definition: Stack.cxx:690
json
nlohmann::json json
Definition: HistogramDef.cxx:9
Monitored::Z
@ Z
Definition: HistogramFillerUtils.h:24
DMTest::C
C_v1 C
Definition: C.h:26
lwtDev::Architecture::LSTM
@ LSTM
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
lwtDev::ActivationConfig::function
Activation function
Definition: NNLayerConfig.h:40
lwtDev::nn_relu
double nn_relu(double x)
Definition: Stack.cxx:716
python.TrigValSteering.Input.get_input
def get_input(keyword)
Definition: Input.py:96
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
x
#define x
lwtDev::Activation::TANH
@ TANH
lwtDev::NNConfigurationException
Definition: Reconstruction/tauRecTools/tauRecTools/lwtnn/Exceptions.h:21
lwtDev::Component::O
@ O
H
#define H(x, y, z)
Definition: MD5.cxx:114
lwtDev::nn_hard_sigmoid
double nn_hard_sigmoid(double x)
Definition: Stack.cxx:697
lwtDev::Activation::SWISH
@ SWISH
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
lwtDev::LeakyReLU
Definition: Stack.h:346
lwtDev::Activation::ELU
@ ELU
AnalysisUtils::Delta::R
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
Definition: AnalysisMisc.h:49
lwtDev::build_vector
VectorXd build_vector(const std::vector< double > &bias)
Definition: Stack.cxx:760
lwtDev::Architecture::MAXOUT
@ MAXOUT
lwtDev::Architecture::HIGHWAY
@ HIGHWAY
lwtDev::Activation::ABS
@ ABS
lwtDev::nn_tanh
double nn_tanh(double x)
Definition: Stack.cxx:712
lwtDev
Definition: Reconstruction/tauRecTools/Root/lwtnn/Exceptions.cxx:8
ptree
boost::property_tree::ptree ptree
Definition: JsonFileLoader.cxx:16
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
weights
Definition: herwig7_interface.h:44
lwtDev::SoftmaxLayer
Definition: Stack.h:101
query_example.col
col
Definition: query_example.py:7
python.PyAthena.v
v
Definition: PyAthena.py:154
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
lwtDev::Architecture::GRU
@ GRU
lwtDev::Architecture::BIDIRECTIONAL
@ BIDIRECTIONAL
lwtDev::Activation::HARD_SIGMOID
@ HARD_SIGMOID
lwtDev::Swish
Definition: Stack.h:354
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
F
#define F(x, y, z)
Definition: MD5.cxx:112
lwtDev::Activation::SIGMOID
@ SIGMOID
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
lwtDev::UnaryActivationLayer
Definition: Stack.h:92
lwtDev::Architecture::EMBEDDING
@ EMBEDDING
lwtDev::ELU
Definition: Stack.h:338
I
#define I(x, y, z)
Definition: MD5.cxx:116
lwtDev::Component::CARRY
@ CARRY
lwtDev::Architecture::NORMALIZATION
@ NORMALIZATION
lwtDev::GraphConfig
Definition: lightweight_network_config.h:58
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
lwtDev::JSONConfig
Definition: lightweight_network_config.h:36
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
lwtDev::Activation::SOFTMAX
@ SOFTMAX
COOLRates.LINEAR
LINEAR
Definition: COOLRates.py:1245