abstractiafcontroller.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __ABSTRACTIAFCONTROLLER_H
00022 #define __ABSTRACTIAFCONTROLLER_H
00023
00024 #include "abstractcontroller.h"
00025
00026 #include <selforg/matrix.h>
00027 #include "controller_misc.h"
00028 #include <selforg/configurable.h>
00029
00030 typedef struct AbstractIAFControllerConf {
00031 AbstractIAFControllerConf() {
00032 thresholdI=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00033 thresholdO=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00034 leakI=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00035 leakO=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00036 restingPotential=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00037 wIInitScale=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00038 wOInitScale=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00039 numberIAFNeuronsPerInput=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00040 numberIAFNeuronsPerOutput=(Configurable::paramval*) malloc(sizeof(Configurable::paramval));
00041 }
00042 ~AbstractIAFControllerConf() {
00043
00044
00045
00046
00047 }
00048 Configurable::paramval* numberIAFNeuronsPerInput;
00049 Configurable::paramval* numberIAFNeuronsPerOutput;
00050 Configurable::paramval* wIInitScale;
00051 Configurable::paramval* wOInitScale;
00052 Configurable::paramval* thresholdI;
00053 Configurable::paramval* thresholdO;
00054 Configurable::paramval* leakI;
00055 Configurable::paramval* leakO;
00056 Configurable::paramval* restingPotential;
00057
00058 } AbstractIAFControllerConf;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 class AbstractIAFController : public AbstractController {
00070
00071 public:
00072 AbstractIAFController(const AbstractIAFControllerConf& conf = getDefaultConf());
00073
00074 virtual ~AbstractIAFController() {}
00075
00076
00077 static AbstractIAFControllerConf getDefaultConf(){
00078 AbstractIAFControllerConf c;
00079 *c.numberIAFNeuronsPerInput = 10;
00080 *c.numberIAFNeuronsPerOutput = 10;
00081 *c.wIInitScale= 0.5;
00082 *c.wOInitScale= 0.5;
00083 *c.thresholdI=0.5;
00084 *c.thresholdO=0.5;
00085 *c.leakI=0.01;
00086 *c.leakO=0.01;
00087 *c.restingPotential=0.0;
00088
00089 return c;
00090 }
00091
00092
00093
00094
00095 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00096
00097 virtual int getSensorNumber() const { return sensorNumber; }
00098
00099 virtual int getMotorNumber() const { return motorNumber; }
00100
00101 virtual void step(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
00102
00103 virtual void stepNoLearning(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
00104
00105
00106
00107 virtual bool store(FILE* f) const { return true; }
00108
00109 virtual bool restore(FILE* f) { return true; }
00110
00111
00112 virtual void notifyOnChange(const paramkey& key);
00113
00114 protected:
00115 AbstractIAFControllerConf conf;
00116 RandGen* randG;
00117 bool initialised;
00118 int sensorNumber;
00119 int motorNumber;
00120 double range;
00121 matrix::Matrix xI;
00122 matrix::Matrix xO;
00123 matrix::Matrix wI;
00124 matrix::Matrix wO;
00125 matrix::Matrix sumI;
00126 matrix::Matrix sumO;
00127 matrix::Matrix tI;
00128 matrix::Matrix tO;
00129
00130
00131
00132
00133 virtual void forwardStep(const sensor* sensors, int number_sensors, motor* motors, int number_motors);
00134
00135
00136
00137
00138
00139
00140
00141 void initMatrices();
00142
00143
00144
00145
00146
00147 static double toTristateWithProbability(void* r,double x) {
00148 RandGen* g = (RandGen*) r;
00149 if (!g) return 0.;
00150 double rand = g->rand();
00151 return x < -rand ? -1. : (x < rand ? 0. : 1.);
00152 }
00153
00154
00155
00156 static double toTristateWithThreshold(double x, double threshold){
00157 return x < -threshold ? -1. : (x < threshold ? 0. : 1.);
00158 }
00159
00160
00161
00162
00163 static double dampToZero(void* r, double x){
00164 double damp = *(double*)r;
00165 return x < -damp ? x+damp : (x > damp ? x-damp : 0.);
00166 }
00167
00168
00169 static double toZeroIfFired(double x, double fired) {
00170 return (fired==1 || fired==-1) ? 0 : x ;
00171 }
00172
00173
00174 static double toValueIfFired(void* r,double x, double fired) {
00175 double value = *(double*)r;
00176 return (fired==1 || fired==-1) ? value : x ;
00177 }
00178
00179
00180
00181 static double toDualStateWithProbability(void* r,double x) {
00182 RandGen* g = (RandGen*) r;
00183 if (!g) return 0.;
00184 double rand = g->rand();
00185 return x < rand ? 0. : 1.;
00186 }
00187
00188
00189 static double toDualStateWithThreshold(double x, double threshold){
00190 return x < threshold ? 0. : 1.;
00191 }
00192
00193
00194
00195
00196 };
00197
00198
00199 #endif