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