TarzaNN
TarzaNN neural network simulator
C:/Users/albertlr/projects/TarzaNN/TarzaNN/common.h
Go to the documentation of this file.
00001 /****************************************************************************
00002  **
00003  ** Copyright C 2002-2012 Laboratory for Active and Attentive Vision (LAAV), Department of Computer Science and Engineering, York University, Toronto, ON, Canada.
00004  ** All rights reserved.
00005  **
00006  ** This file is part of the TarzaNN Neural Network Simulator.
00007  **
00008  ** This file may be distributed and/or modified under the terms of the
00009  ** GNU General Public License version 2 as published by the Free Software
00010  ** Foundation and appearing in the file LICENSE.GPL included in the
00011  ** packaging of this file.
00012  **
00013  ** See http://www.tarzann.org/gpl/ for GPL licensing information.
00014  **
00015  ** Contact info@tarzann.org if any conditions of this licensing are
00016  ** not clear to you.
00017  **
00018  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00019  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00020  **
00021  ****************************************************************************/
00022 
00023 #ifndef COMMON_H_INCLUDED
00024 #define COMMON_H_INCLUDED
00025 
00026 #define ERROR_LOCATION " (" << __FILE__ << ":" <<  __LINE__ << ")"
00027 #define NOT_IMPLEMENTED qDebug() << "!!!ERROR: NOT IMPLEMENTED"  << ERROR_LOCATION;
00028 #define FILE_LINE_ERROR printf("!!!ERROR: NOT IMPLEMENTED in file %s, line %i  \n",__FILE__,__LINE__)
00029 #define INVALID_FUNCTION_CALL printf("!!!ERROR: INVALID FUNCTION CALL in file %s, line %i  \n",__FILE__,__LINE__)
00030 #define PI 3.1415926
00031 
00032 #if  defined(__i386__) && defined(__APPLE__)
00033 #define MAC_OS_INTEL
00034 #endif
00035 
00036 #include <QHash>
00037 #include <QMap>
00038 #include <QMapIterator>
00039 #include <QString>
00040 #include <QPair>
00041 #include "UI_Message.h"
00042 
00043 #ifdef __APPLE__
00044 #include "GLUT/glut.h"
00045 #endif
00046 
00047 using namespace std;
00048 
00052 #define PERMANENT_GU
00053 
00057 #define ST_CONVOLVE
00058 
00059 /****************** DEFINED TYPES **************************************/
00060 // Important
00061 // each enum type has two static variables associated with it in common class
00062 // every time you make changes (add / edit /remove) reflect the changes in common.cpp in the
00063 // appropriate place !
00064 
00066 typedef enum  {LAYER_DEFAULT=0, LAYER_MOTION=1} LayerTypes;
00067 
00069 typedef enum  {FP_NOT_INITIALIZED=0, FP_DEFAULT=1, FP_INPUT=2, FP_INPUT_CONTROLLER=4, FP_INPUT_SOCKET=5, FP_INPUT_VIRTUAL=6, FP_INPUT_CONST=8, FP_INPUT_MULTIPLE=10, FP_PROXY=16, FP_MOTION=32, FP_MG_MOTION=64, FP_BP_LEARNING=128, FP_SOM_LEARNING=130, FP_STSOM_LEARNING=131, FP_CTSOM_LEARNING=132, FP_INPUT_LEARNING=256, FP_HISTOGRAM=512, FP_SALIENCY=513, FP_SALIENCYOUTPUT = 514, FP_FHM = 515, FP_INPUTCAMERA = 516, FP_INPUT_TASK=1024 } FPTypes;
00070 // it is important that we maintain the number convention for FP_INPUT_*, 'cause there are some bitwise operations that depend on it
00071 //note - I think this is obsolete (or at least not used anywhere except for UI_FeaturePlane.cpp for FP_INPUT_CONTROLLER, where it could be replaced with simple comparison)
00072 
00074 enum {F_G=100, F_DOG=101, F_W=102, F_DOUBLEW=103, F_RETINAL=104, F_DEFAULT=105, F_LOG=106, F_FILE=107, F_AVG=107, F_IDENTITY=108, F_HISTOGRAM=109, F_RECT=110, F_RANDOM=111}; 
00075 
00077 enum {INPUT_TYPE_REGULAR=200, INPUT_TYPE_MASKING=201, INPUT_TYPE_NON_FOURIER=202, INPUT_TYPE_GATING_CONTROL=203, INPUT_TYPE_ERROR=204};
00078 
00080 //enum {NONE_PROXY=300, RECEIVER_PROXY=301, SENDER_PROXY=302}; // feature plane proxy
00081 
00083 enum {NEURON_TYPE_SIGMOID=400, NEURON_TYPE_SPIKING=401, NEURON_TYPE_GENERIC=402, NEURON_TYPE_WILSON_COWAN=403, NEURON_TYPE_LINEAR_SIGMOID=404, NEURON_TYPE_TANH=405, NEURON_TYPE_LINEAR=406, NEURON_TYPE_ST=407 }; //neuron abstract
00084 
00086 enum {SYNC_TYPE_SYNC=500, SYNC_TYPE_ASYNC=501}; // NotifyStrategyAbstract
00087 
00089 enum { ERROR_NONE, 
00090         ERROR_EMPTY_OP_ARGUMENT, 
00091         ERROR_NO_FILTER_DEF_FOUND, 
00092         ERROR_MATRIX_ALLOC_ERROR, 
00093         ERROR_MATRIX_GATING_ERROR, 
00094         ERROR_INVALID_NEURON_TYPE,
00095         ERROR_INVALID_SYNC_TYPE,
00096         ERROR_INVALID_INPUT_POSITION,
00097     ERROR_INVALID_INPUT_CATEGORY,
00098     ERROR_IFP_FOUND,
00099         ERROR_HISTOGRAM,
00100         ERROR_CAMERA};
00101 
00102 //typedef QMap<myOrderedString, QString> paramMap;
00103 typedef QMap<QString, QString> paramMap;
00104 typedef QMap< int,QString> enumMap;
00105 typedef QMapIterator< int,QString> enumMapIterator;
00106 
00107 class common {
00108 public:
00110         static QStringList layerTypeList;
00111         static QStringList featurePlaneTypeList;
00112         static QStringList filterTypeList;
00113         static QStringList proxyTypeList;
00114         static QStringList neuronTypeList;
00115         static QStringList neuronInputTypeList;
00116         static QStringList syncTypeList;
00117         static QStringList boolTypeList;
00118         
00120         static enumMap layerTypes;
00121         static enumMap featurePlaneTypes;
00122         static enumMap filterTypes;
00123         static enumMap proxyTypes;
00124         static enumMap neuronTypes;
00125         static enumMap neuronInputTypes;
00126         static enumMap syncTypes;
00127         
00128         
00129         static void initializeTypes();
00130         static QString  getType(enumMap* theList, int value);
00131         static int getType(enumMap* theList, const QString & name);     
00132         
00133 private:
00134         static void setupTypeList(enumMap* theMap, QStringList *theList);
00135 };
00136 
00137 /*activate to get predefined networks*/
00138 /*OLD code, not maintained*/
00139 //#define PREDEFINED
00140 
00141 #define VISIBLE true
00142 #define NOT_VISIBLE false
00143 #define IS_WTA true
00144 #define NOT_WTA false
00145 
00146 // ******************** SVD *********************************************
00147 // the following defines are for the functions below, used by svd - from numerical methods
00148 #define ROUND(_AA) ((_AA) > 0 ? (uint32_t)((_AA)+0.5) : (uint32_t)((_AA)-0.5)) 
00149 #define SIGN(_AA,_BB) (((_BB)>0)?fabs(_AA):(-1)*fabs(_AA))
00150 #define FMAX(_AA,_BB) (((_AA)>(_BB))?(_AA):(_BB))
00151 #define FMIN(_AA,_BB) (((_AA)<(_BB))?(_AA):(_BB))
00152 #define IMIN(_AA,_BB) (((_AA)<(_BB))?(_AA):(_BB))
00153 #define SQR(_AA) ((_AA)*(_AA))
00154 #define IN_RANGE(A,LOWER,UPPER) (((A)>=(LOWER)) && ((A) <= (UPPER)))
00155 #define PYTHAGORA(X,Y) sqrt((double)((X)*(X)+(Y)*(Y)))
00156 #define DIST(X1,Y1,X2,Y2) sqrt((double)(((X1)-(X2))*((X1)-(X2)) + ((Y1)-(Y2))*((Y1)-(Y2))))
00157 
00158 
00159 // **************** TRACE *********************************************
00160 #define TRACE_THREADING 5
00161 #define TRACE_MACRO
00162 
00163 #ifndef TRACE_LEVEL
00164 #define TRACE_LEVEL 1
00165 #endif /*TRACE_LEVEL*/
00166 
00167 #ifdef TRACE_MACRO
00168 #define TRACE(LEVEL,X) ((LEVEL) > TRACE_LEVEL) ? printf(""); : X
00169 #else
00170 #define TRACE(LEVEL,X) ;
00171 #endif
00172 
00173 // **************** OPEN GL ERROR *********************************************
00174 #define OPENGL_ERROR {int e=GL_NO_ERROR;\
00175         e=glGetError();\
00176         if(e!=GL_NO_ERROR){\
00177                 printf("OPEN GL ERROR  %s (%s line %i)\n", gluErrorString(e),__FILE__,__LINE__);fflush(stdout);}\
00178 }
00179 
00180 // *************** Clear vector of pointers ***********
00181  template <class Vector>
00182   void clearPtrVector(Vector &a)
00183   {
00184     for(size_t i = 0; i < a.size(); i++)
00185          delete a[i];
00186 
00187     a.clear();
00188   }
00189 
00190 
00191 // *************** BIG ENDIAN LITTLE ENDIAN HELPER FUNCTIONS ***********
00192 int networkToHost(int value);
00193 void networkToHost(char *data,int length);
00194 int hostToNetwork(int value);
00195 void hostToNetwork(char *data,int length);
00196 
00197 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
00198 #define HTON(X,Y) hostToNetwork((X),(Y));
00199 #define NTOH(X,Y) networkToHost((X),(Y));
00200 #else
00201 #define HTON(X,Y) ;
00202 #define NTOH(X,Y) ;
00203 #endif
00204 
00205 // ************** PLATFORM SPECIFIC **********************************
00206 #ifdef WIN32
00207 #define FILE_DELIM '\\'
00208 #define SLEEP(X) Sleep(X)
00209 #include <windows.h>
00210 #elif defined __linux__
00211 #include <unistd.h>
00212 #define FILE_DELIM '/'
00213 #define SLEEP(X) usleep(1000*X)
00214 #else
00215 #define FILE_DELIM '/'
00216 #define SLEEP(X) sleep(X)
00217 #endif/*Q_OS_WIN*/
00218 
00219 #endif /*COMMON_H_INCLUDED*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines