Robot Simulator of the Robotics Group for Self-Organization of Control: onelayerffnn.h Source File

# onelayerffnn.h

Go to the documentation of this file.

    00001 #ifndef __ONELAYERFFNN_H
    00002 #define __ONELAYERFFNN_H
    00003
    00004 #include "feedforwardnn.h"
    00005 #include "randomgenerator.h"
    00006
    00007 /// simple one layer neural network with configurable activation function
    00008 class OneLayerFFNN : public FeedForwardNN {
    00009 public:
    00010   /**
    00011      Uses linear activation function
    00012      @param eps learning rate
    00013      @param factor_bias learning rate factor for bias learning
    00014   */
    00015   OneLayerFFNN(double eps,
    00016                double factor_bias = 0.1,
    00017                const std::string& name = "OneLayerFFN",
    00018                const std::string& revision = "$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
    00019     : FeedForwardNN(name, revision), eps(eps), factor_bias(factor_bias){
    00020     actfun  = linear;
    00021     dactfun = dlinear;
    00022     addParameter("eps",&this->eps,0,1,"learning rate");
    00023     addParameter("factor_bias",&this->factor_bias,0,2,"factor for learningrate of bias");
    00024     initialised = false;
    00025   }
    00026   /**
    00027      @param eps learning rate
    00028      @param factor_bias learning rate factor for bias learning
    00029      @param actfun callback activation function (see FeedForwardNN)
    00030      @param dactfun callback for first derivative of the activation function
    00031   */
    00032   OneLayerFFNN(double eps,
    00033                double factor_bias,
    00034                ActivationFunction actfun,
    00035                ActivationFunction dactfun,
    00036                const std::string& name = "OneLayerFFN",
    00037                const std::string& revision = "$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
    00038     : FeedForwardNN(name, revision), eps(eps), factor_bias(factor_bias), actfun(actfun), dactfun(dactfun) {
    00039     addParameter("eps",&this->eps,0,1,"learning rate");
    00040     addParameter("factor_bias",&this->factor_bias,0,2,"factor for learningrate of bias");
    00041     initialised = false;
    00042   }
    00043   virtual ~OneLayerFFNN(){ }
    00044
    00045   /* initialisation of the network with the given number of input and output units
    00046      @param unit_map defines the approximate response of the network
    00047        after initialisation (if unit_map=1 the weights are unit matrices).
    00048      @param randGen pointer to random generator, if 0 an new one is used
    00049   */
    00050   virtual void init(unsigned int inputDim, unsigned  int outputDim,
    00051                     double unit_map = 0.0, RandGen* randGen = 0);
    00052
    00053   virtual const matrix::Matrix process (const matrix::Matrix& input);
    00054
    00055   virtual const matrix::Matrix learn (const matrix::Matrix& input,
    00056                                       const matrix::Matrix& nom_output,
    00057                                       double learnRateFactor = 1);
    00058
    00059   /// returns the number of input neurons
    00060   virtual unsigned int getInputDim() const {
    00061     return weights.getN();
    00062   }
    00063   /// returns the number of output neurons
    00064   virtual unsigned int getOutputDim() const {
    00065     return weights.getM();
    00066   }
    00067
    00068   virtual const matrix::Matrix& getWeights() const { return weights; }
    00069   virtual const matrix::Matrix& getBias()    const { return bias; }
    00070
    00071   /// damps the weights and the biases by multiplying (1-damping)
    00072   virtual void damp(double damping){
    00073     weights *= (1-damping);
    00074     bias    *= (1-damping);
    00075   }
    00076
    00077   /**************  STOREABLE **********************************/
    00078   /// stores the layer binary into file stream
    00079   bool store(FILE* f) const;
    00080   /// restores the layer binary from file stream
    00081   bool restore(FILE* f);
    00082
    00083
    00084 private:
    00085   double eps;
    00086   double factor_bias;
    00087   ActivationFunction actfun;  ///< callback activation function
    00088   ActivationFunction dactfun; ///< first derivative of the activation function
    00089
    00090 private:
    00091   bool initialised;
    00092   matrix::Matrix weights;
    00093   matrix::Matrix bias;
    00094 };
    00095
    00096 #endif