A singular Riemannian geometry approach to Deep Neural Networks.
Public Member Functions | Protected Attributes | List of all members
layer Class Referenceabstract

Generic layer class. More...

#include <layer.h>

Public Member Functions

 layer ()
 
 layer (const std::vector< std::vector< double >> &weights_, const std::vector< double > &biases_)
 
 layer (const std::vector< std::vector< double >> &weights_)
 
 layer (const Eigen::MatrixXd &weights_)
 
 layer (const Eigen::MatrixXd &weights_, const std::vector< double > &biases_)
 
 layer (const Eigen::MatrixXd &weights_, const Eigen::VectorXd &biases_)
 
 layer (const Eigen::MatrixXd &weights_, const Eigen::VectorXd &biases_, int in_dim, int out_dim)
 
virtual ~layer ()
 
virtual Eigen::VectorXd predict (const Eigen::VectorXd &input)
 
virtual std::vector< Eigen::VectorXd > predict_batch (const std::vector< Eigen::VectorXd > &input)
 
const Eigen::VectorXd get_biases ()
 
const Eigen::MatrixXd get_weights ()
 
const Eigen::MatrixXd get_weights_biases_as_mat ()
 
const Eigen::MatrixXd get_weights_biases_as_vec_col_maj ()
 
const Eigen::MatrixXd get_weights_biases_as_vec_row_maj ()
 
double get_weight (int i, int j)
 
double get_bias (int i)
 
void set_biases (const Eigen::VectorXd &biases_)
 
void set_biases (const std::vector< double > &biases_)
 
void set_weights (const Eigen::MatrixXd &weights_)
 
void set_weight (int i, int j, double weight_)
 
void set_bias (int i, double bias_)
 
void set_weights_biases_compact (Eigen::MatrixXd &source)
 
void set_weights_biases (Eigen::MatrixXd &source)
 
void set_weights_biases_row_maj (Eigen::MatrixXd &source)
 
int get_num_nodes ()
 
int get_input_size ()
 
int get_weights_rows ()
 
int get_weights_cols ()
 
std::string get_type ()
 
virtual Eigen::MatrixXd compute_partial_derivatives_wrt_inputs (Eigen::VectorXd &input)=0
 
virtual Eigen::MatrixXd compute_partial_derivatives_wrt_weights_biases (Eigen::VectorXd &input)=0
 
void transpose_weights ()
 
void set_exp_max_cut (double exp_max_cut_)
 
void set_exp_zero_approx (double exp_zero_approx_)
 
double get_exp_max_cut ()
 
double get_exp_zero_approx ()
 

Protected Attributes

Eigen::VectorXd biases
 
Eigen::MatrixXd weights
 
int weights_rows = 0
 
int input_dim = 0
 
int output_dim = 0
 
int weights_cols = 0
 
std::string type
 
double exp_max_cut = 50.
 
double exp_zero_approx = 1.92874984e-22
 

Detailed Description

Generic layer class.

The class layer is an abstract class to be used to realize different kind of layers.

Constructor & Destructor Documentation

◆ layer() [1/7]

layer::layer ( )
inline

Default constructor.

◆ layer() [2/7]

layer::layer ( const std::vector< std::vector< double >> &  weights_,
const std::vector< double > &  biases_ 
)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ layer() [3/7]

layer::layer ( const std::vector< std::vector< double >> &  weights_)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ layer() [4/7]

layer::layer ( const Eigen::MatrixXd &  weights_)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ layer() [5/7]

layer::layer ( const Eigen::MatrixXd &  weights_,
const std::vector< double > &  biases_ 
)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ layer() [6/7]

layer::layer ( const Eigen::MatrixXd &  weights_,
const Eigen::VectorXd &  biases_ 
)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ layer() [7/7]

layer::layer ( const Eigen::MatrixXd &  weights_,
const Eigen::VectorXd &  biases_,
int  in_dim,
int  out_dim 
)

Initializes a generic layer given a matrix of weights and a vector of biases.

◆ ~layer()

virtual layer::~layer ( )
inlinevirtual

Default deconstructor.

Member Function Documentation

◆ compute_partial_derivatives_wrt_inputs()

virtual Eigen::MatrixXd layer::compute_partial_derivatives_wrt_inputs ( Eigen::VectorXd &  input)
pure virtual

Computes the Jacobian matrix with respect to the input variables. The Jacobian is computer in reduced form.

Implemented in fc_layer_sg, fc_layer_sl, fc_layer_sm, and fc_layer_sp.

◆ compute_partial_derivatives_wrt_weights_biases()

virtual Eigen::MatrixXd layer::compute_partial_derivatives_wrt_weights_biases ( Eigen::VectorXd &  input)
pure virtual

Computes the Jacobian matrix with respect to weights and biases.

Implemented in fc_layer_sg, fc_layer_sl, fc_layer_sm, and fc_layer_sp.

◆ get_bias()

double layer::get_bias ( int  i)

Returns the bias of the i-th node.

◆ get_biases()

const Eigen::VectorXd layer::get_biases ( )

Returns the biases of the layer.

◆ get_exp_max_cut()

double layer::get_exp_max_cut ( )

