Robotsystem of the Robot Group Leipzig: invertnchannelcontroller.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Examples

- Search for |

- File List
- File Members

# 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  *   LICENSE:                                                              *
    00009  *   This work is licensed under the Creative Commons                      *
    00010  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00011  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00012  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00013  *   San Francisco, California, 94105, USA.                                *
    00014  *                                                                         *
    00015  *   This program is distributed in the hope that it will be useful,       *
    00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00018  *                                            *
    00019  *                                                                         *
    00020  *   $Log: invertnchannelcontroller.h,v $
    00021  *   Revision 1.18  2006/08/02 09:31:34  martius
    00022  *   removed TODO
    00023  *
    00024  *   Revision 1.17  2006/07/20 17:14:35  martius
    00025  *   removed std namespace from matrix.h
    00026  *   storable interface
    00027  *   abstract model and invertablemodel as superclasses for networks
    00028  *
    00029  *   Revision 1.16  2006/07/14 12:23:58  martius
    00030  *   selforg becomes HEAD
    00031  *
    00032  *   Revision 1.14.6.4  2006/07/10 13:05:16  martius
    00033  *   NON-COMMERICAL LICENSE added to controllers
    00034  *
    00035  *   Revision 1.14.6.3  2006/07/10 11:59:24  martius
    00036  *   Matrixlib now in selforg
    00037  *   no namespace std in header files
    00038  *
    00039  *   Revision 1.14.6.2  2006/01/18 16:48:35  martius
    00040  *   stored and restore
    00041  *
    00042  *   Revision 1.14.6.1  2005/11/14 17:37:29  martius
    00043  *   moved to selforg
    00044  *
    00045  *   Revision 1.14  2005/10/27 15:46:38  martius
    00046  *   inspectable interface is expanded to structural information for network visualiser
    00047  *
    00048  *   Revision 1.13  2005/10/27 15:02:06  fhesse
    00049  *   commercial use added
    00050  *                                    *
    00051  *                                                                         *
    00052  ***************************************************************************/
    00053 #ifndef __INVERTNCHANNELCONTROLLER_H
    00054 #define __INVERTNCHANNELCONTROLLER_H
    00055
    00056 #include "invertcontroller.h"
    00057
    00058 #include <assert.h>
    00059 #include <math.h>
    00060
    00061 #include <selforg/matrix.h>
    00062
    00063 /**
    00064  * class for robot controller that uses the georg's matrixlib for
    00065  *  direct matrix inversion for n channels
    00066  * (simple one layer networks)
    00067  *
    00068  * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay
    00069  */
    00070 class InvertNChannelController : public InvertController {
    00071
    00072 public:
    00073   InvertNChannelController(int _buffersize, bool _update_only_1=false);
    00074   virtual void init(int sensornumber, int motornumber);
    00075
    00076   virtual ~InvertNChannelController(){}
    00077
    00078   /// returns the name of the object (with version number)
    00079   virtual paramkey getName() const {return name; }
    00080   /// returns the number of sensors the controller was initialised with or 0 if not initialised
    00081   virtual int getSensorNumber() const { return number_channels; }
    00082   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
    00083   virtual int getMotorNumber() const  { return number_channels; }
    00084
    00085   /// performs one step (includes learning).
    00086   /// Calulates motor commands from sensor inputs.
    00087   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
    00088
    00089
    00090   /// performs one step without learning. Calulates motor commands from sensor inputs.
    00091   virtual void stepNoLearning(const sensor* , int number_sensors,
    00092                               motor* , int number_motors);
    00093
    00094
    00095   /***** STOREABLE ****/
    00096   /** stores the controller values to a given file. */
    00097   virtual bool store(FILE* f) const;
    00098   /** loads the controller values from a given file. */
    00099   virtual bool restore(FILE* f);
    00100
    00101   // inspectable interface
    00102   virtual std::list<iparamkey> getInternalParamNames() const;
    00103   virtual std::list<iparamval> getInternalParams() const;
    00104   virtual std::list<ILayer> getStructuralLayers() const;
    00105   virtual std::list<IConnection> getStructuralConnections() const;
    00106
    00107
    00108 protected:
    00109   unsigned short number_channels;
    00110   unsigned short buffersize;
    00111   bool update_only_1;
    00112
    00113   matrix::Matrix A; // Model Matrix
    00114   matrix::Matrix C; // Controller Matrix
    00115   matrix::Matrix h; // Controller Bias
    00116   matrix::Matrix L; // Jacobi Matrix
    00117   matrix::Matrix* x_buffer;
    00118   matrix::Matrix* y_buffer;
    00119   int t;
    00120   paramkey name;
    00121
    00122
    00123 /*   virtual void iteration(double *column, */
    00124 /*                       double dommy[NUMBER_CHANNELS][NUMBER_CHANNELS], */
    00125 /*                       double *improvment); */
    00126
    00127   virtual double calculateE(const matrix::Matrix& x_delay, const matrix::Matrix& y_delay);
    00128
    00129   /// learn values h,C
    00130   virtual void learn(const matrix::Matrix& x_delay, const matrix::Matrix& y_delay);
    00131
    00132   virtual void learnmodel( const matrix::Matrix& y_delay);
    00133
    00134   /// calculate delayed values
    00135   virtual matrix::Matrix calculateDelayedValues(const matrix::Matrix* buffer,
    00136                                         unsigned int number_steps_of_delay_);
    00137   virtual matrix::Matrix calculateSmoothValues(const matrix::Matrix* buffer,
    00138                                        unsigned int number_steps_for_averaging_);
    00139
    00140   matrix::Matrix calculateControllerValues(const matrix::Matrix& x_smooth);
    00141
    00142   // put new value in ring buffer
    00143   void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec);
    00144
    00145   /// neuron transfer function
    00146   static double g(double z)
    00147   {
    00148     return tanh(z);
    00149   };
    00150
    00151   ///
    00152   static double g_s(double z)
    00153   {
    00154     double k=tanh(z);
    00155     return 1.0 - k*k;
    00156     //    return 1.0 - tanh(z)*tanh(z);
    00157   };
    00158
    00159
    00160
    00161   /// squashing function, to protect against to large weight updates
    00162   static double squash(double z)
    00163   {
    00164     return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z );
    00165     //return 0.1 * tanh(10.0 * z);
    00166   };
    00167 };
    00168
    00169 #endif
    00170
    00171