A singular Riemannian geometry approach to Deep Neural Networks.
neural_network.h
1 /******************************************************
2 *
3 * NEURAL NETWORK CLASS
4 *
5 ******************************************************/
6 
12 #ifndef NEURAL_NETWORK_H
13 #define NEURAL_NETWORK_H
14 
15 
16 //STD libs
17 #include<math.h>
18 #include<vector>
19 #include<fstream>
20 #include<iostream>
21 #include<string>
22 
23 //OpenMP libs
24 #include<omp.h>
25 
26 //Eigen libs
27 #include"Eigen/Dense"
28 
29 //Neural network libs
30 #include"layers.h"
31 #include"layer.h"
32 
33 using namespace std;
34 
37 {
38  public:
39  //ctor
41  neural_network(){num_layers = 0;};
43  neural_network(const std::vector<layer*> &ls);
44 
45  //dtor
47  ~neural_network(){ for (int i = 0; i < num_layers; i++){ delete layers[i];}};
48 
49  //Info about the neural network
50 
52  int get_num_layers();
54  void print_network_info();
57  //Prediction functions
58 
59  void print_network_detailed_info();
60  //Prediction functions (serial version).
62  Eigen::VectorXd predict(const Eigen::VectorXd &input);
64  Eigen::VectorXd predict_to_layer(int tolayer,const Eigen::VectorXd &input);
65  //Prediction functions - Parallel version
67  std::vector<Eigen::VectorXd> predict(const std::vector<Eigen::VectorXd> &input);
69  std::vector<Eigen::VectorXd> predict_to_layer(int tolayer,const std::vector<Eigen::VectorXd> &input);
70 
71  //Save/read the network
72 
74  void network_read(const std::string &filename);
76  void network_save(const std::string &filename);
77 
78  //Builds the network
90  void add_layer_all_parameters(int wrows, int wcols, int in_dim, int out_dim, std::string type);
99  void add_fc_input_layer(int in_dim, int out_dim, std::string type);
109  void add_fc_hidden_layer(int out_dim, std::string type);
110 
111  //Set and get biases and weights. To be used with the python wrapper
113  void set_layer_weights(int num_layer, Eigen::MatrixXd& weights_);
115  void set_layer_biases(int num_layer, Eigen::VectorXd& biases_);
117  Eigen::MatrixXd get_layer_weights(int num_layer);
119  Eigen::VectorXd get_layer_biases(int num_layer);
120 
121  //Loss functions
122  double loss_mse(const std::vector<Eigen::VectorXd> &data, const std::vector<Eigen::VectorXd> &features);
123  double accuracy(const std::vector<Eigen::VectorXd> &data, const std::vector<Eigen::VectorXd> &features);
124 
125  //SiMEC 1D algos
126 
136  void SiMEC_1D(std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint);
148  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);
160  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);
161 
162  //SiMExp 1D algos
174  void SiMExp_1D(std::string output_file, double delta, double epsilon, int max_steps, bool invert_build, Eigen::VectorXd & ipoint);
178  void ClassChange_1D(std::string output_file, int steps, double delta, bool invert_build, Eigen::VectorXd ipoint);
179 
180 
181 
182  layer* get_layer(int n)
183  {
184  return layers[n];
185  }
186 
187  private:
188  int num_layers;
189  std::vector<layer*> layers;
190 };
191 
192 
193 
194 
195 
196 
197 #endif /* NEURAL_NETWORK_H */
198 
neural_network::neural_network
neural_network()
Definition: neural_network.h:41
neural_network::~neural_network
~neural_network()
Definition: neural_network.h:47
neural_network
Definition: neural_network.h:36
layer
Generic layer class.
Definition: layer.h:30