sox.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 __SOX_H
00020 #define __SOX_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 #include <selforg/teachable.h>
00030
00031
00032
00033 struct SoxConf {
00034 double initFeedbackStrength;
00035 bool useExtendedModel;
00036
00037 bool useTeaching;
00038
00039 int steps4Averaging;
00040
00041 int steps4Delay;
00042 bool someInternalParams;
00043 bool onlyMainParameters;
00044
00045 double factorS;
00046 double factorb;
00047 };
00048
00049
00050
00051
00052
00053
00054 class Sox : public AbstractController, public Teachable {
00055
00056 public:
00057
00058 Sox(const SoxConf& conf = getDefaultConf());
00059
00060
00061 Sox(double init_feedback_strength, bool useExtendedModel = true,
00062 bool useTeaching = false );
00063
00064 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00065
00066 virtual ~Sox();
00067
00068 static SoxConf getDefaultConf(){
00069 SoxConf conf;
00070 conf.initFeedbackStrength = 1.0;
00071 conf.useExtendedModel = true;
00072 conf.useTeaching = false;
00073 conf.steps4Averaging = 1;
00074 conf.steps4Delay = 1;
00075 conf.someInternalParams = false;
00076 conf.onlyMainParameters = true;
00077
00078 conf.factorS = 1;
00079 conf.factorb = 1;
00080 return conf;
00081 }
00082
00083
00084
00085 virtual int getSensorNumber() const { return number_sensors; }
00086
00087 virtual int getMotorNumber() const { return number_motors; }
00088
00089
00090
00091 virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00092
00093
00094
00095 virtual void stepNoLearning(const sensor* , int number_sensors,
00096 motor* , int number_motors);
00097
00098
00099 virtual void motorBabblingStep(const sensor* , int number_sensors,
00100 const motor* , int number_motors);
00101
00102
00103
00104 virtual bool store(FILE* f) const;
00105
00106 virtual bool restore(FILE* f);
00107
00108
00109 virtual matrix::Matrix getA();
00110 virtual void setA(const matrix::Matrix& A);
00111 virtual matrix::Matrix getC();
00112 virtual void setC(const matrix::Matrix& C);
00113 virtual matrix::Matrix geth();
00114 virtual void seth(const matrix::Matrix& h);
00115
00116
00117 virtual void setMotorTeaching(const matrix::Matrix& teaching);
00118 virtual void setSensorTeaching(const matrix::Matrix& teaching);
00119 virtual matrix::Matrix getLastMotorValues();
00120 virtual matrix::Matrix getLastSensorValues();
00121
00122 protected:
00123 unsigned short number_sensors;
00124 unsigned short number_motors;
00125 static const unsigned short buffersize = 10;
00126
00127 matrix::Matrix A;
00128 matrix::Matrix C;
00129 matrix::Matrix S;
00130 matrix::Matrix h;
00131 matrix::Matrix b;
00132 matrix::Matrix L;
00133 matrix::Matrix R;
00134 matrix::Matrix C_native;
00135 matrix::Matrix A_native;
00136 matrix::Matrix y_buffer[buffersize];
00137 matrix::Matrix x_buffer[buffersize];
00138 matrix::Matrix v_avg;
00139 matrix::Matrix x;
00140 matrix::Matrix x_smooth;
00141 int t;
00142
00143 bool loga;
00144
00145 SoxConf conf;
00146
00147 bool intern_isTeaching;
00148 matrix::Matrix y_teaching;
00149
00150 paramval creativity;
00151 paramval sense;
00152 paramval harmony;
00153 paramval causeaware;
00154 paramint pseudo;
00155 paramval epsC;
00156 paramval epsA;
00157 paramval damping;
00158 paramval gamma;
00159
00160 void constructor();
00161
00162
00163 matrix::Matrix pseudoInvL(const matrix::Matrix& L, const matrix::Matrix& A, const matrix::Matrix& C);
00164
00165
00166 virtual void learn();
00167
00168
00169 static double g(double z)
00170 {
00171 return tanh(z);
00172 };
00173
00174
00175 static double g_s(double z)
00176 {
00177 double k=tanh(z);
00178 return 1.0 - k*k;
00179 };
00180
00181
00182 static double clip(double r, double x){
00183 return min(max(x,-r),r);
00184 }
00185
00186 static double one_over(double x){
00187 return 1/x;
00188 }
00189
00190
00191 };
00192
00193 #endif
00194
00195