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
ffnncontroller.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  * Ralf Der <ralfder at mis dot mpg dot de> *
5  * *
6  * ANY COMMERCIAL USE FORBIDDEN! *
7  * LICENSE: *
8  * This work is licensed under the Creative Commons *
9  * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of *
10  * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
11  * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, *
12  * San Francisco, California, 94105, USA. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17  * *
18  ***************************************************************************/
19 #ifndef __FFNNCONTROLLER_H
20 #define __FFNNCONTROLLER_H
21 
22 #include "abstractcontroller.h"
23 #include <assert.h>
24 #include <cmath>
25 
26 #include <selforg/matrix.h>
27 #include <selforg/multilayerffnn.h>
28 
29 /**
30  * class for robot controller with a fixed neural network
31  */
33 
34 public:
35  /** @param networkfilename file to load the network
36  @param history number of time steps the network gets input (in sense of dimension of input)
37  @param input_only_x if true then the input vector is \f[ (x_{t},x_{t-1},...,x_{t-history})^T \f]
38  if false then also the y values are used: \f[ (x_{t}, y_{t-1}, x_{t-1},y_{t-2},...,x_{t-history})^T \f]
39  @param init_wait number of timesteps to wait before controlling
40  */
41  FFNNController(const std::string& networkfilename, int history, bool input_only_x, unsigned int init_wait=0);
42 
43  /** @param net pointer to network (it must have the right dimensions)
44  @param history number of time steps the network gets input (in sense of dimension of input)
45  @param input_only_x if true then the input vector is \f[ (x_{t},x_{t-1},...,x_{t-history})^T \f]
46  if false then also the y values are used: \f[ (x_{t}, y_{t-1}, x_{t-1},y_{t-2},...,x_{t-history})^T \f]
47  @param init_wait number of timesteps to wait before controlling
48  */
49  FFNNController(MultiLayerFFNN* net, int history, bool input_only_x, unsigned int init_wait=0);
50 
51  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
52 
53  virtual ~FFNNController();
54 
55  /// returns the number of sensors the controller was initialised with or 0 if not initialised
56  virtual int getSensorNumber() const { return number_sensors; }
57  /// returns the mumber of motors the controller was initialised with or 0 if not initialised
58  virtual int getMotorNumber() const { return number_motors; }
59 
60  virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
61  virtual void stepNoLearning(const sensor* , int number_sensors,
62  motor* , int number_motors);
63 
64  /**** CONFIGURABLE ****/
65  void notifyOnChange(const paramkey& key);
66 
67  /**** STOREABLE ****/
68  /** stores the controller values to a given file (binary). */
69  virtual bool store(FILE* f) const;
70  /** loads the controller values from a given file (binary). */
71  virtual bool restore(FILE* f);
72 
73  // inspectable interface
74  virtual std::list<iparamkey> getInternalParamNames()const { return std::list<iparamkey>(); }
75  virtual std::list<iparamval> getInternalParams() const { return std::list<iparamval>(); }
76 
77 protected:
78  void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay = 0);
79 
80  matrix::Matrix calculateSmoothValues(const matrix::Matrix* buffer, int number_steps_for_averaging_) const;
81 
82  virtual matrix::Matrix assembleNetworkInputXY(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
83 
84  virtual matrix::Matrix assembleNetworkInputX(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
85 
86  virtual matrix::Matrix assembleNetworkOutput(const matrix::Matrix& output) const;
87 
88 
89 protected:
90  unsigned short number_motors;
91  unsigned short number_sensors;
92  unsigned short history;
93  unsigned short buffersize;
95  int s4avg;
96  unsigned int t;
97  unsigned int init_wait;
98 
102 
105 
106 };
107 
108 #endif
Matrix type.
Definition: matrix.h:65
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
unsigned short history
Definition: ffnncontroller.h:92
charArray paramkey
Definition: avrtypes.h:36
virtual int getMotorNumber() const
returns the mumber of motors the controller was initialised with or 0 if not initialised ...
Definition: ffnncontroller.h:58
double sensor
Definition: types.h:29
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual std::list< iparamval > getInternalParams() const
Definition: ffnncontroller.h:75
matrix::Matrix x_smooth
Definition: ffnncontroller.h:101
matrix::Matrix * y_buffer
Definition: ffnncontroller.h:100
unsigned short number_sensors
Definition: ffnncontroller.h:91
virtual void stepNoLearning(const sensor *, int number_sensors, motor *, int number_motors)
performs one step without learning.
Definition: ffnncontroller.cpp:65
virtual std::list< iparamkey > getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: ffnncontroller.h:74
FFNNController(const std::string &networkfilename, int history, bool input_only_x, unsigned int init_wait=0)
Definition: ffnncontroller.cpp:6
unsigned short number_motors
Definition: ffnncontroller.h:90
matrix::Matrix * x_buffer
Definition: ffnncontroller.h:99
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: ffnncontroller.cpp:35
virtual matrix::Matrix assembleNetworkInputXY(matrix::Matrix *xbuffer, matrix::Matrix *ybuffer) const
Definition: ffnncontroller.cpp:121
bool input_only_x
Definition: ffnncontroller.h:94
virtual ~FFNNController()
Definition: ffnncontroller.cpp:31
unsigned int t
Definition: ffnncontroller.h:96
matrix::Matrix calculateSmoothValues(const matrix::Matrix *buffer, int number_steps_for_averaging_) const
calculate time-smoothed values
Definition: ffnncontroller.cpp:107
virtual matrix::Matrix assembleNetworkInputX(matrix::Matrix *xbuffer, matrix::Matrix *ybuffer) const
Definition: ffnncontroller.cpp:130
double motor
Definition: types.h:30
virtual matrix::Matrix assembleNetworkOutput(const matrix::Matrix &output) const
Definition: ffnncontroller.cpp:139
virtual bool store(FILE *f) const
stores the controller values to a given file (binary).
Definition: ffnncontroller.cpp:144
unsigned int init_wait
Definition: ffnncontroller.h:97
multi layer neural network with configurable activation functions
Definition: multilayerffnn.h:35
MultiLayerFFNN * net
Definition: ffnncontroller.h:103
int s4avg
Definition: ffnncontroller.h:95
virtual void step(const sensor *, int number_sensors, motor *, int number_motors)
performs one step (includes learning).
Definition: ffnncontroller.cpp:61
bool initialised
Definition: ffnncontroller.h:104
unsigned short buffersize
Definition: ffnncontroller.h:93
void notifyOnChange(const paramkey &key)
Is called when a parameter was changes via setParam().
Definition: ffnncontroller.cpp:153
class for robot controller with a fixed neural network
Definition: ffnncontroller.h:32
virtual bool restore(FILE *f)
loads the controller values from a given file (binary).
Definition: ffnncontroller.cpp:148
virtual int getSensorNumber() const
returns the number of sensors the controller was initialised with or 0 if not initialised ...
Definition: ffnncontroller.h:56
void putInBuffer(matrix::Matrix *buffer, const matrix::Matrix &vec, int delay=0)
Definition: ffnncontroller.cpp:102