00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __INVERTNCHANNELCONTROLLER_H
00025 #define __INVERTNCHANNELCONTROLLER_H
00026
00027 #include "invertcontroller.h"
00028
00029 #include <assert.h>
00030 #include <math.h>
00031
00032 #include "matrix.h"
00033 using namespace matrix;
00034
00035
00036
00037
00038
00039
00040
00041
00042 class InvertNChannelController : public InvertController {
00043
00044 public:
00045 InvertNChannelController(int _buffersize, bool _update_only_1=false);
00046 virtual void init(int sensornumber, int motornumber);
00047
00048 virtual ~InvertNChannelController(){}
00049
00050
00051 virtual paramkey getName() const {return name; }
00052
00053 virtual int getSensorNumber() const { return number_channels; }
00054
00055 virtual int getMotorNumber() const { return number_channels; }
00056
00057
00058
00059 virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00060
00061
00062
00063 virtual void stepNoLearning(const sensor* , int number_sensors,
00064 motor* , int number_motors);
00065
00066
00067
00068 virtual bool store(const char* filename);
00069
00070 virtual bool restore(const char* filename);
00071
00072
00073 virtual list<iparamkey> getInternalParamNames() const;
00074 virtual list<iparamval> getInternalParams() const;
00075 virtual list<ILayer> getStructuralLayers() const;
00076 virtual list<IConnection> getStructuralConnections() const;
00077
00078
00079 protected:
00080 unsigned short number_channels;
00081 unsigned short buffersize;
00082 bool update_only_1;
00083
00084 Matrix A;
00085 Matrix C;
00086 Matrix h;
00087 Matrix L;
00088 Matrix* x_buffer;
00089 Matrix* y_buffer;
00090 int t;
00091 paramkey name;
00092
00093
00094
00095
00096
00097
00098 virtual double calculateE(const Matrix& x_delay, const Matrix& y_delay);
00099
00100
00101 virtual void learn(const Matrix& x_delay, const Matrix& y_delay);
00102
00103 virtual void learnmodel( const Matrix& y_delay);
00104
00105
00106 virtual Matrix calculateDelayedValues(const Matrix* buffer,
00107 unsigned int number_steps_of_delay_);
00108 virtual Matrix calculateSmoothValues(const Matrix* buffer,
00109 unsigned int number_steps_for_averaging_);
00110
00111 Matrix calculateControllerValues(const Matrix& x_smooth);
00112
00113
00114 void putInBuffer(Matrix* buffer, const Matrix& vec);
00115
00116
00117 static double g(double z)
00118 {
00119 return tanh(z);
00120 };
00121
00122
00123 static double g_s(double z)
00124 {
00125 double k=tanh(z);
00126 return 1.0 - k*k;
00127
00128 };
00129
00130
00131
00132
00133 static double squash(double z)
00134 {
00135 return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z );
00136
00137 };
00138 };
00139
00140 #endif
00141
00142