proactive2.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 * $Log: proactive2.h,v $ 00020 * Revision 1.4 2006/08/04 15:16:13 martius 00021 * documentation 00022 * 00023 * Revision 1.3 2006/07/14 12:23:59 martius 00024 * selforg becomes HEAD 00025 * 00026 * Revision 1.1.2.3 2006/07/10 13:05:16 martius 00027 * NON-COMMERICAL LICENSE added to controllers 00028 * 00029 * Revision 1.1.2.2 2006/07/10 11:59:24 martius 00030 * Matrixlib now in selforg 00031 * no namespace std in header files 00032 * 00033 * Revision 1.1.2.1 2006/02/08 15:14:49 martius 00034 * new version of proactive which uses direct H feeding 00035 * 00036 * 00037 ***************************************************************************/ 00038 #ifndef __PROACTIVE2_H 00039 #define __PROACTIVE2_H 00040 00041 #include "invertmotornstep.h" 00042 #include "onelayerffnn.h" 00043 00044 #include <assert.h> 00045 #include <math.h> 00046 00047 #include <selforg/matrix.h> 00048 00049 /** 00050 * robot controller for self-organized behaviour using pro-active elements 00051 * and it is based in InvertMotorNStep. 00052 */ 00053 class ProActive2 : public InvertMotorNStep { 00054 00055 public: 00056 /** @param numberNonContext number of input channels that are not considered as context inputs 00057 (e.g.\ infrared) 00058 @param tau time window for temporal correlation 00059 @param conf configuration \ref InvertMotorNStepConf 00060 */ 00061 ProActive2( unsigned int numberNonContext, unsigned int tau, const InvertMotorNStepConf& conf = getDefaultConf()) 00062 : InvertMotorNStep(conf), synDyn(0.1) { 00063 // prepare name; 00064 Configurable::insertCVSInfo(name, "$RCSfile: proactive2.h,v $", "$Revision: 1.4 $"); 00065 assert(tau < buffersize); 00066 this->tau = tau; 00067 this->numberNonContext = numberNonContext; 00068 internkeylist = 0; 00069 dampH = 0.0001; 00070 epsH = 0.5; 00071 } 00072 00073 virtual ~ProActive2(){ 00074 if (syndyn_buffer){ 00075 delete[] syndyn_buffer; 00076 } 00077 if(internkeylist) free(internkeylist); 00078 } 00079 00080 virtual void init(int sensornumber, int motornumber){ 00081 assert( numberNonContext <= (unsigned int) sensornumber); 00082 number_all_sensors = sensornumber; 00083 InvertMotorNStep::init(numberNonContext, motornumber); 00084 00085 int synDynInputNumber = (sensornumber - numberNonContext); // + motornumber 00086 synDyn.init(synDynInputNumber, motornumber); 00087 syndyn_buffer = new matrix::Matrix[buffersize]; 00088 00089 for (unsigned int k = 0; k < buffersize; k++) { 00090 syndyn_buffer[k].set(synDynInputNumber,1); 00091 } 00092 00093 xsi_pred.set(numberNonContext,1); 00094 xsi_orig.set(numberNonContext,1); 00095 00096 if(internkeylist) free(internkeylist); 00097 internkeylist=0; 00098 } 00099 00100 virtual void step(const sensor* x_, int number_sensors, motor* y_, int number_motors){ 00101 // call InvertMotorNStep just with the non-context sensors 00102 // column vector with context sensor values 00103 x_context.set(number_all_sensors - numberNonContext, 1, x_ + numberNonContext); 00104 InvertMotorNStep::step(x_, numberNonContext, y_, number_motors); 00105 } 00106 00107 /// performs one step without learning. Calulates motor commands from sensor inputs. 00108 virtual void stepNoLearning(const sensor* x_, int number_sensors, 00109 motor* y_, int number_motors){ 00110 x_context.set(number_all_sensors - numberNonContext, 1, x_ + numberNonContext); // column vector with context sensor values 00111 // time is increased 00112 InvertMotorNStep::stepNoLearning(x_, numberNonContext, y_, number_motors); 00113 t--; 00114 bufferSynDynInput(); 00115 t++; 00116 } 00117 00118 /// return the name of the object (with version number) Hint: use insertCVSInfo from Configurable 00119 virtual paramkey getName() const { return name; } 00120 00121 virtual list<iparamkey> getInternalParamNames() const { 00122 list<iparamkey> keylist = InvertMotorNStep::getInternalParamNames(); 00123 if(conf.someInternalParams){ 00124 keylist += store4x4AndDiagonalFieldNames(synDyn.getWeights(), "HDW"); 00125 }else{ 00126 keylist += storematrix::MatrixFieldNames(synDyn.getWeights(), "HDW"); 00127 } 00128 keylist += storematrix::MatrixFieldNames(synDyn.getBias(), "HDB"); 00129 keylist += storeVectorFieldNames(xsi_pred, "xsi_orig"); 00130 keylist += storeVectorFieldNames(xsi_pred, "xsi_pred"); 00131 return keylist; 00132 } 00133 00134 virtual list<iparamval> getInternalParams() const { 00135 list<iparamval> l = InvertMotorNStep::getInternalParams(); 00136 if(conf.someInternalParams){ 00137 l += store4x4AndDiagonal(synDyn.getWeights()); 00138 }else{ 00139 l += synDyn.getWeights().convertToList(); 00140 } 00141 l += synDyn.getBias().convertToList(); 00142 l += xsi_orig.convertToList(); 00143 l += xsi_pred.convertToList(); 00144 return l; 00145 } 00146 00147 virtual paramval getParam(const paramkey& key) const{ 00148 if( key == "epsH") return epsH; 00149 else if( key == "tau") return tau; 00150 else if( key == "dampH") return dampH; 00151 else { 00152 paramval v = synDyn.getParam(key); 00153 if( v!=0.0) return v; 00154 else return InvertMotorNStep::getParam(key); 00155 } 00156 } 00157 00158 virtual bool setParam(const paramkey& key, paramval val){ 00159 if(key == "epsH") epsH = val; 00160 else if(key == "tau") tau = (unsigned int)val; 00161 else if(key == "dampH") dampH = val; 00162 else if(synDyn.setParam(key, val)) return true; 00163 else return InvertMotorNStep::setParam(key, val); 00164 return true; 00165 } 00166 00167 virtual paramlist getParamList() const{ 00168 paramlist keylist = InvertMotorNStep::getParamList(); 00169 keylist += pair<paramkey, paramval> (string("epsH"), epsH); 00170 keylist += pair<paramkey, paramval> (string("tau"), tau); 00171 keylist += pair<paramkey, paramval> (string("dampH"), dampH); 00172 keylist += synDyn.getParamList(); 00173 return keylist; 00174 } 00175 00176 static InvertMotorNStepConf getDefaultConf(){ 00177 InvertMotorNStepConf c; 00178 c.buffersize = 10; 00179 c.cInit = 0.1; 00180 c.useS = true; 00181 c.someInternalParams = true; 00182 return c; 00183 } 00184 00185 protected: 00186 00187 virtual void bufferSynDynInput(){ 00188 //const matrix::Matrix z = C * x_smooth + H; 00189 // const matrix::Matrix& y = y_buffer[t% buffersize]; 00190 // first the postsynaptic potential and then the context sensors and then the non-context sensors 00191 // matrix::Matrix hinput = z.above(x_context*y.val(0,0)); // column vector with z above x_context 00192 // const matrix::Matrix& hinput = z.above(x_context); // column vector with z above x_context 00193 const matrix::Matrix& hinput = x_context; 00194 // put new sensor vector in ring buffer sensor_buffer (all sensors) 00195 putInBuffer(syndyn_buffer, hinput); 00196 } 00197 00198 /// calculates xsi for the current time step using the delayed y values 00199 // overloaded version which incorporates time smoothing 00200 virtual void calcXsi(int delay){ 00201 InvertMotorNStep::calcXsi(delay); 00202 xsi_orig = xsi; 00203 const matrix::Matrix& y = y_buffer[(t - 1 - delay) % buffersize]; 00204 if(x_context.val(0,0) * y.val(0,0) > 0.1){ 00205 xsi_pred.val(0,0) = x_context.val(0,0) * y.val(0,0) * 0.2 ; 00206 }else{ 00207 xsi_pred.val(0,0)=0; 00208 } 00209 xsi += xsi_pred; 00210 } 00211 00212 protected: 00213 OneLayerFFNN synDyn; 00214 00215 matrix::Matrix* syndyn_buffer; 00216 matrix::Matrix x_context; 00217 matrix::Matrix xsi_pred; 00218 matrix::Matrix xsi_orig; 00219 paramkey* internkeylist; 00220 00221 unsigned int tau; 00222 unsigned int numberNonContext; 00223 unsigned int number_all_sensors; 00224 double dampH; 00225 double epsH; 00226 00227 }; 00228 00229 #endif

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