sos.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 __SOS_H
00020 #define __SOS_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 class Sos : public AbstractController {
00035
00036 public:
00037 Sos(double init_feedback_strength = 1.0);
00038 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00039
00040 virtual ~Sos();
00041
00042
00043 virtual int getSensorNumber() const { return number_sensors; }
00044
00045 virtual int getMotorNumber() const { return number_motors; }
00046
00047
00048
00049 virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00050
00051
00052
00053 virtual void stepNoLearning(const sensor* , int number_sensors,
00054 motor* , int number_motors);
00055
00056
00057
00058
00059 virtual bool store(FILE* f) const;
00060
00061 virtual bool restore(FILE* f);
00062
00063
00064 virtual matrix::Matrix getA();
00065 virtual void setA(const matrix::Matrix& A);
00066 virtual matrix::Matrix getC();
00067 virtual void setC(const matrix::Matrix& C);
00068 virtual matrix::Matrix geth();
00069 virtual void seth(const matrix::Matrix& h);
00070
00071 protected:
00072 unsigned short number_sensors;
00073 unsigned short number_motors;
00074 static const unsigned short buffersize = 10;
00075
00076 matrix::Matrix A;
00077 matrix::Matrix C;
00078 matrix::Matrix h;
00079 matrix::Matrix b;
00080 matrix::Matrix L;
00081 matrix::Matrix y_buffer[buffersize];
00082 matrix::Matrix x_buffer[buffersize];
00083 matrix::Matrix v_avg;
00084 matrix::Matrix x;
00085 matrix::Matrix x_smooth;
00086 int t;
00087 bool TLE;
00088 bool loga;
00089
00090 double init_feedback_strength;
00091
00092 paramval creativity;
00093 paramval epsC;
00094 paramval epsA;
00095 paramint s4avg;
00096 paramint s4delay;
00097
00098
00099
00100 virtual void learn();
00101
00102
00103 static double g(double z)
00104 {
00105 return tanh(z);
00106 };
00107
00108
00109 static double g_s(double z)
00110 {
00111 double k=tanh(z);
00112 return 1.0 - k*k;
00113 };
00114
00115
00116 static double clip(double r, double x){
00117 return min(max(x,-r),r);
00118 }
00119
00120 static double one_over(double x){
00121 return 1/x;
00122 }
00123
00124
00125 };
00126
00127 #endif
00128
00129