SOFM.H

Go to the documentation of this file.
00001 /*!@file Learn/SOFM.H Self-Organizing Map neural network  */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Learn/SOFM.H $
00035 // $Id: SOFM.H 13223 2010-04-15 00:52:46Z lior $
00036 //
00037 
00038 #ifndef LEARN_SOFM_H_DEFINED
00039 #define LEARN_SOFM_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Image/Pixels.H"
00043 #include "Image/ColorOps.H"
00044 
00045 class SOFM
00046 {
00047 public:
00048   enum DISTANCE_MEASURE {EUCLIDEAN, KL,L2GMM};
00049 
00050   SOFM(const char *netname, int InputSize, int x, int y);                        //init with map size x y
00051   ~SOFM();
00052   void SetLearningRate(unsigned long long learning_time);
00053   void Train(float *Input, float *Target, double score);
00054   void organize(std::vector<double> &input);
00055   void organize(const Image<float>& input);
00056   Image<float> getMap();
00057   Image<float> getActMap();
00058   Image<PixRGB<byte> > getWeightsImage();
00059   std::vector<float> getWeights(const Point2D<int> loc);
00060 
00061   void ReadNet(const char *filename);
00062   void WriteNet(const char *filename);
00063   double RandomRange(double Low, double High);
00064   double RandomBinaryRange(double Low, double High);
00065   double Neighborhood(int i);
00066   void RandomWeights(int min = 0, int max = 255);
00067   void ZeroWeights();
00068   void SetInput(float *in);
00069   void setInput(const std::vector<double> &in);
00070   void setInput(const Image<float> &in);
00071   void Propagate(DISTANCE_MEASURE dm = EUCLIDEAN);
00072   Point2D<int> getWinner(double& val);
00073 
00074 
00075   //private:
00076   struct Layer {
00077     int Units;                                //number of units
00078     double *Output;                //output of i unit
00079     float **Weight;                //connection weightto i unit
00080     double *StepSizeX;                //size of search steps of i unit
00081     double *StepSizeY;                //size of search steps of i unit
00082     double *dScoreMean;        //mean score delta of i unit
00083     double *score;                        // the previous score for this move
00084     int          *BadDim;                // the dimintion that we need to work on
00085     double *Lambda;                //for displyaing the neigborhood of units
00086   };
00087 
00088   Layer                *InputLayer;
00089   Layer                *KohonenLayer;
00090   int                itsWinner;
00091   double             itsWinnerValue;
00092   int                itsLooser;
00093   double             itsLooserValue;
00094   int                MapSizeX;
00095   int                MapSizeY;
00096 
00097   const char    *name;                                        // the name of the network for saving
00098   double        KohonenAlpha;                                //learning rate of Kohonen layer
00099   double        OutAlpha;                                        //learning rate of output layer
00100   double        StepAlpha;                                        //learning rate for  step sizes
00101   double        Gamma;                                                //smoothing factor for score deltas
00102   double        Sigma;                                                //width of neighoborhood
00103   unsigned long long itsLearningTime;          //The current learning time
00104 
00105 
00106   void InitSofm();
00107 
00108 
00109 };
00110 
00111 // ######################################################################
00112 /* So things look consistent in everyone's emacs... */
00113 /* Local Variables: */
00114 /* indent-tabs-mode: nil */
00115 /* End: */
00116 
00117 #endif // LEARN_SOFM_H_DEFINED
Generated on Sun May 8 08:05:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3