Robot Simulator of the Robotics Group for Self-Organization of Control: abstractiafcontroller.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# abstractiafcontroller.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *    guettler@informatik.uni-leipzig.de                                   *
    00007  *                                                                         *
    00008  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00009  *   LICENSE:                                                              *
    00010  *   This work is licensed under the Creative Commons                      *
    00011  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00012  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00013  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00014  *   San Francisco, California, 94105, USA.                                *
    00015  *                                                                         *
    00016  *   This program is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00019  *                                                                         *
    00020  *   $Log: abstractiafcontroller.h,v $
    00021  *   Revision 1.3  2009/03/11 11:56:33  guettler
    00022  *   added some comment
    00023  *
    00024  *   Revision 1.2  2008/05/05 13:45:32  guettler
    00025  *   -tristateiafcontroller moved to ode_robots/simulations/iafsim
    00026  *   -this iafcontroller implements a new, more realistic iaf model
    00027  *   still first approaches
    00028  *
    00029  *   Revision 1.1  2008/04/30 14:56:27  guettler
    00030  *   neuron population support, other improvements
    00031  *
    00032  *   Revision 1.7  2008/04/29 15:31:57  guettler
    00033  *   tristate try
    00034  *
    00035  *   Revision 1.6  2008/04/29 11:06:48  guettler
    00036  *   adjusted to changes of matrix.h
    00037  *
    00038  *   Revision 1.5  2008/04/29 07:31:41  guettler
    00039  *   improvements
    00040  *
    00041  *   Revision 1.4  2008/04/28 10:31:11  guettler
    00042  *   first working version, still incomplete
    00043  *
    00044  *   Revision 1.3  2008/04/28 06:55:20  guettler
    00045  *   some advancements
    00046  *
    00047  *   Revision 1.2  2008/04/25 10:36:48  guettler
    00048  *   bugfix
    00049  *
    00050  *   Revision 1.1  2008/04/25 10:31:50  guettler
    00051  *   first version
    00052  *
    00053  *                                                                         *
    00054  ***************************************************************************/
    00055 #ifndef __ABSTRACTIAFCONTROLLER_H
    00056 #define __ABSTRACTIAFCONTROLLER_H
    00057
    00058 #include "abstractcontroller.h"
    00059
    00060 #include <selforg/matrix.h>
    00061 #include "controller_misc.h"
    00062 #include <selforg/configurable.h>
    00063
    00064 typedef struct AbstractIAFControllerConf {
    00065   AbstractIAFControllerConf() {
    00066     thresholdI=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00067     thresholdO=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00068     leakI=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00069     leakO=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00070     restingPotential=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00071     wIInitScale=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00072     wOInitScale=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00073     numberIAFNeuronsPerInput=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00074     numberIAFNeuronsPerOutput=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
    00075   }
    00076   ~AbstractIAFControllerConf() {
    00077     /*  if(thresholdI) free(thresholdI);
    00078     if(thresholdO) free(thresholdO);
    00079     if(leakI) free(leakI);
    00080     if(leakO) free(leakO);*/
    00081   }
    00082   Configurable::paramval* numberIAFNeuronsPerInput;  ///< simulate a population if >1
    00083   Configurable::paramval* numberIAFNeuronsPerOutput; ///< simulate a population if >1
    00084   Configurable::paramval* wIInitScale;            ///< scaling factor of weights, initialized random
    00085   Configurable::paramval* wOInitScale;            ///< between [-1*wInitScale,1*wInitScale]
    00086   Configurable::paramval* thresholdI;
    00087   Configurable::paramval* thresholdO;
    00088   Configurable::paramval* leakI;
    00089   Configurable::paramval* leakO;
    00090   Configurable::paramval* restingPotential;
    00091   //Configurable::paramval* test;
    00092 } AbstractIAFControllerConf;
    00093
    00094
    00095 /**
    00096  * Abstract class (interface) for robot controller that uses an integrate
    00097  * and fire neuron model
    00098  *
    00099  * Implements (assumes) that the sensor values are only 0 or 1.
    00100  * Implements standard configureable interface for some useful parameters
    00101  * like leakI and leakO (input and output layer)
    00102  */
    00103 class AbstractIAFController : public AbstractController {
    00104
    00105 public:
    00106   AbstractIAFController(const AbstractIAFControllerConf& conf = getDefaultConf());
    00107
    00108   virtual ~AbstractIAFController() {}
    00109
    00110
    00111   static AbstractIAFControllerConf getDefaultConf(){
    00112     AbstractIAFControllerConf c;
    00113     *c.numberIAFNeuronsPerInput  = 10;
    00114     *c.numberIAFNeuronsPerOutput = 10;
    00115     *c.wIInitScale= 0.5;
    00116     *c.wOInitScale= 0.5;
    00117     *c.thresholdI=0.5;
    00118     *c.thresholdO=0.5;
    00119     *c.leakI=0.01;
    00120     *c.leakO=0.01;
    00121     *c.restingPotential=0.0;
    00122
    00123     return c;
    00124   }
    00125
    00126
    00127   /// ABSTRACTCONTROLLER INTERFACE
    00128
    00129   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00130
    00131   virtual int getSensorNumber() const { return sensorNumber; }
    00132
    00133   virtual int getMotorNumber() const { return motorNumber; }
    00134
    00135   virtual void step(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
    00136
    00137   virtual void stepNoLearning(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
    00138
    00139   /// STORABLE INTERFACE
    00140
    00141   virtual bool store(FILE* f) const { return true; }
    00142
    00143   virtual bool restore(FILE* f) { return true; }
    00144
    00145   /// CONFIGURABLE INTERFACE
    00146   virtual bool setParam(const paramkey& key, paramval val);
    00147
    00148 protected:
    00149   AbstractIAFControllerConf conf;
    00150   RandGen* randG;
    00151   bool initialised;
    00152   int sensorNumber;
    00153   int motorNumber;
    00154   double range;
    00155   matrix::Matrix xI; // matrix with input for the input layer neurons
    00156   matrix::Matrix xO; // matrix with input for the output layer neurons
    00157   matrix::Matrix wI; // matrix with weights of the input layer neurons, incl.leak
    00158   matrix::Matrix wO; // matrix with weights of the output layer neurons, incl.leak
    00159   matrix::Matrix sumI; // matrix with current sums of the input layer neurons
    00160   matrix::Matrix sumO; // matrix with current sums of the output layer neurons
    00161   matrix::Matrix tI; // matrix with threshold value of the input layer neurons
    00162   matrix::Matrix tO; // matrix with threshold value of the output layer neurons
    00163
    00164   /**
    00165    * makes a forward step (without any learning)
    00166    */
    00167   virtual void forwardStep(const sensor* sensors, int number_sensors, motor* motors, int number_motors);
    00168
    00169   /**
    00170    * inits the internal used matrices
    00171    * If you change something on dimensions, you should call
    00172    * this function.
    00173    * @note that all learned weights are lost.
    00174    */
    00175   void initMatrices();
    00176
    00177
    00178
    00179
    00180   /// returns -1 if probability is to low, otherwise 1 for mapP
    00181   static double toTristateWithProbability(void* r,double x) {
    00182     RandGen* g = (RandGen*) r;
    00183     if (!g) return 0.;
    00184     double rand = g->rand();
    00185     return x < -rand ? -1. : (x < rand ? 0. : 1.);
    00186   }
    00187
    00188   /// returns -1 if below -threshold, 0 if above -threshold
    00189   /// and threshold, otherwise 1, for map2
    00190   static double toTristateWithThreshold(double x, double threshold){
    00191     return x < -threshold ? -1. : (x < threshold ? 0. : 1.);
    00192   }
    00193
    00194   /// damps the value, if <0, damp value is added
    00195   /// if >0, damp value is subtracted
    00196   /// and threshold, otherwise 1, for map2
    00197   static double dampToZero(void* r, double x){
    00198     double damp = *(double*)r;
    00199     return x < -damp ? x+damp : (x > damp ? x-damp : 0.);
    00200   }
    00201
    00202   // returns 0 if fired==1 (-1 or 1), otherwise x
    00203   static double toZeroIfFired(double x, double fired) {
    00204     return (fired==1 || fired==-1) ? 0 : x ;
    00205   }
    00206
    00207     // returns value if fired==1 (-1 or 1), otherwise x
    00208   static double toValueIfFired(void* r,double x, double fired) {
    00209     double value = *(double*)r;
    00210     return (fired==1 || fired==-1) ? value : x ;
    00211   }
    00212
    00213
    00214   /// returns 0 if probability is to low, otherwise 1 for mapP
    00215   static double toDualStateWithProbability(void* r,double x) {
    00216     RandGen* g = (RandGen*) r;
    00217     if (!g) return 0.;
    00218     double rand = g->rand();
    00219     return x < rand ? 0. : 1.;
    00220   }
    00221
    00222     /// returns 0 if below threshold, otherwise 1, for map2
    00223   static double toDualStateWithThreshold(double x, double threshold){
    00224     return x < threshold ? 0. : 1.;
    00225   }
    00226
    00227
    00228
    00229
    00230 };
    00231
    00232
    00233 #endif