00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
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
00078
00079
00080
00081 }
00082 Configurable::paramval* numberIAFNeuronsPerInput;
00083 Configurable::paramval* numberIAFNeuronsPerOutput;
00084 Configurable::paramval* wIInitScale;
00085 Configurable::paramval* wOInitScale;
00086 Configurable::paramval* thresholdI;
00087 Configurable::paramval* thresholdO;
00088 Configurable::paramval* leakI;
00089 Configurable::paramval* leakO;
00090 Configurable::paramval* restingPotential;
00091
00092 } AbstractIAFControllerConf;
00093
00094
00095
00096
00097
00098
00099
00100
00101
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
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
00140
00141 virtual bool store(FILE* f) const { return true; }
00142
00143 virtual bool restore(FILE* f) { return true; }
00144
00145
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;
00156 matrix::Matrix xO;
00157 matrix::Matrix wI;
00158 matrix::Matrix wO;
00159 matrix::Matrix sumI;
00160 matrix::Matrix sumO;
00161 matrix::Matrix tI;
00162 matrix::Matrix tO;
00163
00164
00165
00166
00167 virtual void forwardStep(const sensor* sensors, int number_sensors, motor* motors, int number_motors);
00168
00169
00170
00171
00172
00173
00174
00175 void initMatrices();
00176
00177
00178
00179
00180
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
00189
00190 static double toTristateWithThreshold(double x, double threshold){
00191 return x < -threshold ? -1. : (x < threshold ? 0. : 1.);
00192 }
00193
00194
00195
00196
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
00203 static double toZeroIfFired(double x, double fired) {
00204 return (fired==1 || fired==-1) ? 0 : x ;
00205 }
00206
00207
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
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
00223 static double toDualStateWithThreshold(double x, double threshold){
00224 return x < threshold ? 0. : 1.;
00225 }
00226
00227
00228
00229
00230 };
00231
00232
00233 #endif