soxexpand.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 #ifndef __SOXEXPAND_H
00020 #define __SOXEXPAND_H
00021
00022 #include <selforg/abstractcontroller.h>
00023 #include <selforg/controller_misc.h>
00024
00025 #include <assert.h>
00026 #include <cmath>
00027
00028 #include <selforg/matrix.h>
00029
00030
00031
00032
00033
00034
00035 struct SoxExpandConf {
00036 double initFeedbackStrength;
00037 unsigned int numberContextSensors;
00038 matrix::Matrix contextCoupling;
00039 };
00040
00041
00042
00043
00044
00045
00046 class SoxExpand : public AbstractController {
00047
00048 public:
00049 SoxExpand(const SoxExpandConf& conf = getDefaultConf());
00050 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00051
00052 virtual ~SoxExpand();
00053
00054 static SoxExpandConf getDefaultConf(){
00055 SoxExpandConf c;
00056 c.initFeedbackStrength=1.0;
00057 c.numberContextSensors=0;
00058 return c;
00059 }
00060
00061
00062 virtual int getSensorNumber() const { return number_sensors; }
00063
00064 virtual int getMotorNumber() const { return number_motors; }
00065
00066
00067
00068 virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00069
00070
00071
00072 virtual void stepNoLearning(const sensor* , int number_sensors,
00073 motor* , int number_motors);
00074
00075
00076
00077
00078 virtual bool store(FILE* f) const;
00079
00080 virtual bool restore(FILE* f);
00081
00082
00083 virtual matrix::Matrix getA();
00084 virtual void setA(const matrix::Matrix& A);
00085 virtual matrix::Matrix getC();
00086 virtual void setC(const matrix::Matrix& C);
00087 virtual matrix::Matrix geth();
00088 virtual void seth(const matrix::Matrix& h);
00089 virtual matrix::Matrix getContextC();
00090 virtual void setContextC(const matrix::Matrix& CC);
00091
00092
00093 protected:
00094 unsigned short number_sensors;
00095 unsigned short number_motors;
00096 static const unsigned short buffersize = 10;
00097
00098 matrix::Matrix A;
00099 matrix::Matrix C;
00100 matrix::Matrix S;
00101 matrix::Matrix h;
00102 matrix::Matrix b;
00103 matrix::Matrix L;
00104 matrix::Matrix AC;
00105 matrix::Matrix R;
00106
00107 SoxExpandConf conf;
00108
00109 matrix::Matrix y_buffer[buffersize];
00110 matrix::Matrix x_buffer[buffersize];
00111 matrix::Matrix v_avg;
00112 matrix::Matrix x;
00113 matrix::Matrix x_c;
00114 matrix::Matrix x_smooth;
00115 int t;
00116 bool TLE;
00117 bool loga;
00118
00119 paramval creativity;
00120 paramval sense;
00121 paramval harmony;
00122 paramval causeaware;
00123 paramval epsC;
00124 paramval epsA;
00125 paramint s4avg;
00126 paramint s4delay;
00127
00128
00129
00130 virtual void learn();
00131
00132
00133 static double g(double z)
00134 {
00135 return tanh(z);
00136 };
00137
00138
00139 static double g_s(double z)
00140 {
00141 double k=tanh(z);
00142 return 1.0 - k*k;
00143 };
00144
00145
00146 static double clip(double r, double x){
00147 return min(max(x,-r),r);
00148 }
00149
00150 static double one_over(double x){
00151 return 1/x;
00152 }
00153
00154
00155 };
00156
00157 #endif
00158
00159