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
abstractiafcontroller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by *
3  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
4  * Georg Martius <georg dot martius at web 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  * ANY COMMERCIAL USE FORBIDDEN! *
9  * LICENSE: *
10  * This work is licensed under the Creative Commons *
11  * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of *
12  * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
13  * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, *
14  * San Francisco, California, 94105, USA. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
19  * *
20  ***************************************************************************/
21 #ifndef __ABSTRACTIAFCONTROLLER_H
22 #define __ABSTRACTIAFCONTROLLER_H
23 
24 #include "abstractcontroller.h"
25 
26 #include <selforg/matrix.h>
27 #include "controller_misc.h"
28 #include <selforg/configurable.h>
29 
30 typedef struct AbstractIAFControllerConf {
41  }
43  /* if(thresholdI) free(thresholdI);
44  if(thresholdO) free(thresholdO);
45  if(leakI) free(leakI);
46  if(leakO) free(leakO);*/
47  }
48  Configurable::paramval* numberIAFNeuronsPerInput; ///< simulate a population if >1
49  Configurable::paramval* numberIAFNeuronsPerOutput; ///< simulate a population if >1
50  Configurable::paramval* wIInitScale; ///< scaling factor of weights, initialized random
51  Configurable::paramval* wOInitScale; ///< between [-1*wInitScale,1*wInitScale]
57  //Configurable::paramval* test;
59 
60 
61 /**
62  * Abstract class (interface) for robot controller that uses an integrate
63  * and fire neuron model
64  *
65  * Implements (assumes) that the sensor values are only 0 or 1.
66  * Implements standard configureable interface for some useful parameters
67  * like leakI and leakO (input and output layer)
68  */
70 
71 public:
73 
75 
76 
81  *c.wIInitScale= 0.5;
82  *c.wOInitScale= 0.5;
83  *c.thresholdI=0.5;
84  *c.thresholdO=0.5;
85  *c.leakI=0.01;
86  *c.leakO=0.01;
87  *c.restingPotential=0.0;
88 
89  return c;
90  }
91 
92 
93  /// ABSTRACTCONTROLLER INTERFACE
94 
95  virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
96 
97  virtual int getSensorNumber() const { return sensorNumber; }
98 
99  virtual int getMotorNumber() const { return motorNumber; }
100 
101  virtual void step(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
102 
103  virtual void stepNoLearning(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
104 
105  /// STORABLE INTERFACE
106 
107  virtual bool store(FILE* f) const { return true; }
108 
109  virtual bool restore(FILE* f) { return true; }
110 
111  /// CONFIGURABLE INTERFACE
112  virtual void notifyOnChange(const paramkey& key);
113 
114 protected:
120  double range;
121  matrix::Matrix xI; // matrix with input for the input layer neurons
122  matrix::Matrix xO; // matrix with input for the output layer neurons
123  matrix::Matrix wI; // matrix with weights of the input layer neurons, incl.leak
124  matrix::Matrix wO; // matrix with weights of the output layer neurons, incl.leak
125  matrix::Matrix sumI; // matrix with current sums of the input layer neurons
126  matrix::Matrix sumO; // matrix with current sums of the output layer neurons
127  matrix::Matrix tI; // matrix with threshold value of the input layer neurons
128  matrix::Matrix tO; // matrix with threshold value of the output layer neurons
129 
130  /**
131  * makes a forward step (without any learning)
132  */
133  virtual void forwardStep(const sensor* sensors, int number_sensors, motor* motors, int number_motors);
134 
135  /**
136  * inits the internal used matrices
137  * If you change something on dimensions, you should call
138  * this function.
139  * @note that all learned weights are lost.
140  */
141  void initMatrices();
142 
143 
144 
145 
146  /// returns -1 if probability is to low, otherwise 1 for mapP
147  static double toTristateWithProbability(void* r,double x) {
148  RandGen* g = (RandGen*) r;
149  if (!g) return 0.;
150  double rand = g->rand();
151  return x < -rand ? -1. : (x < rand ? 0. : 1.);
152  }
153 
154  /// returns -1 if below -threshold, 0 if above -threshold
155  /// and threshold, otherwise 1, for map2
156  static double toTristateWithThreshold(double x, double threshold){
157  return x < -threshold ? -1. : (x < threshold ? 0. : 1.);
158  }
159 
160  /// damps the value, if <0, damp value is added
161  /// if >0, damp value is subtracted
162  /// and threshold, otherwise 1, for map2
163  static double dampToZero(void* r, double x){
164  double damp = *(double*)r;
165  return x < -damp ? x+damp : (x > damp ? x-damp : 0.);
166  }
167 
168  // returns 0 if fired==1 (-1 or 1), otherwise x
169  static double toZeroIfFired(double x, double fired) {
170  return (fired==1 || fired==-1) ? 0 : x ;
171  }
172 
173  // returns value if fired==1 (-1 or 1), otherwise x
174  static double toValueIfFired(void* r,double x, double fired) {
175  double value = *(double*)r;
176  return (fired==1 || fired==-1) ? value : x ;
177  }
178 
179 
180  /// returns 0 if probability is to low, otherwise 1 for mapP
181  static double toDualStateWithProbability(void* r,double x) {
182  RandGen* g = (RandGen*) r;
183  if (!g) return 0.;
184  double rand = g->rand();
185  return x < rand ? 0. : 1.;
186  }
187 
188  /// returns 0 if below threshold, otherwise 1, for map2
189  static double toDualStateWithThreshold(double x, double threshold){
190  return x < threshold ? 0. : 1.;
191  }
192 
193 
194 
195 
196 };
197 
198 
199 #endif
Matrix type.
Definition: matrix.h:65
double range
Definition: abstractiafcontroller.h:120
double rand()
returns a value in [0,1)
Definition: randomgenerator.h:42
Configurable::paramval * numberIAFNeuronsPerOutput
simulate a population if >1
Definition: abstractiafcontroller.h:49
virtual int getSensorNumber() const
Definition: abstractiafcontroller.h:97
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
static double toTristateWithThreshold(double x, double threshold)
returns -1 if below -threshold, 0 if above -threshold and threshold, otherwise 1, for map2 ...
Definition: abstractiafcontroller.h:156
charArray paramkey
Definition: avrtypes.h:36
static double toDualStateWithThreshold(double x, double threshold)
returns 0 if below threshold, otherwise 1, for map2
Definition: abstractiafcontroller.h:189
Configurable::paramval * leakI
Definition: abstractiafcontroller.h:54
double sensor
Definition: types.h:29
~AbstractIAFControllerConf()
Definition: abstractiafcontroller.h:42
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
static double toDualStateWithProbability(void *r, double x)
returns 0 if probability is to low, otherwise 1 for mapP
Definition: abstractiafcontroller.h:181
virtual ~AbstractIAFController()
Definition: abstractiafcontroller.h:74
Configurable::paramval * wIInitScale
scaling factor of weights, initialized random
Definition: abstractiafcontroller.h:50
Configurable::paramval * wOInitScale
between [-1*wInitScale,1*wInitScale]
Definition: abstractiafcontroller.h:51
virtual void init(int sensornumber, int motornumber, RandGen *randGen=0)
ABSTRACTCONTROLLER INTERFACE.
Definition: abstractiafcontroller.cpp:51
RandGen * randG
Definition: abstractiafcontroller.h:116
virtual void stepNoLearning(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step without learning.
Definition: abstractiafcontroller.cpp:66
static double dampToZero(void *r, double x)
damps the value, if <0, damp value is added if >0, damp value is subtracted and threshold, otherwise 1, for map2
Definition: abstractiafcontroller.h:163
virtual bool store(FILE *f) const
STORABLE INTERFACE.
Definition: abstractiafcontroller.h:107
double sensor
Definition: abstractcontroller.h:48
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: abstractiafcontroller.cpp:62
matrix::Matrix tI
Definition: abstractiafcontroller.h:127
static double toZeroIfFired(double x, double fired)
Definition: abstractiafcontroller.h:169
double paramval
Definition: configurable.h:88
matrix::Matrix wO
Definition: abstractiafcontroller.h:124
matrix::Matrix xO
Definition: abstractiafcontroller.h:122
matrix::Matrix tO
Definition: abstractiafcontroller.h:128
static double toTristateWithProbability(void *r, double x)
returns -1 if probability is to low, otherwise 1 for mapP
Definition: abstractiafcontroller.h:147
AbstractIAFControllerConf conf
Definition: abstractiafcontroller.h:115
Configurable::paramval * thresholdO
Definition: abstractiafcontroller.h:53
matrix::Matrix wI
Definition: abstractiafcontroller.h:123
void initMatrices()
inits the internal used matrices If you change something on dimensions, you should call this function...
Definition: abstractiafcontroller.cpp:145
static double toValueIfFired(void *r, double x, double fired)
Definition: abstractiafcontroller.h:174
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: abstractiafcontroller.h:109
double g(double z)
neuron transfer function
Definition: regularisation.h:35
struct AbstractIAFControllerConf AbstractIAFControllerConf
virtual void forwardStep(const sensor *sensors, int number_sensors, motor *motors, int number_motors)
makes a forward step (without any learning)
Definition: abstractiafcontroller.cpp:88
AbstractIAFController(const AbstractIAFControllerConf &conf=getDefaultConf())
Definition: abstractiafcontroller.cpp:25
Definition: abstractiafcontroller.h:30
double motor
Definition: types.h:30
virtual void notifyOnChange(const paramkey &key)
CONFIGURABLE INTERFACE.
Definition: abstractiafcontroller.cpp:71
matrix::Matrix sumO
Definition: abstractiafcontroller.h:126
matrix::Matrix sumI
Definition: abstractiafcontroller.h:125
Configurable::paramval * leakO
Definition: abstractiafcontroller.h:55
int motorNumber
Definition: abstractiafcontroller.h:119
bool initialised
Definition: abstractiafcontroller.h:117
Configurable::paramval * restingPotential
Definition: abstractiafcontroller.h:56
Configurable::paramval * numberIAFNeuronsPerInput
simulate a population if >1
Definition: abstractiafcontroller.h:48
Configurable::paramval * thresholdI
Definition: abstractiafcontroller.h:52
double motor
Definition: abstractcontroller.h:49
virtual int getMotorNumber() const
Definition: abstractiafcontroller.h:99
AbstractIAFControllerConf()
Definition: abstractiafcontroller.h:31
int sensorNumber
Definition: abstractiafcontroller.h:118
static AbstractIAFControllerConf getDefaultConf()
Definition: abstractiafcontroller.h:77
matrix::Matrix xI
Definition: abstractiafcontroller.h:121
int c
Definition: hexapod.cpp:56
Abstract class (interface) for robot controller that uses an integrate and fire neuron model...
Definition: abstractiafcontroller.h:69