contourRun.H

Go to the documentation of this file.
00001 /*!@file CINNIC/contourRun.H CINNIC classes */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CINNIC/contourRun.H $
00035 // $Id: contourRun.H 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef CONTOURRUN_H_DEFINED
00039 #define CONTOURRUN_H_DEFINED
00040 
00041 #include "CINNIC/cascadeHold.H"
00042 #include "CINNIC/contourNeuron.H"
00043 #include "CINNIC/contourNeuronProp.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "Raster/Raster.H"
00047 #include <vector>
00048 
00049 #define initSize 50 //This is the inital size of the vector
00050 
00051 // ############################################################
00052 // ############################################################
00053 // ##### ---CINNIC---
00054 // ##### Contour Integration:
00055 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00056 // ############################################################
00057 // ############################################################
00058 //CLASSES:
00059 //NeuronChargeHold
00060 //ContourNeuronProp
00061 //RunNeuron
00062 
00063 
00064 
00065 //###############################################################
00066 //Holder of the basic properties of each contour neuron
00067 //HOW THE HECK DOES THIS CLASS WORK...
00068 //this class stores and releises charges for the CINNIC neurons
00069 //Other neurons will place a charge in into this neuron using the
00070 //Charge method. These charges are stored in a resizable vector
00071 //in a container class called NeuronChargeHold which is then
00072 //stored in a vector called HistoryVector.
00073 //
00074 //When it is a neurons turn to run it does several things. This classes
00075 //part is to take a charge from another neuron that is running and store it
00076 //int this neuron. When this neuron runs it then handles requests to hand
00077 //back the charges stored in here so that this neuron can pass a charge
00078 //to another neuron with an appropriate charge.
00079 
00080 //##########################################################################
00081 
00082 //This class will run the CINNIC neuron on a given Matrix of angle values
00083 //to another node. This is factored with timestep.
00084 //static ContourNeuronPropVec (*NeuronMatrix)[ImageSizeX][ImageSizeY];
00085 
00086 //! Run the hyper column on a given image with a given connection template
00087 /*! This is the central iterative process to CINNIC. It takes as input
00088   a 3D ImageMap and a 4D PropHold made from ContourNeuronCreate. It matches
00089   each neuron in the hyper column against each other neuron in the
00090   hyper column. Energy is tranfered to the other neuron based on a product
00091   of the two neurons current exitation from the ImageMap and the weight of
00092   thier connections. A negative weight signifies inhabition. Energys are
00093   allowed to build iteratively in an upper layer SalMap built into this class.
00094 */
00095 class contourRun
00096 {
00097 private:
00098   float timestep,maxEnergy,iterations,BaseThreshold;
00099   float upperLimit,iTrans,fastPlast;
00100   float GroupTop, GroupBottom, supressionAdd;
00101   float supressionSub, adaptNeuronThresh,orThresh;
00102   float adaptNeuronMax,leak,initialGroupVal;
00103   float passThroughGain;
00104   float passThroughTaper;
00105   int cascadeType,adaptType,doFastPlast,lastIterOnly,doTableOnly;
00106   const char* saveto;
00107   int dumpSwitchPos;
00108   const char* imageSaveTo;
00109   const char* logSaveTo;
00110   int setImageSizeX, setImageSizeY; //the size of the image
00111   float energy,cascadeStore,castemp,excMult;
00112   int cascadeChunk,posCount,negCount,totCount;
00113   int Groups;
00114   int InspX, InspY; //Neuron being inspected by current neuron
00115   int Insp2X, Insp2Y;
00116   bool pol,sender,Mypol,Mysender;
00117   int cascadeCounter;
00118   //! stores values for subsequent iterations
00119   float *storeVal;
00120   Image<float> overlay;
00121   Image<PixRGB<float> > overlayS;
00122   Image<float> Finput;
00123   Image<float> SM;
00124   Image<float> Group;
00125   Image<int> cascadeSize;
00126   Image<cascadeHold> ICH;
00127   std::vector<float> GroupMod;
00128   std::vector<float> GroupMod2;
00129   std::vector<float> GroupHold;
00130   std::vector< Image<float> > SMI;
00131   std::vector< Image<PixRGB<float> > >cascadeMap;
00132   std::vector< Image<float> > GroupMap;
00133   std::vector< Image<float> > imageOpt;
00134   std::vector< Image<float> > combinedSalMap;
00135   const Point2D<int> *point;
00136   std::vector<Image<cascadeHold> > cascadeImage;
00137   std::vector<cascadeHold> cascade;
00138   ContourNeuronCreate<float> *Neuron; //copy the generic neuron
00139   PropHold *Neurons; //hold a property set for each neuron
00140   ContourNeuronProp<float,int,int> prop;
00141   std::vector<  ContourNeuronProp<float,int,int> > mat1;
00142   std::vector< std::vector< ContourNeuronProp<float,int,int> > > mat2;
00143   std::vector< std::vector< std::vector< ContourNeuronProp<float,int,int> > > > mat3;
00144   std::vector< std::vector< std::vector< std::vector<
00145   ContourNeuronProp<float,int,int> > > > > NeuronMatrix;
00146 
00147   //*********************************************************************
00148   // Private member function
00149   //*********************************************************************
00150 
00151   //! Set up initial values and optimizations, run before runImage
00152   void preImage(std::vector< Image<float> > &imageMap,
00153                 ContourNeuronCreate<float> &N);
00154   //! Like runImage except that a sigmoid is used to approximate neuron fireing rate
00155   /*! Insted of using neuron firering potential is
00156     routed through a sigmoid which
00157     approximates the rate of firering.
00158     @param Image This is the ImageMap of orientations
00159     @param N This is the contour neuron template
00160   */
00161   void runImageSigmoid(std::vector< Image<float> > &imageMap,
00162                        ContourNeuronCreate<float> &N, int iter);
00163   //! Calculate group suppression changes
00164   /*! find new group weights based on the delta of excitation
00165     @param Image This is the ImageMap of orientations
00166     @param N This is the contour neuron template
00167   */
00168   void calcGroups(std::vector< Image<float> > &imageMap,
00169                        ContourNeuronCreate<float> &N, int iter);
00170 
00171    //! one iterative process, as exaple called from runImage. Math using convolution
00172   /*! This accounts for one iterations at a time of the hyper column
00173     it will take the ImageMap and template neuron from ContourNeuronCreate
00174     and calculate this iterations energy values
00175     @param iter This is the current iteration number
00176     @param Image The 3D image map of orientations
00177     @param N The emplate neuron
00178     @param node The node number of this process,
00179     defaults to -1 for singe process operations
00180   */
00181   inline void iterateConvolve(int iter,std::vector< Image<float> > &imageMap,
00182                               ContourNeuronCreate<float> &N, const int node = -1);
00183   //! This is the second part of iterate convolve using the convolutoins
00184   /*! This accounts for one iterations at a time of the hyper column
00185     it will take the ImageMap and template neuron from ContourNeuronCreate
00186     and calculate this iterations energy values
00187     NOTE: This version excludes cascades
00188     @param iter This is the current iteration number
00189     @param Image The 3D image map of orientations
00190     @param N The emplate neuron
00191     @param node The node number of this process, defaults to -1
00192     for singe process operations
00193   */
00194   inline void convolveSimple(int iter,std::vector< Image<float> > &imageMap,
00195                              ContourNeuronCreate<float> &N,
00196                              const int a, const int b, const int node = -1);
00197   //! Calculate f with sigmoid described in Kock, Biophysics of Computation
00198   /*! @param beta This is a positive constant for the gain rate
00199     @param v This is the generator potential
00200     For beta higher numbers mean faster gain. a beta of 1
00201     will start at approx -1 and
00202     go to 1 with a v of 0 f will be .5 in all cases
00203   */
00204   float sigmoid(float beta, float v);
00205    //! Another sigmoid function
00206   /* @param beta this is the ceiling for the function
00207      @param v this is the potential input
00208   */
00209   float sigmoid2(float beta, float v);
00210   //! This method is used to pre-process for sigmoid based on a threshold
00211   /*! @param beta The beta param in the sigmoid
00212     @param v The generator potential at its current level
00213     @param thresh This is the max threshold v should reach
00214   */
00215   float preSigmoid(float v, float thresh, float beta = 1);
00216   //! reset the energy matrix
00217   void resetMatrix();
00218   //! set the image size
00219   void setImageSize(int X, int Y);
00220   //! Set configurations for this run
00221   /*! @param readConfig This is the object that contains the config file*/
00222   void setConfig(readConfig &config);
00223 public:
00224   // ######################################################################
00225   // Public members etc.
00226   // ######################################################################
00227   long iterCounter;
00228   contourRun();
00229   ~contourRun();
00230   //! copy the combined sal map to this class for analysis or dumping
00231   void copyCombinedSalMap(std::vector< Image<float> > &CSM);
00232   //! set the storage array size for linear components in subsq. iteration
00233   void setArraySize(long size);
00234   //! returned the processed salmap for this object at iter
00235   Image<float> getSMI(int iter);
00236   //! set number of iterations
00237   void setIterations(int iter);
00238   //! find the time to total energy ratio
00239   void deriveEnergy();
00240   //! Dump energy values computed with sigmoidal process
00241   /*!@param filename The base name to give this file, should include path
00242     @param savefile The tailend of the file name
00243     @param readConfig the config file object
00244   */
00245   void dumpEnergySigmoid(const char* filename, const char* savefile,
00246                          readConfig &config, Image<float> image,
00247                          int scaleNo, int scaleTot);
00248   //! This is a short cut method to run runImage + other methods
00249   /*! This will run setConfig setImageSize, resetMatrix and runImage
00250     for you.
00251     @param Image the processed image map of orientations from ImageMap
00252     @param N This is the generic neuron template from ContourNeuronCreate
00253     @param config This is the config file object from readConfig.C
00254     @param sizeX The size of the image in X
00255     @param sizeY The size of the image in Y
00256   */
00257   void contourRunMain(std::vector< Image<float> > &imageMap,
00258                       ContourNeuronCreate<float> &N
00259                       ,readConfig &config, Image<float> &group,
00260                       int groups,int iter, float groupTop);
00261 
00262 };
00263 
00264 // ######################################################################
00265 /* So things look consistent in everyone's emacs... */
00266 /* Local Variables: */
00267 /* indent-tabs-mode: nil */
00268 /* End: */
00269 
00270 #endif
Generated on Sun May 8 08:40:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3