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