Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

kernel.h

Go to the documentation of this file.
00001 
00006 #ifndef __KERNEL_H__
00007 #define __KERNEL_H__
00008 
00009 #include <vector>
00010 
00011 #include "globals.h" 
00012 #include "tristate.h"
00013 #include "matrix.h"
00014 
00015 
00016 
00017 /******************************************************************************/
00018 /* Defines and typedefs                                                       */
00019 /******************************************************************************/
00020 
00032 #define PARTIAL_LAT_INDEX(ui,uj,k,radius,width) (((k)-(ui)+(radius))*(width)-(uj)+(radius))
00033 #define FULL_LAT_INDEX(partial_index,l) ((partial_index)+(l))
00034 #define LAT_INDEX(ui,uj,k,l,radius,width) FULL_LAT_INDEX(PARTIAL_LAT_INDEX((ui),(uj),(k),(radius),(width)),(l))
00035 
00036 
00037 
00038 /* MAP/LOCAL ROW CONVERSION:  These hide how rows are distributed to PEs      */
00039 
00042 #define MAPROW(localrow) (ARBITRARY_MAPROW((localrow),MyPE))
00043 #define ARBITRARY_MAPROW(localrow,pe) (pe+(localrow)*NPEs)
00044 
00047 #define LOCALROW(maprow) ((maprow)/NPEs)
00048 
00050 #define PEFORROW(maprow) ((maprow)%NPEs)
00051 
00053 #define ROWISLOCAL(maprow) (ARBITRARY_ROWISLOCAL((maprow),MyPE))
00054 #define ARBITRARY_ROWISLOCAL(maprow,pe) ((pe)==PEFORROW(maprow))
00055 
00056 
00068 /* #define VERIFY_WEIGHT_SAVES */
00069 
00070 
00071 
00088 #define PARTIAL_INP_INDEX(eye,x) ((eye)*(RN*RN)+(x)*(RN))
00089 #define FULL_INP_INDEX(partial_inp_index,y) ((partial_inp_index)+(y))
00090 #define INP_INDEX(eye,x,y) FULL_INP_INDEX(PARTIAL_INP_INDEX((eye),(x)),(y))
00091 #define INP_INDEX_OTHER_EYE(eye,first_inp_index) ((first_inp_index) + ((eye)*RN*RN))
00092 
00093 
00094 
00095 /******************************************************************************/
00096 /* BasicLissomMap                                                             */
00097 /******************************************************************************/
00098 
00099 
00105 class BasicLissomMap {
00106 public:
00107   BasicLissomMap(int height, int width,
00108                  // These parameters should instead be deduced from
00109                  // add_input, but doing so would require breaking up
00110                  // init_weights, which would change the stream of 
00111                  // random numbers generated to initialize the weights,
00112                  // which would change every simulations' results,
00113                  // so it has been put off until other things settle
00114                  // down.
00115                  int num_aff_, int RN_, int rf_rad_, int exc_rad_, int inh_rad_, int NPEs) :
00116     exc_rad(exc_rad_), inh_rad(inh_rad_), rf_radius(rf_rad_),
00117     N(width), RN(RN_),
00118     aff_array_width(2*rf_radius+1),
00119     exc_array_width(2*exc_rad+1),
00120     inh_array_width(2*inh_rad+1),
00121     lat_exc_dimension(exc_array_width * exc_array_width),
00122     lat_inh_dimension(inh_array_width * inh_array_width),
00123     perows(N/NPEs),
00124   
00125 #ifdef VERIFY_WEIGHT_SAVES
00126   Orig_map(height,width),
00127   Orig_wts(perows,width),
00128 #endif
00129     
00130     cortex_map(height,width),
00131     wts(perows,width),
00132     reference_wts(num_aff_,aff_array_width,exc_array_width,inh_array_width)
00133     {
00134       (void)height;  assert (height==width);
00135 
00136       /* Copy addresses into map structure */
00137       for (int i=0; i< perows; i++)
00138         for (int j=0; j<N; j++){               
00139           
00140           wts[i][j] = Wts(num_aff_,aff_array_width,exc_array_width,inh_array_width);
00141             
00142           cortex_map[MAPROW(i)][j].lat_exc_wts = &(wts[i][j].lat_exc_wts[0]);
00143           cortex_map[MAPROW(i)][j].lat_inh_wts = &(wts[i][j].lat_inh_wts[0]);
00144           cortex_map[MAPROW(i)][j].weights     = &(wts[i][j].weights);
00145           
00146 #ifdef VERIFY_WEIGHT_SAVES
00147           Orig_wts[i][j] = Wts(num_aff_,aff_array_width,exc_array_width,inh_array_width);
00148             
00149           /* Copy addresses into duplicate map structure */
00150           Orig_map[MAPROW(i)][j].lat_exc_wts = &(Orig_wts[i][j].lat_exc_wts[0]);
00151           Orig_map[MAPROW(i)][j].lat_inh_wts = &(Orig_wts[i][j].lat_inh_wts[0]);
00152           Orig_map[MAPROW(i)][j].weights     = &(Orig_wts[i][j].weights);
00153 #endif
00154         }
00155   }
00156   
00157   virtual ~BasicLissomMap() { }
00158 
00159   typedef float a_weight;
00160   typedef float l_weight;
00161   typedef MatrixType<a_weight>::rectangular  AfferentWeights;
00162   typedef std::vector<AfferentWeights>       AfferentWeightsList;
00163   
00164   /* The record type for neurons in a map */
00165   struct Neuron {
00166     int centerx, centery         ; 
00167     AfferentWeightsList* weights ; 
00168     l_weight *lat_exc_wts        ; 
00169     l_weight *lat_inh_wts        ; 
00170   };
00171 
00172   
00174   struct Wts {
00177     Wts() { }
00178     
00180     Wts(int num_aff, int aff_width, int exc_width, int inh_width)
00181       : lat_exc_wts(exc_width*exc_width),
00182         lat_inh_wts(inh_width*inh_width) {
00183       for (int i=0; i<num_aff; i++)
00184         weights.push_back(AfferentWeights(aff_width,aff_width));
00185     }
00186 
00187     AfferentWeightsList weights;
00188     
00189     typedef std::vector<l_weight> LateralWeights;
00190     LateralWeights lat_exc_wts;
00191     LateralWeights lat_inh_wts;
00192   };
00193   
00194   virtual int    num_aff_inputs() const=0;
00195   
00196   /* Publically-accessible variables */
00197   int exc_rad; /* Can be changed */
00198   const int inh_rad;
00199   const int rf_radius;
00200   const int N;
00201   const int RN;
00202   
00203   const int aff_array_width;
00204   const int exc_array_width;
00205   const int inh_array_width;
00206   const int lat_exc_dimension;
00207   const int lat_inh_dimension;
00208   const int perows;
00209 
00210   typedef MatrixType<Neuron>::rectangular  MapType;
00211   typedef MatrixType<Wts>::rectangular     WtsType;
00212 
00214 #ifdef VERIFY_WEIGHT_SAVES
00215   MapType Orig_map;
00216   WtsType Orig_wts;
00217 #endif
00218 
00219   MapType cortex_map;
00220   WtsType wts;
00221 
00222 protected:
00224   Wts reference_wts; 
00225 };
00226 
00227 
00228 
00229 #endif

Generated on Mon Jan 20 02:35:44 2003 for RF-LISSOM by doxygen1.3-rc2