Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
onelayerffnn.h
Go to the documentation of this file.
1 #ifndef __ONELAYERFFNN_H
2 #define __ONELAYERFFNN_H
3 
4 #include "feedforwardnn.h"
5 #include "randomgenerator.h"
6 
7 /// simple one layer neural network with configurable activation function
8 class OneLayerFFNN : public FeedForwardNN {
9 public:
10  /**
11  Uses linear activation function
12  @param eps learning rate
13  @param factor_bias learning rate factor for bias learning
14  */
15  OneLayerFFNN(double eps,
16  double factor_bias = 0.1,
17  const std::string& name = "OneLayerFFN",
18  const std::string& revision = "$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
19  : FeedForwardNN(name, revision), eps(eps), factor_bias(factor_bias){
20  actfun = linear;
21  dactfun = dlinear;
22  addParameter("eps",&this->eps,0,1,"learning rate");
23  addParameter("factor_bias",&this->factor_bias,0,2,"factor for learningrate of bias");
24  initialised = false;
25  }
26  /**
27  @param eps learning rate
28  @param factor_bias learning rate factor for bias learning
29  @param actfun callback activation function (see FeedForwardNN)
30  @param dactfun callback for first derivative of the activation function
31  */
32  OneLayerFFNN(double eps,
33  double factor_bias,
34  ActivationFunction actfun,
35  ActivationFunction dactfun,
36  const std::string& name = "OneLayerFFN",
37  const std::string& revision = "$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
38  : FeedForwardNN(name, revision), eps(eps), factor_bias(factor_bias), actfun(actfun), dactfun(dactfun) {
39  addParameter("eps",&this->eps,0,1,"learning rate");
40  addParameter("factor_bias",&this->factor_bias,0,2,"factor for learningrate of bias");
41  initialised = false;
42  }
43  virtual ~OneLayerFFNN(){ }
44 
45  /* initialisation of the network with the given number of input and output units
46  @param unit_map defines the approximate response of the network
47  after initialisation (if unit_map=1 the weights are unit matrices).
48  @param randGen pointer to random generator, if 0 an new one is used
49  */
50  virtual void init(unsigned int inputDim, unsigned int outputDim,
51  double unit_map = 0.0, RandGen* randGen = 0);
52 
53  virtual const matrix::Matrix process (const matrix::Matrix& input);
54 
55  virtual const matrix::Matrix learn (const matrix::Matrix& input,
56  const matrix::Matrix& nom_output,
57  double learnRateFactor = 1);
58 
59  /// returns the number of input neurons
60  virtual unsigned int getInputDim() const {
61  return weights.getN();
62  }
63  /// returns the number of output neurons
64  virtual unsigned int getOutputDim() const {
65  return weights.getM();
66  }
67 
68  virtual const matrix::Matrix& getWeights() const { return weights; }
69  virtual const matrix::Matrix& getBias() const { return bias; }
70 
71  /// damps the weights and the biases by multiplying (1-damping)
72  virtual void damp(double damping){
73  weights *= (1-damping);
74  bias *= (1-damping);
75  }
76 
77  /************** STOREABLE **********************************/
78  /// stores the layer binary into file stream
79  bool store(FILE* f) const;
80  /// restores the layer binary from file stream
81  bool restore(FILE* f);
82 
83 
84 private:
85  double eps;
86  double factor_bias;
87  ActivationFunction actfun; ///< callback activation function
88  ActivationFunction dactfun; ///< first derivative of the activation function
89 
90 private:
91  bool initialised;
92  matrix::Matrix weights;
93  matrix::Matrix bias;
94 };
95 
96 #endif
Matrix type.
Definition: matrix.h:65
virtual const matrix::Matrix process(const matrix::Matrix &input)
passive processing of the input
Definition: onelayerffnn.cpp:20
bool store(FILE *f) const
stores the layer binary into file stream
Definition: onelayerffnn.cpp:41
bool restore(FILE *f)
restores the layer binary from file stream
Definition: onelayerffnn.cpp:48
virtual ~OneLayerFFNN()
Definition: onelayerffnn.h:43
I getM() const
Definition: matrix.h:88
virtual unsigned int getOutputDim() const
returns the number of output neurons
Definition: onelayerffnn.h:64
iparamkey name
Definition: inspectable.h:251
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual void damp(double damping)
damps the weights and the biases by multiplying (1-damping)
Definition: onelayerffnn.h:72
I getN() const
Definition: matrix.h:90
virtual const matrix::Matrix learn(const matrix::Matrix &input, const matrix::Matrix &nom_output, double learnRateFactor=1)
performs learning and returns the network output before learning
Definition: onelayerffnn.cpp:25
virtual void addParameter(const paramkey &key, paramval *val, paramval minBound, paramval maxBound, const paramdescr &descr=paramdescr())
This is the new style for adding configurable parameters.
Definition: configurable.h:172
OneLayerFFNN(double eps, double factor_bias, ActivationFunction actfun, ActivationFunction dactfun, const std::string &name="OneLayerFFN", const std::string &revision="$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
Definition: onelayerffnn.h:32
virtual unsigned int getInputDim() const
returns the number of input neurons
Definition: onelayerffnn.h:60
abstract class (interface) for feed forward rate based neural networks
Definition: feedforwardnn.h:41
static double dlinear(double)
Definition: feedforwardnn.h:55
simple one layer neural network with configurable activation function
Definition: onelayerffnn.h:8
virtual const matrix::Matrix & getBias() const
Definition: onelayerffnn.h:69
virtual void init(unsigned int inputDim, unsigned int outputDim, double unit_map=0.0, RandGen *randGen=0)
initialisation of the network with the given number of input and output units
Definition: onelayerffnn.cpp:8
double(* ActivationFunction)(double)
activation function type: input: membrane potential
Definition: feedforwardnn.h:34
static double linear(double z)
Definition: feedforwardnn.h:54
virtual const matrix::Matrix & getWeights() const
Definition: onelayerffnn.h:68
OneLayerFFNN(double eps, double factor_bias=0.1, const std::string &name="OneLayerFFN", const std::string &revision="$Id: onelayerffnn.h,v 1.10 2011/05/30 13:52:54 martius Exp $")
Uses linear activation function.
Definition: onelayerffnn.h:15