SANN: Sushi Artificial Neural Network
This is a short library for a simple but efficient neural network
dataStructures.h
1 /*******************************************************
2  * *
3  * sann: Neural Network library *
4  * *
5  * DATA STRUCUTRES *
6  * *
7  * Giulio Auriemma *
8  * *
9  *******************************************************/
10 #ifndef S_DATASTRUCTURES_S
11 #define S_DATASTRUCTURES_S
12 
13 #include <string>
14 #include <vector>
15 #include <functional>
16 #include <iostream>
17 
18 namespace sann{
19 
27 typedef struct ds{
28  std::vector<std::string> names;
29  std::vector<std::vector<double>> inputs;
30  std::vector<std::vector<double>> results;
31 
32  struct ds operator+(const struct ds x) const{
33  struct ds newDs{names, inputs, results};
34  newDs.names.insert(newDs.names.end(), x.names.begin(), x.names.end());
35  newDs.inputs.insert(newDs.inputs.end(), x.inputs.begin(), x.inputs.end());
36  newDs.results.insert(newDs.results.end(), x.results.begin(), x.results.end());
37  return newDs;
38  }
39 
48  struct ds extractData(const size_t start, const size_t end){
49  auto starti = this->inputs.begin() + start, startr = this->results.begin() + start,
50  endi = this->inputs.begin() + end, endr = this->results.begin() + end;
51  auto startn = this->names.begin() + start, endn = this->names.begin() + end;
52 
53  // Check if the size is right.
54  if(end >= this->inputs.size()){
55  endi = this->inputs.end(); endr = this->results.end(); endn = this->names.end();
56  }
57 
58  // Build and erase the new dataset.
59  std::vector<std::vector<double>> newInputs{starti, endi}, newResults{startr, endr};
60  std::vector<std::string> newNames{startn, endn};
61  this->inputs.erase(starti, endi); this->results.erase(startr, endr); this->names.erase(startn, endn);
62 
63  return {newNames, newInputs, newResults};
64  }
65 } dataSet;
66 
78 typedef struct p{
79  std::size_t max_epoch, mb;
80  float eta;
81  float mi;
82  float lambda;
83  std::function<void(struct p &par, const size_t epoch)> update;
84 } parameters;
85 
86 typedef std::vector<std::vector<double>> weightsMatrix;
87 
88 /****************************************FUNCTIONS****************************************/
89 
90 
91 // Overload for << stream operator on weightsmatrix.
92 // std::ostream& operator<<(std::ostream& os, const weightsMatrix& weights)
93 // {
94 // for(size_t i = 0; i < weights.size(); ++i){
95 // for(size_t j = 0; j < weights[i].size(); ++j)
96 // os << weights[i][j] << ' ';
97 // os << '\n';
98 // }
99 
100 // return os;
101 // }
102 
103 }
104 
105 #endif
This is the struct that represents the dataset to handle. It has three attributes: ...
Definition: dataStructures.h:27
The parameters object. It holds all the settable hyper-parameters:
Definition: dataStructures.h:78
Definition: constants.h:15
struct ds extractData(const size_t start, const size_t end)
Creates a new dataset from a subset of a given dataset. The dataset on which this method is call will...
Definition: dataStructures.h:48