Returns the parameter exp_max_cut, controlling the approximations of \( f(x) = e^{-x} \) and \( f(x) = ln(1+e^{x}) \) for large values of the argument \( x \).

◆ get_exp_zero_approx()

double layer::get_exp_zero_approx ( )

Returns the parameter exp_zero_approx, approximating \( f(x) = e^{-x} \) for large values of the argument \( x \).

◆ get_input_size()

int layer::get_input_size ( )

Returns the dimension of the input space of the layer.

◆ get_num_nodes()

int layer::get_num_nodes ( )

Returns the number of nodes of the layer.

◆ get_type()

std::string layer::get_type ( )

Returns the type of the layer.

◆ get_weight()

double layer::get_weight ( int  i,
int  j 
)

Returns the (i-th,j-th) entry of the matrix of weights.

◆ get_weights()

const Eigen::MatrixXd layer::get_weights ( )

Returns the weights of the layer.

◆ get_weights_biases_as_mat()

const Eigen::MatrixXd layer::get_weights_biases_as_mat ( )

Returns the weights and the biases of the layers in a matrix whose last column is the vector of the biases.

◆ get_weights_biases_as_vec_col_maj()

const Eigen::MatrixXd layer::get_weights_biases_as_vec_col_maj ( )

Returns the weights and the biases of the layers as a column vector. The order is the following: Weights of the first node, bias of the first node, weights of the first node, bias of the second node, etc.

◆ get_weights_biases_as_vec_row_maj()

const Eigen::MatrixXd layer::get_weights_biases_as_vec_row_maj ( )

Returns the weights and the biases of the layers as a row vector. The order is the following: Weights of the first node, bias of the first node, weights of the first node, bias of the second node, etc.

◆ get_weights_cols()

int layer::get_weights_cols ( )

Returns the number of columns of the weights matrix.

◆ get_weights_rows()

int layer::get_weights_rows ( )

Returns the number of rows of the weights matrix.

◆ predict()

virtual Eigen::VectorXd layer::predict ( const Eigen::VectorXd &  input)
inlinevirtual

Computes the output of the layer given an Eigen::VectorXd as input.

Reimplemented in fc_layer_sg, fc_layer_sl, fc_layer_sp, and fc_layer_sm.

◆ predict_batch()

virtual std::vector<Eigen::VectorXd> layer::predict_batch ( const std::vector< Eigen::VectorXd > &  input)
inlinevirtual

Computes the outputs of the layer given a vector<Eigen::VectorXd> as input.

Reimplemented in fc_layer_sg, fc_layer_sl, and fc_layer_sp.

◆ set_bias()

void layer::set_bias ( int  i,
double  bias_ 
)

Sets the bias of the i-th node.

◆ set_biases() [1/2]

void layer::set_biases ( const Eigen::VectorXd &  biases_)

Sets the biases of the layer.

◆ set_biases() [2/2]

void layer::set_biases ( const std::vector< double > &  biases_)

Sets the biases of the layer.

◆ set_exp_max_cut()

void layer::set_exp_max_cut ( double  exp_max_cut_)

Set the exp_max_cut parameter to approximate \( f(x) = e^{-x} \) and \( f(x) = ln(1+e^{x}) \) for large values of the argument \( x \).

  • For \( x \) above exp_max_cut approximates \( f(x) = e^{-x} \) with exp_zero_approx.
  • For \( x \) above exp_max_cut approximates \( f(x) = ln(1+e^{x}) \) with \( x \).

◆ set_exp_zero_approx()

void layer::set_exp_zero_approx ( double  exp_zero_approx_)

Set the exp_zero_approx parameter to approximate \( f(x) = e^{-x} \) and \( f(x) = ln(1+e^{x}) \) for large values of the argument \( x \).

  • For \( x \) above exp_max_cut approximates \( f(x) = e^{-x} \) with exp_zero_approx.
  • For \( x \) above exp_max_cut approximates \( f(x) = ln(1+e^{x}) \) with \( x \).

◆ set_weight()

void layer::set_weight ( int  i,
int  j,
double  weight_ 
)

Sets the (i-th,j-th) weight of the layer.

◆ set_weights()

void layer::set_weights ( const Eigen::MatrixXd &  weights_)

Sets the weights of the layer.

◆ set_weights_biases()

void layer::set_weights_biases ( Eigen::MatrixXd &  source)

Sets the weights and the biases of the layer. The entries of the input (1 x N) matrix is the following: Weights of the first node, bias of the first node, weights of the first node, bias of the second node, etc.

◆ set_weights_biases_compact()

void layer::set_weights_biases_compact ( Eigen::MatrixXd &  source)

Sets the weights and the biases of the layer, passing a matrix whose last column is the vector of the biases.

◆ set_weights_biases_row_maj()

void layer::set_weights_biases_row_maj ( Eigen::MatrixXd &  source)

Sets the weights and the biases of the layer. The entries of the input (1 x N) matrix is the following: Weights of the first node, bias of the first node, weights of the first node, bias of the second node, etc.

◆ transpose_weights()

void layer::transpose_weights ( )

Transposes the weights matrix of the layer.


The documentation for this class was generated from the following files: