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
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #ifndef __INVERTMOTORCONTROLLER_H
00073 #define __INVERTMOTORCONTROLLER_H
00074
00075 #include "abstractcontroller.h"
00076 #include "controller_misc.h"
00077 #include <stdlib.h>
00078 #include <string.h>
00079
00080
00081
00082
00083
00084
00085
00086
00087 class InvertMotorController : public AbstractController {
00088 public:
00089 InvertMotorController( unsigned short buffersize ,
00090 const std::string& name, const std::string& revision)
00091 : AbstractController(name, revision){
00092 this->buffersize = buffersize;
00093 addParameterDef("epsC", &epsC, 0.1);
00094 addParameterDef("epsA",&epsA, 0.1);
00095 addParameterDef("dampA",&dampA,0 );
00096 addParameterDef("adaptrate",&adaptRate,0.000);
00097 addParameterDef("nomupdate",&nomUpdate,0.005);
00098 addParameterDef("desens",&desens,0);
00099 addParameterDef("s4delay",&s4delay,1);
00100 addParameterDef("s4avg",&s4avg,1);
00101 addParameterDef("steps",&steps,1);
00102 addParameterDef("zetaupdate",&zetaupdate,0);
00103 addParameterDef("squashsize",&squashSize,0.01);
00104 addParameterDef("factorB",&factorB,0.2);
00105 addParameterDef("noiseB",&noiseB,0.001);
00106 addParameterDef("noiseY",&noiseY,0);
00107 addParameterDef("teacher",&teacher,5);
00108 rootE=0;
00109 logaE=0;
00110 relativeE=0;
00111 t=0;
00112 initialised = false;
00113 }
00114
00115
00116
00117 virtual paramval getParam(const paramkey& key) const{
00118 if(key == "logaE") return logaE;
00119 else if(key == "rootE") return rootE;
00120 else if(key == "relativeE") return relativeE;
00121 else return AbstractController::getParam(key);
00122 }
00123
00124 virtual bool setParam(const paramkey& key, paramval val){
00125 if(key == "logaE") logaE=(short)val;
00126 else if(key == "rootE") rootE=(short)val;
00127 else if(key == "relativeE") relativeE=(short)val;
00128 else return AbstractController::setParam(key, val);
00129
00130 return true;
00131 }
00132
00133 virtual paramlist getParamList() const{
00134 paramlist list;
00135 list.push_back(std::pair<paramkey, paramval> ("logaE", logaE));
00136 list.push_back(std::pair<paramkey, paramval> ("rootE", rootE));
00137 list.push_back(std::pair<paramkey, paramval> ("relativeE", relativeE));
00138 return list;
00139 }
00140
00141 protected:
00142 paramval epsC;
00143 paramval desens;
00144 paramval s4delay;
00145 paramval s4avg;
00146 paramval steps;
00147 paramval epsA;
00148 paramval factorB;
00149 paramval zetaupdate;
00150 paramval dampA;
00151 short logaE;
00152 short rootE;
00153 short relativeE;
00154
00155 paramval squashSize;
00156 paramval adaptRate;
00157 paramval nomUpdate;
00158 paramval noiseB;
00159 paramval noiseY;
00160 paramval teacher;
00161
00162 int t;
00163 unsigned short buffersize;
00164 bool initialised;
00165
00166 protected:
00167
00168 void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay=0){
00169 buffer[(t-delay)%buffersize] = vec;
00170 }
00171
00172
00173 virtual matrix::Matrix calculateDelayedValues(const matrix::Matrix* buffer,
00174 int number_steps_of_delay_){
00175
00176 assert ((unsigned)number_steps_of_delay_ < buffersize);
00177 return buffer[(t - number_steps_of_delay_) % buffersize];
00178 };
00179
00180
00181 virtual matrix::Matrix calculateSmoothValues(const matrix::Matrix* buffer,
00182 int number_steps_for_averaging_){
00183
00184 assert ((int)number_steps_for_averaging_ <= buffersize);
00185
00186 matrix::Matrix result(buffer[t % buffersize]);
00187 for (int k = 1; k < number_steps_for_averaging_; k++) {
00188 result += buffer[(t - k + buffersize) % buffersize];
00189 }
00190 result *= 1/((double) (number_steps_for_averaging_));
00191 return result;
00192 };
00193
00194
00195 virtual double calcErrorFactor(const matrix::Matrix& e, bool loga, bool root) {
00196 double error_factor = 1;
00197 if (loga){
00198 error_factor= 1/(e.multTM().val(0,0)+0.000001)*0.01;
00199 }
00200 if (root){
00201 error_factor= 1/sqrt(e.multTM().val(0,0)+0.000001)*0.1;
00202 }
00203 return error_factor;
00204 }
00205
00206
00207
00208 static double g(double z)
00209 {
00210 return tanh(z);
00211 };
00212
00213
00214
00215 };
00216
00217 #endif