onelayerffnn.h

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

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