invertmotorcontroller.h

Go to the documentation of this file.
00001 #ifndef __INVERTMOTORCONTROLLER_H
00002 #define __INVERTMOTORCONTROLLER_H
00003 
00004 #include "abstractcontroller.h"
00005 #include "controller_misc.h"
00006 #include <stdlib.h>
00007 #include <string.h>
00008 
00009 /**
00010  * Abstract class (interface) for robot controller that use direct matrix inversion and
00011  * simple one layer networks.
00012  * 
00013  * Implements standart parameters: epsC, rho, mu, stepnumber4avg, stepnumber4delay
00014  */
00015 class InvertMotorController : public AbstractController {
00016 public:
00017   InvertMotorController( unsigned short buffersize ){
00018     this->buffersize = buffersize;
00019     epsC=0.1;    // base learning rate
00020     desens=0.0; // name form desensitization
00021     s4delay=1;
00022     s4avg=1;
00023     steps=1;  
00024     epsA=0.1; // learning rate factor for model learning
00025     dampA=0;  // no damping
00026     factorB=0.2; // additional learning rate factor for model bias 
00027     zetaupdate=0; // don't use the zeta update line
00028     squashSize=0.01; // maximum size of update components
00029     logaE=0; // don't use logarithmic error ( ln(v^T*v) )
00030     rootE=0; // don't use logarithmic error ( (v^T*v)^(1/2) )
00031     relativeE=0; // don't use relative modelling error 
00032     adaptRate=0.005; // factor used for adapting the lerning rates.
00033     nomUpdate=0.005; // size of nominal update in respect to matrix norm 
00034     noiseB = 0.001;   // noise that is added to bias update (before factorB is applied)
00035     teacher = 5;      // factor for teaching signal
00036     t=0;
00037     initialised = false;
00038   }
00039 
00040   virtual paramval getParam(const paramkey& key) const{
00041     if(key == "epsC") return epsC; 
00042     else if(key == "epsA") return epsA; 
00043     else if(key == "dampA") return dampA;
00044     else if(key == "adaptrate") return adaptRate;
00045     else if(key == "nomupdate") return nomUpdate;
00046     else if(key == "desens") return desens; 
00047     else if(key == "s4delay") return s4delay; 
00048     else if(key == "s4avg") return s4avg; 
00049     else if(key == "steps") return steps; 
00050     else if(key == "zetaupdate") return zetaupdate; 
00051     else if(key == "squashsize") return squashSize; 
00052     else if(key == "logaE") return logaE; 
00053     else if(key == "rootE") return rootE;
00054     else if(key == "relativeE") return relativeE;
00055     else if(key == "factorB") return factorB; 
00056     else if(key == "noiseB") return noiseB;
00057     else if(key == "teacher") return teacher;
00058     else  return AbstractController::getParam(key);
00059   }
00060 
00061   virtual bool setParam(const paramkey& key, paramval val){
00062     if(key == "epsC") epsC=val;
00063     else if(key == "epsA") epsA=val;
00064     else if(key == "dampA") dampA=val;
00065     else if(key == "adaptrate") adaptRate=val;
00066     else if(key == "nomupdate") nomUpdate=val;
00067     else if(key == "desens") desens=val;
00068     else if(key == "s4delay") s4delay=val; 
00069     else if(key == "s4avg") s4avg=val;
00070     else if(key == "steps") steps=val;
00071     else if(key == "zetaupdate") zetaupdate=val;
00072     else if(key == "squashsize") squashSize=val;
00073     else if(key == "logaE") logaE=(short)val;
00074     else if(key == "rootE") rootE=(short)val;
00075     else if(key == "relativeE") relativeE=(short)val;
00076     else if(key == "factorB") factorB=val;
00077     else if(key == "noiseB") noiseB=val;
00078     else if(key == "teacher") teacher=val;
00079     else return AbstractController::setParam(key, val);
00080     //    else fprintf(stderr, "parameter %s unknown\n", key);
00081     return true;
00082   }
00083 
00084   virtual paramlist getParamList() const{
00085     paramlist list;
00086     list.push_back(pair<paramkey, paramval> ("epsA", epsA));
00087     list.push_back(pair<paramkey, paramval> ("epsC", epsC));
00088     list.push_back(pair<paramkey, paramval> ("dampA", dampA));
00089     list.push_back(pair<paramkey, paramval> ("adaptrate", adaptRate));
00090     list.push_back(pair<paramkey, paramval> ("nomupdate", nomUpdate));
00091     list.push_back(pair<paramkey, paramval> ("desens", desens));
00092     list.push_back(pair<paramkey, paramval> ("s4delay", s4delay ));
00093     list.push_back(pair<paramkey, paramval> ("s4avg", s4avg));
00094     list.push_back(pair<paramkey, paramval> ("steps", steps));
00095     list.push_back(pair<paramkey, paramval> ("zetaupdate", zetaupdate));
00096     list.push_back(pair<paramkey, paramval> ("squashsize", squashSize));
00097     list.push_back(pair<paramkey, paramval> ("logaE", logaE));
00098     list.push_back(pair<paramkey, paramval> ("rootE", rootE));
00099     list.push_back(pair<paramkey, paramval> ("relativeE", relativeE));
00100     list.push_back(pair<paramkey, paramval> ("factorB", factorB));
00101     list.push_back(pair<paramkey, paramval> ("noiseB", noiseB));
00102     list.push_back(pair<paramkey, paramval> ("teacher", teacher));
00103     return list;
00104   }
00105 
00106 protected:
00107   paramval epsC; //< learning rate factor for controller learning
00108   paramval desens;
00109   paramval s4delay; //< number of timesteps of delay in the SML 
00110   paramval s4avg; //< number of timesteps used for smoothing the controller output values 
00111   paramval steps; //< number of timesteps is used for controller learning
00112   paramval epsA; //< learning rate factor for model learning
00113   paramval factorB; //< additional learning rate factor for model bias 
00114   paramval zetaupdate;
00115   paramval dampA; //< damping term for model (0: no damping, 0.1 high damping)
00116   short logaE;  //< logarithmic error is used for learning 1: controller 2: model 3: both
00117   short rootE;  //< root error is used for learning 1: controller 2: model 3: both
00118   short relativeE; //< if not 0: a relative error signal is used (xsi is normalised in respect to |y|)
00119 
00120   paramval squashSize; //< size of the box, where the parameter updates are clipped to
00121   paramval adaptRate; //< adaptation rate for learning rate adaptation
00122   paramval nomUpdate; //< nominal update of controller in respect to matrix norm
00123   paramval noiseB;    //< size of the additional noise for model bias B
00124   paramval teacher; //< factor for teaching signal
00125 
00126   int t;
00127   unsigned short buffersize;
00128   string name;
00129   bool initialised;
00130 
00131 protected:
00132   // put new value in ring buffer
00133   void putInBuffer(Matrix* buffer, const Matrix& vec, int delay = 0){
00134     buffer[(t-delay)%buffersize] = vec;
00135   }
00136 
00137   /// neuron transfer function
00138   static double g(double z)
00139   {
00140     return tanh(z);
00141   };
00142 
00143   /// first dervative
00144   static double g_s(double z)
00145   {
00146     double k=tanh(z); 
00147     return 1.025 - k*k; 
00148     //return 1.2 - k*k; 
00149     // return 1/(1+z*z);    // softer
00150     //return 1/(1+log(1+z*z)); // even softer
00151   };
00152 
00153   /// inverse of the first derivative
00154   static double g_s_inv(double z)
00155   {
00156     double k=tanh(z);
00157     return 1/(1.025 - k*k);
00158     //return 1/(1.2 - k*k);
00159     // return 1+z*z; // softer
00160     //return 1+log(1+z*z); // even softer
00161   };
00162 
00163   /// squashing function, to protect against to large weight updates
00164   static double squash(double z)
00165   {
00166     return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z );
00167     //return 0.1 * tanh(10.0 * z);
00168   };
00169 
00170 };
00171 
00172 #endif

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5