A singular Riemannian geometry approach to Deep Neural Networks.
Public Member Functions | List of all members
neural_network Class Reference

#include <neural_network.h>

Public Member Functions

 neural_network ()
 
 neural_network (const std::vector< layer * > &ls)
 
 ~neural_network ()
 
int get_num_layers ()
 
void print_network_info ()
 
void print_network_detailed_info ()
 
Eigen::VectorXd predict (const Eigen::VectorXd &input)
 
Eigen::VectorXd predict_to_layer (int tolayer, const Eigen::VectorXd &input)
 
std::vector< Eigen::VectorXd > predict (const std::vector< Eigen::VectorXd > &input)
 
std::vector< Eigen::VectorXd > predict_to_layer (int tolayer, const std::vector< Eigen::VectorXd > &input)
 
void network_read (const std::string &filename)
 
void network_save (const std::string &filename)
 
void add_layer_all_parameters (int wrows, int wcols, int in_dim, int out_dim, std::string type)
 
void add_fc_input_layer (int in_dim, int out_dim, std::string type)
 
void add_fc_hidden_layer (int out_dim, std::string type)
 
void set_layer_weights (int num_layer, Eigen::MatrixXd &weights_)
 
void set_layer_biases (int num_layer, Eigen::VectorXd &biases_)
 
Eigen::MatrixXd get_layer_weights (int num_layer)
 
Eigen::VectorXd get_layer_biases (int num_layer)
 
double loss_mse (const std::vector< Eigen::VectorXd > &data, const std::vector< Eigen::VectorXd > &features)
 
double accuracy (const std::vector< Eigen::VectorXd > &data, const std::vector< Eigen::VectorXd > &features)
 
void SiMEC_1D (std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint)
 
void SiMEC_1D_norm_proj (std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint, Eigen::VectorXd &H_inf, Eigen::VectorXd &H_sup)
 
void SiMEC_1D_stop_boundary (std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint, Eigen::VectorXd &H_inf, Eigen::VectorXd &H_sup)
 
void SiMExp_1D (std::string output_file, double delta, double epsilon, int max_steps, bool invert_build, Eigen::VectorXd &ipoint)
 
void ClassChange_1D (std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint)
 
layerget_layer (int n)
 

Detailed Description

Neural network class.

Constructor & Destructor Documentation

◆ neural_network() [1/2]

neural_network::neural_network ( )
inline

Default constructor.

◆ neural_network() [2/2]

neural_network::neural_network ( const std::vector< layer * > &  ls)

Builds a neural network given a vectors of pointers to layers.

◆ ~neural_network()

neural_network::~neural_network ( )
inline

Default deconstructor

Member Function Documentation

◆ add_fc_hidden_layer()

void neural_network::add_fc_hidden_layer ( int  out_dim,
std::string  type 
)

Adds an hidden layer of a fully-connected feedforward layer to the neural network. Arguments:

  • in_dim: dimension of the input space of the layer.
  • out_dim: dimension of the output space of the layer.
  • type: type of layer.

Note: The last hidden layer built invoking this method is the final layer of the network.

◆ add_fc_input_layer()

void neural_network::add_fc_input_layer ( int  in_dim,
int  out_dim,
std::string  type 
)

Builds the input layer of a fully-connected feedforward layer to the neural network. Arguments:

  • in_dim: dimension of the input space of the layer.
  • out_dim: dimension of the output space of the layer.
  • type: type of layer.

◆ add_layer_all_parameters()

void neural_network::add_layer_all_parameters ( int  wrows,
int  wcols,
int  in_dim,
int  out_dim,
std::string  type 
)

Append a layer to the neural network. Arguments:

  • wrows: Number of rows of the weights matrix.
  • wcols: Number of columns of the weights matrix.
  • in_dim: dimension of the input space of the layer.
  • out_dim: dimension of the output space of the layer.
  • type: type of layer.

Note: For feedforward layers wrows = in_dim and wcols = out_dim.

◆ ClassChange_1D()

void neural_network::ClassChange_1D ( std::string  output_file,
int  steps,
double  delta,
bool  invert_build,
Eigen::VectorXd  ipoint 
)

Starting from a point, proceed along the curve which change the output of the network the most. Instead of this method, use SiMExp_1D, which avoids infinite loop by coinstruction.

◆ get_layer_biases()

Eigen::VectorXd neural_network::get_layer_biases ( int  num_layer)

Returns a copy of the biases vector of a given layer.

◆ get_layer_weights()

Eigen::MatrixXd neural_network::get_layer_weights ( int  num_layer)

Returns a copy of the weights matrix of a given layer.

◆ get_num_layers()

int neural_network::get_num_layers ( )

Returns the number of layers of the neural network.

◆ network_read()

void neural_network::network_read ( const std::string &  filename)

Reads network from file

