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 * guettler@informatik.uni-leipzig.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 * * 00023 * $Log: inspectable.h,v $ 00024 * Revision 1.3 2008/08/01 14:42:03 guettler 00025 * we try the trip to hell! make selforg AVR compatible...good luck (first changes) 00026 * 00027 * Revision 1.2 2008/04/29 09:55:30 guettler 00028 * -class uses now a list of pairs instead of a map 00029 * -debug printouts removed 00030 * 00031 * Revision 1.1 2008/04/29 07:39:24 guettler 00032 * -interfaces moved to selforg/utils 00033 * -added addInspectableValue and addInspectableMatrix 00034 * -methods getInternalParamNames and getInternalParams do not need to be 00035 * overloaded anymore, use addInspectableValue and addInspectableMatrix 00036 * instead (preferred) 00037 * 00038 * Revision 1.9 2006/12/21 11:44:17 martius 00039 * commenting style for doxygen //< -> ///< 00040 * FOREACH and FOREACHC are macros for collection iteration 00041 * 00042 * Revision 1.8 2006/07/20 17:14:34 martius 00043 * removed std namespace from matrix.h 00044 * storable interface 00045 * abstract model and invertablemodel as superclasses for networks 00046 * 00047 * Revision 1.7 2006/07/14 12:23:58 martius 00048 * selforg becomes HEAD 00049 * 00050 * Revision 1.5.6.1 2006/06/25 16:51:35 martius 00051 * configureable has name and revision 00052 * a robot is configureable by default 00053 * 00054 * Revision 1.5 2005/10/27 15:46:38 martius 00055 * inspectable interface is expanded to structural information for network visualiser 00056 * 00057 * Revision 1.4 2005/10/06 17:06:57 martius 00058 * switched to stl lists 00059 * 00060 * Revision 1.3 2005/09/11 11:20:01 martius 00061 * virtual destructor 00062 * 00063 * Revision 1.2 2005/08/06 20:47:54 martius 00064 * Commented 00065 * 00066 * Revision 1.1 2005/08/03 20:28:57 martius 00067 * inspectable interface 00068 * 00069 * * 00070 ***************************************************************************/ 00071 #ifndef __INSPECTABLE_H 00072 #define __INSPECTABLE_H 00073 00074 00075 #ifndef AVR 00076 00077 #include <list> 00078 #include <map> 00079 #include <utility> 00080 #include <string> 00081 #include "stl_adds.h" 00082 00083 #include <iostream> 00084 00085 namespace matrix { 00086 class Matrix; 00087 } 00088 00089 /** 00090 * Interface for inspectable objects. 00091 * That means that one can read out some internal parameters indentified by string keys 00092 */ 00093 class Inspectable { 00094 public: 00095 00096 /// TYPEDEFS BEGIN 00097 00098 typedef std::string iparamkey; 00099 typedef double iparamval; 00100 typedef std::pair<iparamkey,iparamval*> iparampair; 00101 typedef std::pair<iparamkey,matrix::Matrix*> imatrixpair; 00102 00103 typedef std::list<iparamkey> iparamkeylist; 00104 typedef std::list<iparamval> iparamvallist; 00105 typedef std::list<iparampair> iparampairlist; 00106 typedef std::list<imatrixpair> imatrixpairlist; 00107 00108 00109 typedef struct ILayer{ 00110 ILayer(const std::string& vectorname, const std::string& biasname, 00111 int dimension, int rank, const std::string& layername) 00112 : vectorname(vectorname), biasname(biasname), 00113 dimension(dimension), rank(rank), layername(layername) {} 00114 std::string vectorname; //< prefix of the internal parameter vector e.g. "v" 00115 std::string biasname; ///< prefix of the internal parameter vector used as bias for the neurons e.g. "h" 00116 int dimension; ///< length of the vector (number of units) 00117 int rank; ///< rank of the layer (0 are input layers) 00118 std::string layername; ///< name of the layer as displayed by the visualiser 00119 }ILayer; 00120 00121 typedef struct IConnection{ 00122 IConnection(const std::string& matrixname, const std::string& vector1, const std::string& vector2) 00123 : matrixname(matrixname), vector1(vector1), vector2(vector2) {} 00124 std::string matrixname; ///< matrix name is the prefix of the internal parameter matrix e.g. "A" 00125 std::string vector1; ///< vectorname of input layer 00126 std::string vector2; ///< vectorname of output layer 00127 }IConnection; 00128 00129 typedef std::list<ILayer> ilayerlist; 00130 typedef std::list<IConnection> iconnectionlist; 00131 00132 /// nice predicate function for finding a Layer with its vectorname 00133 struct matchName : public std::unary_function<ILayer, bool> { 00134 matchName(std::string name) : name(name) {} 00135 std::string name; 00136 bool operator()(ILayer l) { return l.vectorname == name; } 00137 }; 00138 00139 /// TYPEDEFS END 00140 00141 00142 Inspectable(); 00143 00144 00145 virtual ~Inspectable(); 00146 00147 00148 /** The list of the names of all internal parameters given by getInternalParams(). 00149 The naming convention is "v[i]" for vectors 00150 and "A[i][j]" for matrices, where i, j start at 0. 00151 @return: list of keys 00152 */ 00153 virtual iparamkeylist getInternalParamNames() const; 00154 00155 00156 /** @return: list of values 00157 */ 00158 virtual iparamvallist getInternalParams() const; 00159 00160 00161 /** Specifies which parameter vector forms a structural layer (in terms of a neural network) 00162 The ordering is important. The first entry is the input layer and so on. 00163 @return: list of layer names with dimension 00164 00165 */ 00166 virtual ilayerlist getStructuralLayers() const; 00167 00168 00169 /** Specifies which parameter matrix forms a connection between layers (in terms of a neural network) 00170 The orderning is not important. 00171 @return: list of layer names with dimension 00172 */ 00173 virtual iconnectionlist getStructuralConnections() const; 00174 00175 00176 /** 00177 * This is the new style for adding inspectable values. Just call this 00178 * function for each parameter and you are done. 00179 * registers a single value 00180 * @param key the name of the inspectable, shown e.g. in guilogger 00181 * @param val the address of the value to inspect 00182 */ 00183 virtual void addInspectableValue(const iparamkey key, iparamval* val); 00184 00185 00186 /** 00187 * This is the new style for adding inspectable values. Just call this 00188 * function for each parameter and you are done. 00189 * inspects all elements of the given matrix given through the functions 00190 * store4x4AndDiagonalFieldNames(Matrix& m,string& matrixName); 00191 * defined in <selforg/controller_misc.h> 00192 * @param key the name of the matrix, shown e.g. in guilogger 00193 * @param m the address of the matrix to inspect 00194 * @note that you can change the structure of the matrix while 00195 * being inspected. 00196 */ 00197 virtual void addInspectableMatrix(const iparamkey key, matrix::Matrix* m); 00198 00199 00200 00201 private: 00202 iparampairlist mapOfValues; 00203 imatrixpairlist mapOfMatrices; 00204 00205 00206 }; 00207 00208 #else 00209 00210 #include <string.h> 00211 #include "stl_adds.h" 00212 #include "avrtypes.h" 00213 00214 00215 namespace matrix { 00216 class Matrix; 00217 } 00218 00219 /** 00220 * Interface for inspectable objects. 00221 * That means that one can read out some internal parameters indentified by string keys 00222 */ 00223 class Inspectable { 00224 public: 00225 00226 00227 typedef struct ILayer{ 00228 ILayer(const charArray vectorname, const charArray& biasname, 00229 int dimension, int rank, const charArray& layername) 00230 : vectorname(vectorname), biasname(biasname), 00231 dimension(dimension), rank(rank), layername(layername) {} 00232 charArray vectorname; //< prefix of the internal parameter vector e.g. "v" 00233 charArray biasname; ///< prefix of the internal parameter vector used as bias for the neurons e.g. "h" 00234 int dimension; ///< length of the vector (number of units) 00235 int rank; ///< rank of the layer (0 are input layers) 00236 charArray layername; ///< name of the layer as displayed by the visualiser 00237 }ILayer; 00238 00239 typedef struct IConnection{ 00240 IConnection(const charArray& matrixname, const charArray& vector1, const charArray& vector2) 00241 : matrixname(matrixname), vector1(vector1), vector2(vector2) {} 00242 charArray matrixname; ///< matrix name is the prefix of the internal parameter matrix e.g. "A" 00243 charArray vector1; ///< vectorname of input layer 00244 charArray vector2; ///< vectorname of output layer 00245 }IConnection; 00246 00247 00248 typedef ILayer[maxNumberEntries] ilayerlist; 00249 typedef IConnection[maxNumberEntries] iconnectionlist; 00250 00251 Inspectable(); 00252 00253 virtual ~Inspectable(); 00254 00255 00256 /** The list of the names of all internal parameters given by getInternalParams(). 00257 The naming convention is "v[i]" for vectors 00258 and "A[i][j]" for matrices, where i, j start at 0. 00259 @return: list of keys 00260 */ 00261 virtual iparamkeylist getInternalParamNames() const; 00262 00263 00264 /** @return: list of values 00265 */ 00266 virtual iparamvallist getInternalParams() const; 00267 00268 00269 /** 00270 * This is the new style for adding inspectable values. Just call this 00271 * function for each parameter and you are done. 00272 * registers a single value 00273 * @param key the name of the inspectable, shown e.g. in guilogger 00274 * @param val the address of the value to inspect 00275 */ 00276 virtual void addInspectableValue(const iparamkey key, iparamval* val); 00277 00278 00279 /** 00280 * This is the new style for adding inspectable values. Just call this 00281 * function for each parameter and you are done. 00282 * inspects all elements of the given matrix given through the functions 00283 * store4x4AndDiagonalFieldNames(Matrix& m,string& matrixName); 00284 * defined in <selforg/controller_misc.h> 00285 * @param key the name of the matrix, shown e.g. in guilogger 00286 * @param m the address of the matrix to inspect 00287 * @note that you can change the structure of the matrix while 00288 * being inspected. 00289 */ 00290 virtual void addInspectableMatrix(const iparamkey key, matrix::Matrix* m); 00291 00292 00293 00294 private: 00295 iparamkeylist ikeylist; 00296 iparamvallist ivallist; 00297 uint8_t numberParameters; 00298 00299 00300 }; 00301 #endif 00302 00303 #endif