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
invertnchannelcontroller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
5  * Ralf Der <ralfder at mis dot mpg dot de> *
6  * *
7  * ANY COMMERCIAL USE FORBIDDEN! *
8  * LICENSE: *
9  * This work is licensed under the Creative Commons *
10  * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of *
11  * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
12  * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, *
13  * San Francisco, California, 94105, USA. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
18  * *
19  ***************************************************************************/
20 #ifndef __INVERTNCHANNELCONTROLLER_H
21 #define __INVERTNCHANNELCONTROLLER_H
22 
23 #include "invertcontroller.h"
24 #include "controller_misc.h"
25 
26 #include <assert.h>
27 #include <cmath>
28 
29 #include <selforg/matrix.h>
30 
31 /**
32  * class for robot controller that uses the georg's matrixlib for
33  * direct matrix inversion for n channels
34  * (simple one layer networks)
35  *
36  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
37  */
39 
40 public:
41  InvertNChannelController(int _buffersize, bool _update_only_1=false);
42  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
43 
44  virtual ~InvertNChannelController();
45 
46  /// returns the name of the object (with version number)
47  virtual paramkey getName() const {return name; }
48  /// returns the number of sensors the controller was initialised with or 0 if not initialised
49  virtual int getSensorNumber() const { return number_channels; }
50  /// returns the mumber of motors the controller was initialised with or 0 if not initialised
51  virtual int getMotorNumber() const { return number_channels; }
52 
53  /// performs one step (includes learning).
54  /// Calulates motor commands from sensor inputs.
55  virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
56 
57 
58  /// performs one step without learning. Calulates motor commands from sensor inputs.
59  virtual void stepNoLearning(const sensor* , int number_sensors,
60  motor* , int number_motors);
61 
62 
63  /***** STOREABLE ****/
64  /** stores the controller values to a given file. */
65  virtual bool store(FILE* f) const;
66  /** loads the controller values from a given file. */
67  virtual bool restore(FILE* f);
68 
69  // inspectable interface
70  virtual std::list<ILayer> getStructuralLayers() const;
71  virtual std::list<IConnection> getStructuralConnections() const;
72 
73 
74 protected:
75  unsigned short number_channels;
76  unsigned short buffersize;
78 
79  matrix::Matrix A; // Model Matrix
80  matrix::Matrix C; // Controller Matrix
81  matrix::Matrix h; // Controller Bias
82  matrix::Matrix L; // Jacobi Matrix
85  int t;
87 
88 
89 /* virtual void iteration(double *column, */
90 /* double dommy[NUMBER_CHANNELS][NUMBER_CHANNELS], */
91 /* double *improvment); */
92 
93  virtual double calculateE(const matrix::Matrix& x_delay, const matrix::Matrix& y_delay);
94 
95  /// learn values h,C
96  virtual void learn(const matrix::Matrix& x_delay, const matrix::Matrix& y_delay);
97 
98  virtual void learnmodel( const matrix::Matrix& y_delay);
99 
100  /// calculate delayed values
102  unsigned int number_steps_of_delay_);
104  unsigned int number_steps_for_averaging_);
105 
107 
108  // put new value in ring buffer
109  void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec);
110 
111  /// neuron transfer function
112  static double g(double z)
113  {
114  return tanh(z);
115  };
116 
117  ///
118  static double g_s(double z)
119  {
120  double k=tanh(z);
121  return 1.0 - k*k;
122  // return 1.0 - tanh(z)*tanh(z);
123  };
124 
125 
126 
127  /// squashing function, to protect against to large weight updates
128  static double squash(double z)
129  {
130  return clip(z,-0.1,0.1);
131  // return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z );
132  //return 0.1 * tanh(10.0 * z);
133  };
134 };
135 
136 #endif
137 
138 
Matrix type.
Definition: matrix.h:65
matrix::Matrix L
Definition: invertnchannelcontroller.h:82
std::string paramkey
Definition: configurable.h:85
static double squash(double z)
squashing function, to protect against to large weight updates
Definition: invertnchannelcontroller.h:128
static double g(double z)
neuron transfer function
Definition: invertnchannelcontroller.h:112
virtual paramkey getName() const
returns the name of the object (with version number)
Definition: invertnchannelcontroller.h:47
InvertNChannelController(int _buffersize, bool _update_only_1=false)
Definition: invertnchannelcontroller.cpp:26
int t
Definition: invertnchannelcontroller.h:85
double sensor
Definition: types.h:29
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
unsigned short buffersize
Definition: invertnchannelcontroller.h:76
matrix::Matrix C
Definition: invertnchannelcontroller.h:80
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: invertnchannelcontroller.cpp:44
virtual double calculateE(const matrix::Matrix &x_delay, const matrix::Matrix &y_delay)
Definition: invertnchannelcontroller.cpp:163
virtual ~InvertNChannelController()
Definition: invertnchannelcontroller.cpp:39
virtual void learn(const matrix::Matrix &x_delay, const matrix::Matrix &y_delay)
learn values h,C
Definition: invertnchannelcontroller.cpp:233
matrix::Matrix * x_buffer
Definition: invertnchannelcontroller.h:83
static double g_s(double z)
Definition: invertnchannelcontroller.h:118
virtual bool restore(FILE *f)
loads the controller values from a given file.
Definition: invertnchannelcontroller.cpp:324
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning. Calulates motor commands from sensor inputs.
Definition: invertnchannelcontroller.cpp:86
paramkey name
Definition: invertnchannelcontroller.h:86
class for robot controller that uses the georg's matrixlib for direct matrix inversion for n channels...
Definition: invertnchannelcontroller.h:38
matrix::Matrix * y_buffer
Definition: invertnchannelcontroller.h:84
virtual std::list< IConnection > getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: invertnchannelcontroller.cpp:343
double clip(double r, double x)
clipping function for mapP
Definition: controller_misc.cpp:39
virtual matrix::Matrix calculateDelayedValues(const matrix::Matrix *buffer, unsigned int number_steps_of_delay_)
calculate delayed values
Definition: invertnchannelcontroller.cpp:280
unsigned short number_channels
Definition: invertnchannelcontroller.h:75
matrix::Matrix h
Definition: invertnchannelcontroller.h:81
virtual int getMotorNumber() const
returns the mumber of motors the controller was initialised with or 0 if not initialised ...
Definition: invertnchannelcontroller.h:51
matrix::Matrix calculateControllerValues(const matrix::Matrix &x_smooth)
calculate controller outputs
Definition: invertnchannelcontroller.cpp:303
double motor
Definition: types.h:30
virtual bool store(FILE *f) const
stores the controller values to a given file.
Definition: invertnchannelcontroller.cpp:314
virtual void step(const sensor *, int number_sensors, motor *, int number_motors)
performs one step (includes learning).
Definition: invertnchannelcontroller.cpp:66
virtual std::list< ILayer > getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: invertnchannelcontroller.cpp:335
virtual matrix::Matrix calculateSmoothValues(const matrix::Matrix *buffer, unsigned int number_steps_for_averaging_)
Definition: invertnchannelcontroller.cpp:287
Abstract class (interface) for robot controller that use direct matrix inversion and simple one layer...
Definition: invertcontroller.h:33
virtual int getSensorNumber() const
returns the number of sensors the controller was initialised with or 0 if not initialised ...
Definition: invertnchannelcontroller.h:49
virtual void learnmodel(const matrix::Matrix &y_delay)
Definition: invertnchannelcontroller.cpp:274
matrix::Matrix A
Definition: invertnchannelcontroller.h:79
void putInBuffer(matrix::Matrix *buffer, const matrix::Matrix &vec)
Definition: invertnchannelcontroller.cpp:309
bool update_only_1
Definition: invertnchannelcontroller.h:77