◆ network_save()

void neural_network::network_save ( const std::string &  filename)

Saves network to file

◆ predict() [1/2]

Eigen::VectorXd neural_network::predict ( const Eigen::VectorXd &  input)

Computes the output of the neural network for a given input.

◆ predict() [2/2]

std::vector< Eigen::VectorXd > neural_network::predict ( const std::vector< Eigen::VectorXd > &  input)

Computes the outputs of the neural network for a given vector of inputs.

◆ predict_to_layer() [1/2]

Eigen::VectorXd neural_network::predict_to_layer ( int  tolayer,
const Eigen::VectorXd &  input 
)

Computes the output of the subnetwork up to a specified layer for a given input.

◆ predict_to_layer() [2/2]

std::vector< Eigen::VectorXd > neural_network::predict_to_layer ( int  tolayer,
const std::vector< Eigen::VectorXd > &  input 
)

Computes the outputs of the subnetwork up to a specified layer for a given vector of inputs.

◆ print_network_detailed_info()

void neural_network::print_network_detailed_info ( )

Prints detailed info about the neural network.

◆ print_network_info()

void neural_network::print_network_info ( )

Prints info about the neural network.

◆ set_layer_biases()

void neural_network::set_layer_biases ( int  num_layer,
Eigen::VectorXd &  biases_ 
)

Sets the biases of a given layer given a vector in input.

◆ set_layer_weights()

void neural_network::set_layer_weights ( int  num_layer,
Eigen::MatrixXd &  weights_ 
)

Sets the weights of a given layer given a matrix in input.

◆ SiMEC_1D()

void neural_network::SiMEC_1D ( std::string  output_file,
int  steps,
double  delta,
bool  invert_build,
Eigen::VectorXd  ipoint 
)

Basic version of the SiMEC_1D algorithm, bulding the equaivalence class of a point.
Arguments:

  • output_file: Name of the file in which the outputs of the algorithm are saved.
  • steps: Number of interations of the algorithm.
  • delta: Integration step of the algorithm.
  • invert_build: Allows to follow a null curve in both directions.
  • ipoint: The starting point for which SiMEC_1D builds the equivalence class.

◆ SiMEC_1D_norm_proj()

void neural_network::SiMEC_1D_norm_proj ( std::string  output_file,
int  steps,
double  delta,
bool  invert_build,
Eigen::VectorXd  ipoint,
Eigen::VectorXd &  H_inf,
Eigen::VectorXd &  H_sup 
)

A modification of the SiMEC_1D algorithm. When it hits the boundary it projects inside the hypercube \((a_1\cdots,a_n) \times (b_1,\cdots,b_n) \).
Arguments:

  • output_file: Name of the file in which the outputs of the algorithm are saved.
  • steps: Number of interations of the algorithm.
  • delta: Integration step of the algorithm.
  • invert_build: Allows to follow a null curve in both directions.
  • ipoint: The starting point for which SiMEC_1D builds the equivalence class.
  • H_inf: The vector \((a_1\cdots,a_n)\).
  • H_max: The vector \((b_1,\cdots,b_n) \)

◆ SiMEC_1D_stop_boundary()

void neural_network::SiMEC_1D_stop_boundary ( std::string  output_file,
int  steps,
double  delta,
bool  invert_build,
Eigen::VectorXd  ipoint,
Eigen::VectorXd &  H_inf,
Eigen::VectorXd &  H_sup 
)

A modification of the SiMEC_1D algorithm. Hitting the boundary of the hypercube \((a_1\cdots,a_n) \times (b_1,\cdots,b_n) \) halts the algorithm.
Arguments:

  • output_file: Name of the file in which the outputs of the algorithm are saved.
  • steps: Number of interations of the algorithm.
  • delta: Integration step of the algorithm.
  • invert_build: Allows to follow a null curve in both directions.
  • ipoint: The starting point for which SiMEC_1D builds the equivalence class.
  • H_inf: The vector \((a_1\cdots,a_n)\).
  • H_max: The vector \((b_1,\cdots,b_n) \)

◆ SiMExp_1D()

void neural_network::SiMExp_1D ( std::string  output_file,
double  delta,
double  epsilon,
int  max_steps,
bool  invert_build,
Eigen::VectorXd &  ipoint 
)

SiMExp_1D algorithm. Produces a non-null curve of maximum lenght epsilon starting from a given point.
Arguments:

  • output_file: Name of the file in which the outputs of the algorithm are saved.
  • steps: Number of interations of the algorithm.
  • delta: Integration step of the algorithm.
  • epsilon: Maximum distance from the starting point.
  • invert_build: Allows to follow a null curve in both directions.
  • max_step: The maximum number of iteration; To avoid infinite loops.
  • ipoint: The starting point for which SiMEC_1D builds the equivalence class.

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