multilayerffnn.h

Go to the documentation of this file.
00001 #ifndef __MULTILAYERFFNN_H
00002 #define __MULTILAYERFFNN_H
00003 
00004 #include <vector>
00005 
00006 #include "feedforwardnn.h"
00007 
00008 class Layer {
00009 public:
00010   Layer(int size, double factor_bias=0.1, 
00011         ActivationFunction actfun = FeedForwardNN::linear, 
00012         ActivationFunction dactfun = FeedForwardNN::dlinear)
00013     : size(size), factor_bias(factor_bias), actfun(actfun), dactfun(dactfun) {}
00014 
00015   int size;
00016   double factor_bias;
00017   ActivationFunction actfun;  //< callback activation function
00018   ActivationFunction dactfun; //< first derivative of the activation function  
00019 };
00020 
00021 /// multi layer neural network with configurable activation functions
00022 class MultiLayerFFNN : public FeedForwardNN {
00023 public: 
00024   /**
00025      @param eps learning rate
00026      @param layers Layer description (the input layer is not specified (always linear))
00027   */
00028   MultiLayerFFNN(double eps, 
00029                  const vector<Layer>& layers)
00030     : eps(eps), layers(layers) { 
00031     
00032     initialised = false;  
00033   }
00034   virtual ~MultiLayerFFNN(){ }
00035 
00036   /// initialisation of the network with the given number of input and output units
00037   virtual void init(unsigned int inputDim, unsigned  int outputDim); 
00038 
00039   /// passive processing of the input
00040   virtual const matrix::Matrix process (const matrix::Matrix& input) const; 
00041 
00042   /// performs learning and returns the network output before learning
00043   virtual const matrix::Matrix learn (const matrix::Matrix& input, 
00044                                       const matrix::Matrix& nom_output, 
00045                                       double learnRateFactor = 1);
00046 
00047   /// returns the number of input neurons
00048   virtual unsigned int getInputDim() const { 
00049     return weights[0].getN(); 
00050   }
00051   /// returns the number of output neurons
00052   virtual unsigned int getOutputDim() const { 
00053     return (weights.rbegin())->getM(); 
00054   }
00055 
00056   /// damps the weights and the biases by multiplying (1-damping)
00057   virtual void damp(double damping);
00058 
00059   /************** CONFIGURABLE INTERFACE ************************/
00060   virtual paramkey getName() const {
00061     return string("multilayerffnn");
00062   }
00063 
00064   virtual paramval getParam(const paramkey key) const {
00065     if(key == "eps") return eps;
00066     else return 0.0;
00067   }
00068   
00069   virtual bool setParam(const paramkey key, paramval val){
00070     if( key == "eps") { 
00071       eps = val;
00072       return true;
00073     } else return false;
00074   }
00075 
00076   virtual paramlist getParamList() const{
00077     paramlist l;
00078     l.push_back(pair<paramkey, paramval> ("eps", eps));
00079     return l;
00080   }
00081 
00082 
00083 private:
00084   double eps;
00085   vector<Layer> layers;
00086   vector<matrix::Matrix> weights;
00087   vector<matrix::Matrix> bias;
00088 
00089   bool initialised;
00090 };
00091 
00092 #endif

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5