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.19 2006/12/11 18:14:14 martius 00022 * delete for BNoise 00023 * delete of buffers 00024 * 00025 * Revision 1.18 2006/08/02 09:31:34 martius 00026 * removed TODO 00027 * 00028 * Revision 1.17 2006/07/20 17:14:35 martius 00029 * removed std namespace from matrix.h 00030 * storable interface 00031 * abstract model and invertablemodel as superclasses for networks 00032 * 00033 * Revision 1.16 2006/07/14 12:23:58 martius 00034 * selforg becomes HEAD 00035 * 00036 * Revision 1.14.6.4 2006/07/10 13:05:16 martius 00037 * NON-COMMERICAL LICENSE added to controllers 00038 * 00039 * Revision 1.14.6.3 2006/07/10 11:59:24 martius 00040 * Matrixlib now in selforg 00041 * no namespace std in header files 00042 * 00043 * Revision 1.14.6.2 2006/01/18 16:48:35 martius 00044 * stored and restore 00045 * 00046 * Revision 1.14.6.1 2005/11/14 17:37:29 martius 00047 * moved to selforg 00048 * 00049 * Revision 1.14 2005/10/27 15:46:38 martius 00050 * inspectable interface is expanded to structural information for network visualiser 00051 * 00052 * Revision 1.13 2005/10/27 15:02:06 fhesse 00053 * commercial use added 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 * class for robot controller that uses the georg's matrixlib for 00070 * direct matrix inversion for n channels 00071 * (simple one layer networks) 00072 * 00073 * Implements standart parameters: eps, rho, mu, stepnumber4avg, stepnumber4delay 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 /// returns the name of the object (with version number) 00084 virtual paramkey getName() const {return name; } 00085 /// returns the number of sensors the controller was initialised with or 0 if not initialised 00086 virtual int getSensorNumber() const { return number_channels; } 00087 /// returns the mumber of motors the controller was initialised with or 0 if not initialised 00088 virtual int getMotorNumber() const { return number_channels; } 00089 00090 /// performs one step (includes learning). 00091 /// Calulates motor commands from sensor inputs. 00092 virtual void step(const sensor* , int number_sensors, motor* , int number_motors); 00093 00094 00095 /// performs one step without learning. Calulates motor commands from sensor inputs. 00096 virtual void stepNoLearning(const sensor* , int number_sensors, 00097 motor* , int number_motors); 00098 00099 00100 /***** STOREABLE ****/ 00101 /** stores the controller values to a given file. */ 00102 virtual bool store(FILE* f) const; 00103 /** loads the controller values from a given file. */ 00104 virtual bool restore(FILE* f); 00105 00106 // inspectable interface 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; // Model Matrix 00119 matrix::Matrix C; // Controller Matrix 00120 matrix::Matrix h; // Controller Bias 00121 matrix::Matrix L; // Jacobi Matrix 00122 matrix::Matrix* x_buffer; 00123 matrix::Matrix* y_buffer; 00124 int t; 00125 paramkey name; 00126 00127 00128 /* virtual void iteration(double *column, */ 00129 /* double dommy[NUMBER_CHANNELS][NUMBER_CHANNELS], */ 00130 /* double *improvment); */ 00131 00132 virtual double calculateE(const matrix::Matrix& x_delay, const matrix::Matrix& y_delay); 00133 00134 /// learn values h,C 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 /// calculate delayed values 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 // put new value in ring buffer 00148 void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec); 00149 00150 /// neuron transfer function 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 // return 1.0 - tanh(z)*tanh(z); 00162 }; 00163 00164 00165 00166 /// squashing function, to protect against to large weight updates 00167 static double squash(double z) 00168 { 00169 return clip(z,-0.1,0.1); 00170 // return z < -0.1 ? -0.1 : ( z > 0.1 ? 0.1 : z ); 00171 //return 0.1 * tanh(10.0 * z); 00172 }; 00173 }; 00174 00175 #endif 00176 00177

Generated on Tue Jan 16 02:14:36 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8