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

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# 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     : eps(eps), factor_bias(factor_bias){
    00018     actfun  = linear;
    00019     dactfun = dlinear;
    00020
    00021     initialised = false;
    00022   }
    00023   /**
    00024      @param eps learning rate
    00025      @param factor_bias learning rate factor for bias learning
    00026      @param actfun callback activation function (see FeedForwardNN)
    00027      @param dactfun callback for first derivative of the activation function
    00028   */
    00029   OneLayerFFNN(double eps,
    00030                double factor_bias,
    00031                ActivationFunction actfun,
    00032                ActivationFunction dactfun)
    00033     : eps(eps), factor_bias(factor_bias), actfun(actfun), dactfun(dactfun) {
    00034     initialised = false;
    00035   }
    00036   virtual ~OneLayerFFNN(){ }
    00037
    00038   /* initialisation of the network with the given number of input and output units
    00039      @param unit_map defines the approximate response of the network
    00040        after initialisation (if unit_map=1 the weights are unit matrices).
    00041      @param randGen pointer to random generator, if 0 an new one is used
    00042   */
    00043   virtual void init(unsigned int inputDim, unsigned  int outputDim,
    00044                     double unit_map = 0.0, RandGen* randGen = 0);
    00045
    00046   virtual const matrix::Matrix process (const matrix::Matrix& input);
    00047
    00048   virtual const matrix::Matrix learn (const matrix::Matrix& input,
    00049                                       const matrix::Matrix& nom_output,
    00050                                       double learnRateFactor = 1);
    00051
    00052   /// returns the number of input neurons
    00053   virtual unsigned int getInputDim() const {
    00054     return weights.getN();
    00055   }
    00056   /// returns the number of output neurons
    00057   virtual unsigned int getOutputDim() const {
    00058     return weights.getM();
    00059   }
    00060
    00061   virtual const matrix::Matrix& getWeights() const { return weights; }
    00062   virtual const matrix::Matrix& getBias()    const { return bias; }
    00063
    00064   /// damps the weights and the biases by multiplying (1-damping)
    00065   virtual void damp(double damping){
    00066     weights *= (1-damping);
    00067     bias    *= (1-damping);
    00068   }
    00069
    00070   /**************  STOREABLE **********************************/
    00071   /// stores the layer binary into file stream
    00072   bool store(FILE* f) const;
    00073   /// restores the layer binary from file stream
    00074   bool restore(FILE* f);
    00075
    00076   /************** CONFIGURABLE INTERFACE ************************/
    00077   virtual paramkey getName() const {
    00078     return paramkey("onelayerffnn");
    00079   }
    00080
    00081   virtual paramval getParam(const paramkey key) const {
    00082     if(key == "eps") return eps;
    00083     else return 0.0;
    00084   }
    00085
    00086   virtual bool setParam(const paramkey key, paramval val){
    00087     if( key == "eps") {
    00088       eps = val;
    00089       return true;
    00090     } else return false;
    00091   }
    00092
    00093   virtual paramlist getParamList() const{
    00094     paramlist l;
    00095     l.push_back(std::pair<paramkey, paramval> ("eps", eps));
    00096     return l;
    00097   }
    00098
    00099
    00100 private:
    00101   double eps;
    00102   double factor_bias;
    00103   ActivationFunction actfun;  ///< callback activation function
    00104   ActivationFunction dactfun; ///< first derivative of the activation function
    00105
    00106 private:
    00107   bool initialised;
    00108   matrix::Matrix weights;
    00109   matrix::Matrix bias;
    00110 };
    00111
    00112 #endif