Tenncor
|
Classes | |
struct | Conv |
Layer implementation to apply conv2d functions to weight and optional bias. More... | |
struct | ConvBuilder |
Builder implementation for convolution layer. More... | |
struct | Dense |
Layer implementation to apply fully_connect functions to weight and optional bias. More... | |
struct | DenseBuilder |
Builder implementation for fully connected layer. More... | |
struct | iLayer |
struct | iLayerBuilder |
struct | LayerId |
Sublayer type, label, and index encapsulation. More... | |
struct | LayerRegistry |
struct | LayerTag |
Tag implementation specifically for contents of layers. More... | |
struct | RBM |
struct | RBMBuilder |
Builder implementation for restricted boltzmann layer. More... | |
struct | SeqModelBuilder |
Builder implementation for sequentially connected models. More... | |
struct | SequentialModel |
Layer implementation that sequentially applies sublayers. More... | |
struct | ULayer |
Layer implementation to apply activation and pooling functions. More... | |
struct | ULayerBuilder |
Builder implementation for activation layer. More... | |
struct | VarAssign |
Variable and error approximation assignment encapsulation. More... | |
Typedefs | |
using | ConvptrT = std::shared_ptr< Conv > |
Smart pointer of convolutional layer. More... | |
using | DenseptrT = std::shared_ptr< Dense > |
Smart pointer of fully connected layer. More... | |
using | VarErrsT = std::vector< std::pair< eteq::VarptrT< PybindT >, NodeptrT > > |
Ordered association between variable and error. More... | |
using | AssignsT = std::vector< VarAssign > |
One batch of assignments. More... | |
using | AssignGroupsT = std::vector< AssignsT > |
All batches of assignments. More... | |
using | ApproxF = std::function< AssignGroupsT(const VarErrsT &)> |
using | UpdateStepF = std::function< void(teq::TensSetT &)> |
template<typename T > | |
using | InitF = std::function< eteq::VarptrT< T >(teq::Shape, std::string)> |
Function that produces a variable given the variable's shape and label. More... | |
template<typename T > | |
using | ShapeFactorF = std::function< T(teq::Shape)> |
Function that returns some metric of a shape. More... | |
using | LayerIdsT = std::vector< LayerId > |
Vector of sublayer ids. More... | |
using | LayerptrT = std::shared_ptr< iLayer > |
Smart pointer of layer. More... | |
using | LBuilderptrT = std::shared_ptr< iLayerBuilder > |
Layer builder smart pointer. More... | |
using | LayerBuildF = std::function< LBuilderptrT(std::string)> |
Function that takes layer type and returns associated layer builder. More... | |
using | RBMptrT = std::shared_ptr< RBM > |
Smart pointer of RBM layer. More... | |
using | SeqModelptrT = std::shared_ptr< SequentialModel > |
Smart pointer of sequentially connected model. More... | |
using | UnaryF = std::function< NodeptrT(const ULayer &, NodeptrT)> |
Function that takes corresponding unary layer and node. More... | |
using | UnaryptrT = std::shared_ptr< ULayer > |
Smart pointer of unary layer. More... | |
Functions | |
AssignGroupsT | sgd (const VarErrsT &leaves, PybindT learning_rate=0.5, std::string root_label="") |
AssignGroupsT | rms_momentum (const VarErrsT &leaves, PybindT learning_rate=0.5, PybindT discount_factor=0.99, PybindT epsilon=std::numeric_limits< PybindT >::epsilon(), std::string root_label="") |
void | assign_groups (const AssignGroupsT &groups, UpdateStepF update_step) |
Apply all batches of assignments with update_step applied after each batch. More... | |
void | assign_groups_preupdate (const AssignGroupsT &groups, UpdateStepF update_step) |
Apply all batches of assignments with update_step applied before each batch. More... | |
template<typename T > | |
T | fanio (teq::Shape shape) |
Return the sum of the first 2 dimensions of a shape. More... | |
template<typename T > | |
T | fanavg (teq::Shape shape) |
Return the mean of the first 2 dimensions of a shape. More... | |
template<typename T > | |
void | truncated_normal (std::vector< T > &out, teq::Shape shape, T mean, T stdev, size_t max_repick=5) |
template<typename T > | |
InitF< T > | zero_init (void) |
Return initialization function that makes zero variables. More... | |
template<typename T > | |
InitF< T > | variance_scaling_init (T factor, ShapeFactorF< T > sfactor=fanavg< T >) |
template<typename T > | |
InitF< T > | unif_xavier_init (T factor=1) |
template<typename T > | |
InitF< T > | norm_xavier_init (T factor=1) |
void | validate_label (const std::string &label) |
std::string | layer_label_fmt (std::string label, LayerId subid) |
Return formatted raw label with associated sublayer. More... | |
std::unordered_map< std::string, LayerIdsT > | unpack_labels (const std::vector< std::string > &labels) |
Return raw labels mapped to sublayers given a vector of formatted labels. More... | |
LayerRegistry & | get_layer_reg (void) |
Return global layer registry reference. More... | |
void | recursive_layer_tag (teq::TensptrT tens, std::string layer_type, std::string name, teq::TensSetT stops, LayerRegistry ®istry=get_layer_reg()) |
LayerptrT | load_layer (std::istream &ins, teq::TensptrsT &roots, std::string ltype, std::string label, LayerRegistry ®istry=get_layer_reg()) |
bool | save_layer (std::ostream &outs, const iLayer &layer, teq::TensptrsT roots, LayerRegistry ®istry=get_layer_reg()) |
NodeptrT | softmax_from_layer (const ULayer &layer, NodeptrT input) |
NodeptrT | maxpool_from_layer (const ULayer &layer, NodeptrT input) |
NodeptrT | meanpool_from_layer (const ULayer &layer, NodeptrT input) |
UnaryptrT | sigmoid (void) |
Return activation layer using sigmoid. More... | |
UnaryptrT | tanh (void) |
Return activation layer using tanh. More... | |
UnaryptrT | softmax (teq::RankT dim) |
Return activation layer using softmax of specified dimension. More... | |
UnaryptrT | maxpool2d (std::pair< teq::DimT, teq::DimT > dims={0, 1}) |
Return pooling layer using max aggregation. More... | |
UnaryptrT | meanpool2d (std::pair< teq::DimT, teq::DimT > dims={0, 1}) |
Return pooling layer using mean aggregation. More... | |
Variables | |
const std::string | conv_weight_key = "weight" |
Convolutional weight label. More... | |
const std::string | conv_bias_key = "bias" |
Convolutional bias label. More... | |
const std::string | conv_layer_key |
Identifier for convolutional layer. More... | |
const std::string | dense_weight_key = "weight" |
Fully connected weight label. More... | |
const std::string | dense_bias_key = "bias" |
Fully connected bias label. More... | |
const std::string | dense_layer_key |
Identifier for fully connected layer. More... | |
const std::string | layers_key_prefix = "layer_" |
String prefixed to every layer key. More... | |
const char | llabel_sep = ':' |
Layer label separator to divide each element in the LayerId. More... | |
const std::string | hidden_key = "hidden" |
Hidden fully connected layer label. More... | |
const std::string | visible_key = "visible" |
Visible fully connected layer label. More... | |
const std::string | rbm_layer_key |
Identifier for restricted boltzmann machine. More... | |
const std::string | seq_model_key |
Identifier for sequentially connected models. More... | |
const std::string | sigmoid_layer_key |
Identifier for sigmoid activation layer. More... | |
const std::string | tanh_layer_key |
Identifier for tanh activation layer. More... | |
const std::string | softmax_layer_key |
Identifier for softmax activation layer. More... | |
const std::string | maxpool2d_layer_key |
Identifier for max pooling layer. More... | |
const std::string | meanpool2d_layer_key |
Identifier for mean pooling layer. More... | |
const std::unordered_map< std::string, UnaryF > | unaries |
Map unary layer identifier to connection function. More... | |
err_approx.hpp layr
Purpose: Define error approximation algorithms and variable assignment utilities
init.hpp layr
Purpose: Define variable initialization algorithms
layer.hpp layr
Purpose: Define layer interface and tagging
seqmodel.hpp layr
Purpose: Implement sequentially connected model
ulayer.hpp layr
Purpose: Implement generic layer that applies unary functions these functions don't store any data
using layr::ApproxF = typedef std::function<AssignGroupsT(const VarErrsT&)> |
Function that approximate error of sources given a vector of variables and its corresponding errors
using layr::AssignGroupsT = typedef std::vector<AssignsT> |
All batches of assignments.
using layr::AssignsT = typedef std::vector<VarAssign> |
One batch of assignments.
using layr::ConvptrT = typedef std::shared_ptr<Conv> |
Smart pointer of convolutional layer.
using layr::DenseptrT = typedef std::shared_ptr<Dense> |
Smart pointer of fully connected layer.
using layr::InitF = typedef std::function<eteq::VarptrT<T>(teq::Shape,std::string)> |
Function that produces a variable given the variable's shape and label.
using layr::LayerBuildF = typedef std::function<LBuilderptrT(std::string)> |
Function that takes layer type and returns associated layer builder.
using layr::LayerIdsT = typedef std::vector<LayerId> |
Vector of sublayer ids.
using layr::LayerptrT = typedef std::shared_ptr<iLayer> |
Smart pointer of layer.
using layr::LBuilderptrT = typedef std::shared_ptr<iLayerBuilder> |
Layer builder smart pointer.
using layr::RBMptrT = typedef std::shared_ptr<RBM> |
Smart pointer of RBM layer.
using layr::SeqModelptrT = typedef std::shared_ptr<SequentialModel> |
Smart pointer of sequentially connected model.
using layr::ShapeFactorF = typedef std::function<T(teq::Shape)> |
Function that returns some metric of a shape.
using layr::UnaryF = typedef std::function<NodeptrT( const ULayer&,NodeptrT)> |
Function that takes corresponding unary layer and node.
using layr::UnaryptrT = typedef std::shared_ptr<ULayer> |
Smart pointer of unary layer.
using layr::UpdateStepF = typedef std::function<void(teq::TensSetT&)> |
Function that runs before or after variable assignment to calculate approximation graphs
using layr::VarErrsT = typedef std::vector<std::pair<eteq::VarptrT<PybindT>,NodeptrT> > |
Ordered association between variable and error.
void layr::assign_groups | ( | const AssignGroupsT & | groups, |
UpdateStepF | update_step | ||
) |
Apply all batches of assignments with update_step applied after each batch.
void layr::assign_groups_preupdate | ( | const AssignGroupsT & | groups, |
UpdateStepF | update_step | ||
) |
Apply all batches of assignments with update_step applied before each batch.
T layr::fanavg | ( | teq::Shape | shape | ) |
Return the mean of the first 2 dimensions of a shape.
T layr::fanio | ( | teq::Shape | shape | ) |
Return the sum of the first 2 dimensions of a shape.
LayerRegistry& layr::get_layer_reg | ( | void | ) |
Return global layer registry reference.
std::string layr::layer_label_fmt | ( | std::string | label, |
LayerId | subid | ||
) |
Return formatted raw label with associated sublayer.
LayerptrT layr::load_layer | ( | std::istream & | ins, |
teq::TensptrsT & | roots, | ||
std::string | ltype, | ||
std::string | label, | ||
LayerRegistry & | registry = get_layer_reg() |
||
) |
Return a rebuilt layer from protobuf in stream (ins) a bunch of subgraph roots and the output layer's type and label
Return pooling layer using max aggregation.
NodeptrT layr::maxpool_from_layer | ( | const ULayer & | layer, |
NodeptrT | input | ||
) |
Return pooling layer using mean aggregation.
NodeptrT layr::meanpool_from_layer | ( | const ULayer & | layer, |
NodeptrT | input | ||
) |
InitF<T> layr::norm_xavier_init | ( | T | factor = 1 | ) |
Return initialization function that makes xavier initialized variables (that uses gaussian distribution) (see https://andyljones.tumblr.com/post/110998971763/an-explanation-of-xavier-initialization)
void layr::recursive_layer_tag | ( | teq::TensptrT | tens, |
std::string | layer_type, | ||
std::string | name, | ||
teq::TensSetT | stops, | ||
LayerRegistry & | registry = get_layer_reg() |
||
) |
Recursively tag tensor subgraph with specified layer type, and label only ignoring subgraphs of tensors in stops set
AssignGroupsT layr::rms_momentum | ( | const VarErrsT & | leaves, |
PybindT | learning_rate = 0.5 , |
||
PybindT | discount_factor = 0.99 , |
||
PybindT | epsilon = std::numeric_limits<PybindT>::epsilon() , |
||
std::string | root_label = "" |
||
) |
Return all batches of variable assignments of momentum-based rms error approximation applied to particular variables-error associations
Momentum-based Root Mean Square Approximation for each (x, err) in leaves momentum_next ~ χ * momentum_cur + (1 - χ) * err ^ 2 x_next ~ x_curr - (η * err) / (sqrt(ε + momentum_next))
where η is the learning rate, ε is epsilon, and χ is discount_factor initial momentum is 1
bool layr::save_layer | ( | std::ostream & | outs, |
const iLayer & | layer, | ||
teq::TensptrsT | roots, | ||
LayerRegistry & | registry = get_layer_reg() |
||
) |
Return true if specified layer and root subgraphs are saved to protobuf out stream (outs)
AssignGroupsT layr::sgd | ( | const VarErrsT & | leaves, |
PybindT | learning_rate = 0.5 , |
||
std::string | root_label = "" |
||
) |
Return all batches of variable assignments of stochastic gradient descent error approximation applied to particular variables-error associations
Stochastic Gradient Descent Approximation for each (x, err) in leaves x_next ~ x_curr - η * err,
where η is the learning rate
UnaryptrT layr::sigmoid | ( | void | ) |
Return activation layer using sigmoid.
UnaryptrT layr::softmax | ( | teq::RankT | dim | ) |
Return activation layer using softmax of specified dimension.
NodeptrT layr::softmax_from_layer | ( | const ULayer & | layer, |
NodeptrT | input | ||
) |
Softmax layer connection function that extracts transformation parameter from layer and apply to input
UnaryptrT layr::tanh | ( | void | ) |
Return activation layer using tanh.
void layr::truncated_normal | ( | std::vector< T > & | out, |
teq::Shape | shape, | ||
T | mean, | ||
T | stdev, | ||
size_t | max_repick = 5 |
||
) |
Populate out vector with normally distributed values (using mean and stdev) except repick values if the value is not within 2 stdev of the mean
InitF<T> layr::unif_xavier_init | ( | T | factor = 1 | ) |
Return initialization function that makes xavier initialized variables (that uses uniform distribution) (see https://andyljones.tumblr.com/post/110998971763/an-explanation-of-xavier-initialization)
std::unordered_map<std::string,LayerIdsT> layr::unpack_labels | ( | const std::vector< std::string > & | labels | ) |
Return raw labels mapped to sublayers given a vector of formatted labels.
void layr::validate_label | ( | const std::string & | label | ) |
Check if the raw label does not contain llabel_sep as to not clash with LayerId representation
InitF<T> layr::variance_scaling_init | ( | T | factor, |
ShapeFactorF< T > | sfactor = fanavg<T> |
||
) |
Return initialization function that makes variance scaling variables (see https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/contrib/layers/variance_scaling_initializer)
InitF<T> layr::zero_init | ( | void | ) |
Return initialization function that makes zero variables.
const std::string layr::conv_bias_key = "bias" |
Convolutional bias label.
const std::string layr::conv_layer_key |
Identifier for convolutional layer.
const std::string layr::conv_weight_key = "weight" |
Convolutional weight label.
const std::string layr::dense_bias_key = "bias" |
Fully connected bias label.
const std::string layr::dense_layer_key |
Identifier for fully connected layer.
const std::string layr::dense_weight_key = "weight" |
Fully connected weight label.
const std::string layr::hidden_key = "hidden" |
Hidden fully connected layer label.
const std::string layr::layers_key_prefix = "layer_" |
String prefixed to every layer key.
const char layr::llabel_sep = ':' |
Layer label separator to divide each element in the LayerId.
const std::string layr::maxpool2d_layer_key |
Identifier for max pooling layer.
const std::string layr::meanpool2d_layer_key |
Identifier for mean pooling layer.
const std::string layr::rbm_layer_key |
Identifier for restricted boltzmann machine.
const std::string layr::seq_model_key |
Identifier for sequentially connected models.
const std::string layr::sigmoid_layer_key |
Identifier for sigmoid activation layer.
const std::string layr::softmax_layer_key |
Identifier for softmax activation layer.
const std::string layr::tanh_layer_key |
Identifier for tanh activation layer.
const std::unordered_map<std::string,UnaryF> layr::unaries |
Map unary layer identifier to connection function.
const std::string layr::visible_key = "visible" |
Visible fully connected layer label.