invertnchannelcontroller.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *                                                                         *
00007  *   ANY COMMERCIAL USE FORBIDDEN!                                         * 
00008  *                                                                         *
00009  *   $Log: invertnchannelcontroller.h,v $
00010  *   Revision 1.14.6.2  2006/01/18 16:48:35  martius
00011  *   stored and restore
00012  *
00013  *   Revision 1.14.6.1  2005/11/14 17:37:29  martius
00014  *   moved to selforg
00015  *
00016  *   Revision 1.14  2005/10/27 15:46:38  martius
00017  *   inspectable interface is expanded to structural information for network visualiser
00018  *
00019  *   Revision 1.13  2005/10/27 15:02:06  fhesse
00020  *   commercial use added
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  * class for robot controller that uses the georg's matrixlib for 
00037  *  direct matrix inversion for n channels 
00038  * (simple one layer networks)
00039  * 
00040  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
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   /// returns the name of the object (with version number)
00051   virtual paramkey getName() const {return name; } 
00052   /// returns the number of sensors the controller was initialised with or 0 if not initialised
00053   virtual int getSensorNumber() const { return number_channels; }
00054   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
00055   virtual int getMotorNumber() const  { return number_channels; }
00056 
00057   /// performs one step (includes learning). 
00058   /// Calulates motor commands from sensor inputs.
00059   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
00060 
00061 
00062   /// performs one step without learning. Calulates motor commands from sensor inputs.
00063   virtual void stepNoLearning(const sensor* , int number_sensors, 
00064                               motor* , int number_motors);
00065 
00066 
00067   /** stores the controller values to a given file. */
00068   virtual bool store(const char* filename);
00069   /** loads the controller values from a given file. */
00070   virtual bool restore(const char* filename);  
00071 
00072   // inspectable interface
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; // Model Matrix
00085   Matrix C; // Controller Matrix
00086   Matrix h; // Controller Bias
00087   Matrix L; // Jacobi Matrix
00088   Matrix* x_buffer;
00089   Matrix* y_buffer;
00090   int t;
00091   paramkey name;
00092   
00093 
00094 /*   virtual void iteration(double *column, */
00095 /*                       double dommy[NUMBER_CHANNELS][NUMBER_CHANNELS], */
00096 /*                       double *improvment); */
00097 
00098   virtual double calculateE(const Matrix& x_delay, const Matrix& y_delay);      
00099 
00100   /// learn values h,C
00101   virtual void learn(const Matrix& x_delay, const Matrix& y_delay);
00102 
00103   virtual void learnmodel( const Matrix& y_delay);
00104 
00105   /// calculate delayed values
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   // put new value in ring buffer
00114   void putInBuffer(Matrix* buffer, const Matrix& vec);
00115 
00116   /// neuron transfer function
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;  //TODO:     return 1.0 - k*k;
00127     //    return 1.0 - tanh(z)*tanh(z);
00128   };
00129 
00130 
00131 
00132   /// squashing function, to protect against to large weight updates
00133   static double squash(double z)
00134   {
00135     return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z );
00136     //return 0.1 * tanh(10.0 * z);
00137   };
00138 };
00139 
00140 #endif
00141 
00142 

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