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
elman.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __ELMAN_H
25 #define __ELMAN_H
26 
27 #include <vector>
28 
29 #include "multilayerffnn.h"
30 
31 /// updates for network
32 class NetUpdate {
33 public:
35  NetUpdate(int numweights, int numbias, int numothers)
36  : weights(numweights), bias(numweights), other(numothers) {}
37  std::vector<matrix::Matrix> weights;
38  std::vector<matrix::Matrix> bias;
39  std::vector<matrix::Matrix> other;
40 };
41 
42 /** Multilayer Neural Network with context neurons (after Elman and Jordan)
43 Example of 2 hidden layer network with both, elman and jordan context units.
44 \pre{
45 +--<-----O O O
46 | | | |
47 | H H H
48 | | | |
49 | | | |
50 | | | |
51 | H H H ----->-----+ 1:1 fixed connections (time delayed)
52 | >->-/| | |\-<-< |
53 | / / / | | | \ \ \ |
54 | J J J I I I E E E |
55 +-^-^-^ ^-^-^--<--+
56 }
57  */
58 class Elman : public MultiLayerFFNN {
59 public:
60  /**
61  @param eps learning rate
62  @param layers Layer description (the input layer is not specified (always linear))
63  @param lambda self-recurrent feedback strength of context neurons
64  */
65  Elman(double eps, const std::vector<Layer>& layers,
66  bool useElman, bool useJordan=false, bool useBypass=false)
67  : MultiLayerFFNN(eps,layers,useBypass), useElman(useElman), useJordan(useJordan) {
68 
69  initialised = false;
70  }
71 
72  virtual ~Elman(){ }
73 
74  /// initialisation of the network with the given number of input and output units
75  virtual void init(unsigned int inputDim, unsigned int outputDim,
76  double unit_map = 0.0, RandGen* randGen = 0);
77 
78  /** passive processing of the input
79  (this will be different for every input, since it is a recurrent network)
80  */
81  virtual const matrix::Matrix process (const matrix::Matrix& input);
82 
83  /// performs learning and returns the network output before learning
84  virtual const matrix::Matrix learn (const matrix::Matrix& input,
85  const matrix::Matrix& nom_output,
86  double learnRateFactor = 1);
87 
88  /** determines the weight and bias updates
89  */
90  virtual NetUpdate weightIncrement(const matrix::Matrix& xsi);
91 
92  /** like weightIncrement but with blocked backprop flow for some neurons.
93  @param blockedlayer index of layer with blocked neurons
94  @param blockfrom index of neuron in blockedlayer to start blocking
95  @param blockto index of neuron in blockedlayer to end blocking (if -1 then to end)
96  (not included)
97  */
99  int blockedlayer,
100  int blockfrom, int blockto);
101 
102 
103  /** applies the weight increments to the weight (and bias) matrices
104  with the learningrate and the learnRateFactor */
105  virtual void updateWeights(const NetUpdate& updates);
106 
107 
108  /* Is implemented in multilayerfnn
109  virtual const matrix::Matrix response(const matrix::Matrix& input) const;
110  */
111 
112  void damp(double damping);
113 
114  /************** STOREABLE **********************************/
115  /// stores the layer binary into file stream
116  bool store(FILE* f) const;
117  /// restores the layer binary from file stream
118  bool restore(FILE* f);
119 
120 
121  /************** CONFIGURABLE INTERFACE ************************/
122  virtual paramkey getName() const {
123  return std::string("elmanNN");
124  }
125 
126 
127 
128  /************** Inspectable INTERFACE ************************/
129  virtual iparamkeylist getInternalParamNames() const;
130  virtual iparamvallist getInternalParams() const;
131  virtual ilayerlist getStructuralLayers() const;
133 
134 protected:
139  bool useElman;
140  bool useJordan;
141 
142 };
143 
144 #endif
Matrix type.
Definition: matrix.h:65
std::list< IConnection > iconnectionlist
Definition: inspectable.h:88
virtual ilayerlist getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: elman.cpp:308
NetUpdate()
Definition: elman.h:34
std::string paramkey
Definition: configurable.h:85
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: elman.cpp:82
updates for network
Definition: elman.h:32
virtual paramkey getName() const
return the name of the object
Definition: elman.h:122
matrix::Matrix jordanContext
Definition: elman.h:138
double eps
learning rate
Definition: multilayerffnn.h:167
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
std::vector< matrix::Matrix > weights
Definition: elman.h:37
Elman(double eps, const std::vector< Layer > &layers, bool useElman, bool useJordan=false, bool useBypass=false)
Definition: elman.h:65
bool initialised
Definition: multilayerffnn.h:199
matrix::Matrix input
Definition: multilayerffnn.h:194
virtual NetUpdate weightIncrementBlocked(const matrix::Matrix &xsi_, int blockedlayer, int blockfrom, int blockto)
like weightIncrement but with blocked backprop flow for some neurons.
Definition: elman.cpp:163
virtual iparamkeylist getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: elman.cpp:279
Multilayer Neural Network with context neurons (after Elman and Jordan) Example of 2 hidden layer net...
Definition: elman.h:58
virtual iparamvallist getInternalParams() const
Definition: elman.cpp:293
NetUpdate(int numweights, int numbias, int numothers)
Definition: elman.h:35
virtual ~Elman()
Definition: elman.h:72
matrix::Matrix elmanWeights
Definition: elman.h:135
bool store(FILE *f) const
stores the layer binary into file stream
Definition: elman.cpp:245
bool restore(FILE *f)
restores the layer binary from file stream
Definition: elman.cpp:260
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: elman.cpp:34
virtual NetUpdate weightIncrement(const matrix::Matrix &xsi)
determines the weight and bias updates
Definition: elman.cpp:125
std::vector< matrix::Matrix > bias
Definition: elman.h:38
virtual iconnectionlist getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: elman.cpp:317
virtual void updateWeights(const NetUpdate &updates)
applies the weight increments to the weight (and bias) matrices with the learningrate and the learnRa...
Definition: elman.cpp:208
std::vector< matrix::Matrix > other
Definition: elman.h:39
bool useBypass
Definition: multilayerffnn.h:190
multi layer neural network with configurable activation functions
Definition: multilayerffnn.h:35
void damp(double damping)
damps the weights and the biases by multiplying (1-damping)
Definition: elman.cpp:234
bool useJordan
Definition: elman.h:140
bool useElman
Definition: elman.h:139
std::list< ILayer > ilayerlist
Definition: inspectable.h:87
matrix::Matrix jordanWeights
Definition: elman.h:137
matrix::Matrix elmanContext
Definition: elman.h:136
std::list< iparamkey > iparamkeylist
Definition: inspectable.h:59
std::list< iparamval > iparamvallist
Definition: inspectable.h:61
std::vector< Layer > layers
Definition: multilayerffnn.h:186
virtual const matrix::Matrix process(const matrix::Matrix &input)
passive processing of the input (this will be different for every input, since it is a recurrent netw...
Definition: elman.cpp:51