LoveBrains  1.0.0
neural_net.h
1 /*
2 ** NeuralNet.h for GANNEngine in /home/robin_f/Programming/Git/CPP/GANNEngine
3 **
4 ** Made by Guillaume ROBIN
5 ** Login <robin_f@epitech.eu>
6 **
7 ** Started on Wed Jul 8 14:47:02 2015 Guillaume ROBIN
8 ** Last update Fri Aug 21 23:52:24 2015 Guillaume ROBIN
9 */
10 
11 #ifndef NEURAL_NET_H_
12 # define NEURAL_NET_H_
13 
14 # include "ANN/ann_layer.h"
15 # include "ANN/ann_exception.h"
16 # include "json/json.h"
17 
18 namespace GANN
19 {
24  class ANN
25  {
26  public:
30  enum class ActivationType { SIGMOID, THRESHOLD, CUSTOM };
31 
35  ANN(void) throw();
40  ANN(std::vector<unsigned int> const& infos);
44  ~ANN(void) throw();
45 
46  /*
47  ** Getters.
48  */
49 
54  Matrix<double> const& getOutputs(void) const;
59  double getMinRandom(void) const throw();
64  double getMaxRandom(void) const throw();
69  std::vector<ANNLayer *> const& getLayers(void) const throw();
74  std::vector<unsigned int> const& getInfos(void) const throw();
79  double getCrossingRate(void) const throw();
84  ANNLayer::FActivate getActivationFunction(void) const throw();
89  ANNLayer::FActivate getOutputsActivation(void) const throw();
94  ActivationType getOutputType(void) const throw();
99  ActivationType getLayerType(void) const throw();
100 
101  /*
102  ** Setters.
103  */
104 
110  void setRandom(double min, double max) throw();
115  void setLayers(std::vector<ANNLayer *> const& layers) throw();
120  void setCrossingRate(double rate) throw();
126  void setActivationFunction(ANNLayer::FActivate f, ActivationType type);
132  void setOutputsActivation(ANNLayer::FActivate f, ActivationType type);
133 
134  /*
135  ** Overload.
136  */
137  ANN& operator=(ANN const& b);
138 
139  /*
140  ** Methods.
141  */
142 
147  void Create(std::vector<unsigned int> const& infos);
152  void Activate(Matrix<double> const& inputs);
157  void Save(const char *path) const;
162  void Load(const char *path);
163 
164  private:
165  double _rand_min;
166  double _rand_max;
167  double _cross_rate;
168  ActivationType _out_ftype;
169  ActivationType _layer_ftype;
170  ANNLayer::FActivate _out_activation;
171  ANNLayer::FActivate _layer_activation;
172  std::vector<unsigned int> _infos;
173  std::vector<ANNLayer *> _layers;
175  /*
176  ** Methods.
177  */
178 
183  void SaveInfos(Json::Value& ann) const throw();
188  void SaveRandomize(Json::Value& ann) const throw();
193  void SaveOutputActivation(Json::Value& ann) const throw();
198  void SaveLayerActivation(Json::Value& ann) const throw();
204  void SaveLayers(Json::Value& ann) const;
205 
206 
211  void LoadInfos(Json::Value const& ann) throw();
216  void LoadGenerateInfos(Json::Value const& ann) throw();
221  void LoadOutputActivation(Json::Value const& ann) throw();
226  void LoadLayerActivation(Json::Value const& ann) throw();
232  void LoadLayers(Json::Value const& ann);
233  };
234 }
235 
236 #endif /* !NEURAL_NET_H_ */
std::vector< ANNLayer * > const & getLayers(void) const
Get the vector that contains all the layers of the neural network.
Definition: neural_net.cc:78
double getMaxRandom(void) const
Get the maximum value of the randomization range.
Definition: neural_net.cc:73
Definition: json.h:1186
ANNLayer::FActivate getActivationFunction(void) const
Get the activation function of the intern layers.
Definition: neural_net.cc:93
void setRandom(double min, double max)
Set the range of the randomization.
Definition: neural_net.cc:116
std::vector< unsigned int > const & getInfos(void) const
Get the topology of the neural network.
Definition: neural_net.cc:83
void setActivationFunction(ANNLayer::FActivate f, ActivationType type)
Set the function pointer of the intern layers activation function.
Definition: neural_net.cc:142
ANNLayer::FActivate getOutputsActivation(void) const
Get the activation function of the output layer.
Definition: neural_net.cc:98
double getCrossingRate(void) const
Get the crossing rate of the nerual network.
Definition: neural_net.cc:88
void setCrossingRate(double rate)
Set the crossing rate of the neural network.
Definition: neural_net.cc:131
void Save(const char *path) const
Save the neural network in JSON (using the librairy called "Jsoncpp").
Definition: neural_net_save.cc:106
ActivationType getLayerType(void) const
Get the activation function's type of the output layer.
Definition: neural_net.cc:108
double getMinRandom(void) const
Get the minimum value of the randomization range.
Definition: neural_net.cc:68
void setOutputsActivation(ANNLayer::FActivate f, ActivationType type)
Set the function pointer of the output layer's activation function.
Definition: neural_net.cc:150
Define a layer of a neural network.
Definition: ann_layer.h:22
JSON (JavaScript Object Notation).
Definition: json-forwards.h:172
Define what is a neural network.
Definition: neural_net.h:24
Definition: matrix.h:26
ANN(void)
Constructor.
Definition: neural_net.cc:23
Matrix< double > const & getOutputs(void) const
Get the matrix of outputs.
Definition: neural_net.cc:60
void Create(std::vector< unsigned int > const &infos)
Create a neural network.
Definition: neural_net.cc:207
Contains all the objects that provide the management for the genetic algorithm with neural networks...
Definition: ann_exception.h:16
void Load(const char *path)
Load the neural network from the JSON file (using the librairy called "Jsoncpp"). ...
Definition: neural_net_load.cc:136
ActivationType
Define the type of the activation function.
Definition: neural_net.h:30
ActivationType getOutputType(void) const
Get the activation function's type of the intern layers.
Definition: neural_net.cc:103
void setLayers(std::vector< ANNLayer * > const &layers)
Set the vector of layers.
Definition: neural_net.cc:122
void Activate(Matrix< double > const &inputs)
Activate the neural network and set the matrix of outputs.
Definition: neural_net.cc:186