RecurBayes.H

Go to the documentation of this file.
00001 /*!@file Learn/RecurBayes.H RecurBayesian network classifier */
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/RecurBayes.H $
00035 // $Id: RecurBayes.H 9108 2007-12-30 06:14:30Z rjpeters $
00036 //
00037 
00038 //This is a Naive RecurBayes for now
00039 #ifndef LEARN_BAYES_H_DEFINED
00040 #define LEARN_BAYES_H_DEFINED
00041 
00042 #include "Util/Types.H" // for uint
00043 #include <vector>
00044 #include <string>
00045 
00046 class RecurBayes
00047 {
00048 public:
00049 
00050   struct ClassInfo
00051   {
00052     ClassInfo(int id, double p, double sig) : classID(id), prob(p), statSig(sig) {} //constructor to set values
00053     int classID; //the class ID;
00054     double prob; //the probability of this class
00055     double statSig; //the statistical significance between the features value and the params
00056   };
00057 
00058   //! Construct a bayes classifer with a given number of features and
00059   //! number of classes
00060   RecurBayes(uint numClasses, uint numFeatures, uint nfix);
00061 
00062   //! Destructor
00063   ~RecurBayes();
00064 
00065   //! Learn to associate a feature vector with a particuler class name
00066   void learn(std::vector<double> &fv, const char *name, uint fix); //TODO make as a Template
00067 
00068   //! classify a given feature vector
00069   int classify(std::vector<double> &fv, double *prob = NULL, uint fix = 1); //TODO make as a template
00070 
00071   //! Get the mean for a particuler feature
00072   double getMean(uint cls, uint i, uint fix);
00073 
00074   //! Get the stdev Squared for a particuler feature
00075   double getStdevSq(uint cls, uint i, uint fix);
00076 
00077   //! Get the number of features
00078   uint getNumFeatures();
00079 
00080   //! Get the number of classes
00081   uint getNumClasses();
00082 
00083   //! Get the Freq of a given class
00084   uint getClassFreq(uint cls);
00085 
00086   //! Get the probability of a given class
00087   double getClassProb(uint cls);
00088 
00089   //! return the statistical significent of the FV for a given class
00090   double getStatSig(std::vector<double> &fv, uint cls, uint fix);
00091 
00092   //! Calculate a Normal Dist (use the srdev squared
00093   double gauss(double x, double mean, double stdevSq);
00094 
00095   //! Save the network to a file
00096   void save(const char *filename);
00097 
00098   //! Load the network from a file
00099   void load(const char *filename);
00100 
00101   //! set feature name (for debuging)
00102   void setFeatureName(uint index, const char *name);
00103 
00104   //! get feature name (for debuging)
00105   const char* getFeatureName(const uint index) const;
00106 
00107   //! Add class by name and return its Id
00108   int addClass(const char *name);
00109 
00110   //! Get the class name from a given Id
00111   const char* getClassName(const uint id);
00112 
00113   //! Get the class id from a given name
00114   int getClassId(const char *name);
00115 
00116 private:
00117 
00118   uint itsNumFeatures;   //the number of features we have
00119   uint itsNumClasses;   //the Number of classes we have
00120   uint itsNumFix;
00121   std::vector<std::vector<std::vector<double> > > itsMean;  //the mean for each feature per class per fixation
00122   //the stdev squared for each feature
00123   std::vector<std::vector<std::vector<double> > > itsVar;  //the variance for each feature per class per fixation
00124   //TODO: its long int sufficent? is there a better way of calc the mean and stdev?
00125   std::vector<uint64> itsClassFreq;   //the Freq of a given class
00126 
00127   std::vector<std::string> itsFeatureNames; //THe name of the features
00128   std::vector<std::string> itsClassNames;   //The names of the clases
00129 
00130 };
00131 
00132 // ######################################################################
00133 /* So things look consistent in everyone's emacs... */
00134 /* Local Variables: */
00135 /* indent-tabs-mode: nil */
00136 /* End: */
00137 
00138 #endif // LEARN_BAYES_H_DEFINED
Generated on Sun May 8 08:05:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3