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
derlinunivers.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Robot Group Leipzig *
3  * martius@informatik.uni-leipzig.de *
4  * fhesse@informatik.uni-leipzig.de *
5  * der@informatik.uni-leipzig.de *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  * $Log$
23  * Revision 1.1 2008-06-26 14:04:51 guettler
24  * controller with linear inversion and multilayer FFNN
25  *
26  * Revision 1.3 2008/04/17 14:54:45 martius
27  * randomGen added, which is a random generator with long period and an
28  * internal state. Each Agent has an instance and passed it to the controller
29  * and the wiring. This is good for
30  * a) repeatability on agent basis,
31  * b) parallel execution as done in ode_robots
32  *
33  * Revision 1.2 2007/12/13 16:04:01 martius
34  * store and restore
35  * stuctural output for neuronviz
36  *
37  * Revision 1.1 2007/12/11 14:22:09 martius
38  * new (old) controller update only with backprop steps
39  * and complex nets
40  *
41  * *
42  * *
43  ***************************************************************************/
44 #ifndef __DERLINUNIVERS_H
45 #define __DERLINUNIVERS_H
46 
47 
48 #include <stdio.h>
49 #include <vector>
50 #include "abstractcontroller.h"
51 #include "elman.h"
52 #include "matrix.h"
53 
54 typedef struct _DerLinUniversConf {
55  unsigned int buffersize; ///< buffersize size of the time-buffer for x,y,v
56  double init; ///< init size of the matrices of the network.
57  double squashsize; ///< update squashing
58  bool someInternalParams; ///< someInternalParams if true only some internal parameters are exported, all otherwise
59 
60  Elman* net; ///< entire contoller network (should have at least 2 layers)
61  int motorlayer; ///< index of motor layer in the network (if -1 then one but last layer)
63 
64 
65 /**
66  * class for robot control with sine and cosine
67  *
68  *
69  */
71 public:
72 
74  virtual ~DerLinUnivers();
75 
78  c.buffersize = 50;
79  c.init = 1;
80  c.squashsize = 0.05;
81  c.someInternalParams = true;
82  c.net = 0;
83  c.motorlayer = -1;
84  return c;
85  }
86 
89  std::vector<Layer> layers;
90  // layers.push_back(Layer(20,0.5,FeedForwardNN::tanh)); // hidden layer
91  layers.push_back(Layer(0,1,FeedForwardNN::tanhr)); // motor layer
92  // size of output layer is automatically set
93  layers.push_back(Layer(1,0,FeedForwardNN::linear));
94 
95  Elman* e = new Elman(1,layers,false, false, false);
96  c.net = e;
97  return c;
98  }
99 
100  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
101 
102  virtual int getSensorNumber() const {return number_sensors;}
103 
104  virtual int getMotorNumber() const {return number_motors;}
105 
106  virtual void step(const sensor* sensors, int sensornumber,
107  motor* motors, int motornumber);
108 
109  virtual void stepNoLearning(const sensor* , int number_sensors,
110  motor* , int number_motors);
111 
112 protected:
113  /** puts the sensors in the ringbuffer,
114  generate controller values (by activating the network) and put them in the
115  ringbuffer as well */
116  void fillBuffersAndControl(const sensor* x_, int number_sensors,
117  motor* y_, int number_motors);
118 
119  /// calculate time-smoothed values
121  int number_steps_for_averaging_);
122 
123  /// calculate controller outputs (and activates inputs)
125 
126  // put new value in ring buffer
127  void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay=0){
128  buffer[(t-delay)%conf.buffersize] = vec;
129  }
130 
131  /** calculates the error_factor for
132  1: square (E=sqrt(e^t*e)) error;
133  2: logarithmic (E=ln(e^T*e)) or 0 for normal
134  */
135  static double calcErrorFactor(const matrix::Matrix& e, int Enorm);
136 
137 
138 public:
139  /********* INSPECTABLE INTERFACE ******/
140  virtual std::list<iparamkey> getInternalParamNames() const;
141  virtual std::list<iparamval> getInternalParams() const;
142  virtual ilayerlist getStructuralLayers() const;
144 
145  /********* STORABLE INTERFACE ******/
146  virtual bool store(FILE* f) const;
147  virtual bool restore(FILE* f);
148 
149 protected:
150 
151  unsigned int t;
152  unsigned int number_sensors;
153  unsigned int number_motors;
155 
160 
164 
173 };
174 
175 #endif
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning.
Definition: derlinunivers.cpp:178
unsigned int number_sensors
Definition: derlinunivers.h:152
Matrix type.
Definition: matrix.h:65
static double tanhr(double z)
Definition: feedforwardnn.h:67
unsigned int number_motors
Definition: derlinunivers.h:153
std::list< IConnection > iconnectionlist
Definition: inspectable.h:88
virtual iconnectionlist getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: derlinunivers.cpp:282
Definition: layer.h:31
paramval epsM
Definition: derlinunivers.h:166
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
matrix::Matrix * y_buffer
Definition: derlinunivers.h:158
paramval s4avg
Definition: derlinunivers.h:169
paramval Enorm
Definition: derlinunivers.h:171
struct _DerLinUniversConf DerLinUniversConf
double sensor
Definition: types.h:29
bool initialised
Definition: derlinunivers.h:154
void putInBuffer(matrix::Matrix *buffer, const matrix::Matrix &vec, int delay=0)
Definition: derlinunivers.h:127
bool someInternalParams
someInternalParams if true only some internal parameters are exported, all otherwise ...
Definition: derlinunivers.h:58
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
paramval eps
Definition: derlinunivers.h:165
virtual ilayerlist getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: derlinunivers.cpp:278
void fillBuffersAndControl(const sensor *x_, int number_sensors, motor *y_, int number_motors)
puts the sensors in the ringbuffer, generate controller values (by activating the network) and put th...
Definition: derlinunivers.cpp:185
matrix::Matrix * x_buffer
Definition: derlinunivers.h:157
double paramval
Definition: configurable.h:88
Multilayer Neural Network with context neurons (after Elman and Jordan) Example of 2 hidden layer net...
Definition: elman.h:58
matrix::Matrix * v_buffer
Definition: derlinunivers.h:159
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: derlinunivers.cpp:244
int motorlayer
index of motor layer in the network (if -1 then one but last layer)
Definition: derlinunivers.h:61
virtual std::list< iparamkey > getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: derlinunivers.cpp:254
DerLinUniversConf conf
Definition: derlinunivers.h:156
virtual ~DerLinUnivers()
Definition: derlinunivers.cpp:51
paramval epsDyn
Definition: derlinunivers.h:172
virtual int getMotorNumber() const
Definition: derlinunivers.h:104
DerLinUnivers(const DerLinUniversConf &conf=getDefaultConf())
Definition: derlinunivers.cpp:33
virtual int getSensorNumber() const
Definition: derlinunivers.h:102
matrix::Matrix xsi_smooth
Definition: derlinunivers.h:163
Definition: derlinunivers.h:54
matrix::Matrix v
Definition: derlinunivers.h:161
class for robot control with sine and cosine
Definition: derlinunivers.h:70
Elman * net
entire contoller network (should have at least 2 layers)
Definition: derlinunivers.h:60
static DerLinUniversConf getDefaultConf()
Definition: derlinunivers.h:76
double motor
Definition: types.h:30
double init
init size of the matrices of the network.
Definition: derlinunivers.h:56
unsigned int buffersize
buffersize size of the time-buffer for x,y,v
Definition: derlinunivers.h:55
paramval s4del
Definition: derlinunivers.h:170
paramval epsV
Definition: derlinunivers.h:167
static DerLinUniversConf getDefaultNetConf()
Definition: derlinunivers.h:87
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
initialisation of the controller with the given sensor/ motornumber Must be called before use...
Definition: derlinunivers.cpp:59
static double linear(double z)
Definition: feedforwardnn.h:54
double squashsize
update squashing
Definition: derlinunivers.h:57
std::list< ILayer > ilayerlist
Definition: inspectable.h:87
matrix::Matrix calculateControllerValues(const matrix::Matrix &x)
calculate controller outputs (and activates inputs)
Definition: derlinunivers.cpp:206
matrix::Matrix J
Definition: derlinunivers.h:162
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: derlinunivers.cpp:94
int c
Definition: hexapod.cpp:56
virtual std::list< iparamval > getInternalParams() const
Definition: derlinunivers.cpp:266
unsigned int t
Definition: derlinunivers.h:151
paramval lambda
Definition: derlinunivers.h:168
matrix::Matrix calculateSmoothValues(const matrix::Matrix *buffer, int number_steps_for_averaging_)
calculate time-smoothed values
Definition: derlinunivers.cpp:213
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: derlinunivers.cpp:237
static double calcErrorFactor(const matrix::Matrix &e, int Enorm)
calculates the error_factor for 1: square (E=sqrt(e^t*e)) error; 2: logarithmic (E=ln(e^T*e)) or 0 fo...
Definition: derlinunivers.cpp:226