ATLAS Offline Software
Loading...
Searching...
No Matches
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 class  Activation {
  NONE , LINEAR , SIGMOID , RECTIFIED ,
  SOFTMAX , TANH , HARD_SIGMOID , ELU ,
  LEAKY_RELU , SWISH , ABS
}
enum class  Architecture {
  NONE , DENSE , NORMALIZATION , MAXOUT ,
  HIGHWAY , LSTM , GRU , BIDIRECTIONAL ,
  EMBEDDING
}
enum class  Component {
  I , O , C , F ,
  Z , R , H , T ,
  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

◆ 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 class 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 class lwtDev::Architecture
strong
Enumerator
NONE 
DENSE 
NORMALIZATION 
MAXOUT 
HIGHWAY 
LSTM 
GRU 
BIDIRECTIONAL 
EMBEDDING 

Definition at line 22 of file NNLayerConfig.h.

◆ Component

enum class 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
#define F(x, y, z)
Definition MD5.cxx:112
#define I(x, y, z)
Definition MD5.cxx:116
#define H(x, y, z)
Definition MD5.cxx:114
struct color C
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
unsigned long long T

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);
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 }
#define x
double nn_sigmoid(double x)
Definition Stack.cxx:690
double nn_hard_sigmoid(double x)
Definition Stack.cxx:697
double nn_relu(double x)
Definition Stack.cxx:716
double nn_tanh(double x)
Definition Stack.cxx:712

◆ 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 {std::move(weights), std::move(U), std::move(bias)};
812 }
MatrixXd build_matrix(const std::vector< double > &weights, size_t n_inputs)
Definition Stack.cxx:741
VectorXd build_vector(const std::vector< double > &bias)
Definition Stack.cxx:760

◆ 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 {
44 boost::property_tree::ptree pt;
45 boost::property_tree::read_json(json, pt);
46
47 JSONConfig cfg;
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 }
nlohmann::json json

◆ parse_json_graph()

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

Definition at line 71 of file parse_json.cxx.

71 {
72 boost::property_tree::ptree pt;
73 boost::property_tree::read_json(json, pt);
74
75 GraphConfig cfg;
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 }
OutputNodeConfig get_output_node(const nlohmann::json &v)

◆ 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 }