OpenANN  1.1.0
An open source library for artificial neural networks.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Net.h
Go to the documentation of this file.
1 #ifndef OPENANN_NET_H_
2 #define OPENANN_NET_H_
3 
4 #include <OpenANN/Learner.h>
7 #include <OpenANN/layers/Layer.h>
8 #include <vector>
9 #include <sstream>
10 
11 namespace OpenANN
12 {
13 
20 {
22  MSE,
23  CE
24 };
25 
34 class Net : public Learner
35 {
36 protected:
37  std::vector<OutputInfo> infos;
38  std::vector<Layer*> layers;
39  std::vector<double*> parameters;
40  std::vector<double*> derivatives;
43  bool dropout;
44 
46  int P, L;
47  Eigen::VectorXd parameterVector, tempGradient;
48  Eigen::MatrixXd tempInput, tempOutput, tempError;
49 
50  std::stringstream architecture;
51 
52 public:
56  Net();
57  virtual ~Net();
58 
63 
72  Net& inputLayer(int dim1, int dim2 = 1, int dim3 = 1);
80  Net& alphaBetaFilterLayer(double deltaT, double stdDev = 0.05);
90  double stdDev = 0.05, bool bias = true);
100  Net& restrictedBoltzmannMachineLayer(int H, int cdN = 1,
101  double stdDev = 0.01,
102  bool backprop = true);
110  Net& sparseAutoEncoderLayer(int H, double beta, double rho,
111  ActivationFunction act);
124  Net& compressedLayer(int units, int params, ActivationFunction act,
125  const std::string& compression, double stdDev = 0.05,
126  bool bias = true);
135  Net& extremeLayer(int units, ActivationFunction act, double stdDev = 5.0,
136  bool bias = true);
146  Net& intrinsicPlasticityLayer(double targetMean, double stdDev = 1.0);
157  Net& convolutionalLayer(int featureMaps, int kernelRows, int kernelCols,
158  ActivationFunction act, double stdDev = 0.05,
159  bool bias = true);
170  Net& subsamplingLayer(int kernelRows, int kernelCols,
171  ActivationFunction act, double stdDev = 0.05,
172  bool bias = true);
179  Net& maxPoolingLayer(int kernelRows, int kernelCols);
191  Net& localReponseNormalizationLayer(double k, int n, double alpha,
192  double beta);
197  Net& dropoutLayer(double dropoutProbability);
207  Net& outputLayer(int units, ActivationFunction act, double stdDev = 0.05,
208  bool bias = true);
222  Net& compressedOutputLayer(int units, int params, ActivationFunction act,
223  const std::string& compression,
224  double stdDev = 0.05, bool bias = true);
232  Net& addLayer(Layer* layer);
240  Net& addOutputLayer(Layer* layer);
242 
246 
251  unsigned int numberOflayers();
257  Layer& getLayer(unsigned int l);
263  OutputInfo getOutputInfo(unsigned int l);
270  DataSet* propagateDataSet(DataSet& dataSet, int l);
272 
276 
281  void save(const std::string& fileName);
286  void save(std::ostream& stream);
291  void load(const std::string& fileName);
313  void load(std::istream& stream);
315 
319  Net& setRegularization(double l1Penalty = 0.0, double l2Penalty = 0.0,
321  double maxSquaredWeightNorm = 0.0);
333  Net& useDropout(bool activate = true);
335 
339  virtual Eigen::VectorXd operator()(const Eigen::VectorXd& x);
341  virtual Eigen::MatrixXd operator()(const Eigen::MatrixXd& X);
342  virtual unsigned int dimension();
343  virtual const Eigen::VectorXd& currentParameters();
344  virtual void setParameters(const Eigen::VectorXd& parameters);
345  virtual bool providesInitialization();
346  virtual void initialize();
347  virtual unsigned int examples();
348  virtual double error(unsigned int n);
349  virtual double error();
350  virtual bool providesGradient();
351  virtual Eigen::VectorXd gradient(unsigned int n);
352  virtual Eigen::VectorXd gradient();
353  virtual void errorGradient(int n, double& value, Eigen::VectorXd& grad);
354  virtual void errorGradient(double& value, Eigen::VectorXd& grad);
355  virtual void errorGradient(std::vector<int>::const_iterator startN,
356  std::vector<int>::const_iterator endN,
357  double& value, Eigen::VectorXd& grad);
358  virtual void finishedIteration();
360 
361 protected:
362  void initializeNetwork();
363  void forwardPropagate(double* error);
364  void backpropagate();
365 };
366 
367 } // namespace OpenANN
368 
369 #endif // OPENANN_NET_H
370