Scorer.H

Go to the documentation of this file.
00001 /*!@file TIGS/Scorer.H Score the fit between predicted and actual eye positions */
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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TIGS/Scorer.H $
00035 // $Id: Scorer.H 9132 2008-01-15 21:45:31Z rjpeters $
00036 //
00037 
00038 #ifndef TIGS_SCORER_H_DEFINED
00039 #define TIGS_SCORER_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Util/log.H"
00043 #include "rutz/rand.h"
00044 
00045 #include <iosfwd>
00046 #include <string>
00047 
00048 /// Score the fit between predicted and actual eye positions
00049 class Scorer
00050 {
00051 public:
00052   virtual ~Scorer();
00053 
00054   virtual void accum(const Image<float>& eyeposmap, int pos) = 0;
00055 
00056   virtual std::string getScoreString(const std::string& name) = 0;
00057 };
00058 
00059 struct KLScorer : public Scorer
00060 {
00061   KLScorer(int nbins, int nrand);
00062 
00063   virtual ~KLScorer();
00064 
00065   virtual void accum(const Image<float>& eyeposmap, int pos);
00066 
00067   virtual std::string getScoreString(const std::string& name);
00068 
00069 private:
00070   static rutz::urand theirGenerator;
00071 
00072   int itsNbins;
00073   int itsNrand;
00074   Image<int> itsObservedBins;
00075   Image<int> itsRandomBins;
00076   int itsNtrials;
00077 };
00078 
00079 class NssScorer : public Scorer
00080 {
00081 public:
00082   NssScorer();
00083 
00084   virtual void accum(const Image<float>& eyeposmap, int pos);
00085 
00086   virtual std::string getScoreString(const std::string& name);
00087 
00088   double getCurrentZscore() const
00089   {
00090     if (observedCount <= 0)
00091       LFATAL("no zscore observations");
00092 
00093     return currentZscore;
00094   }
00095 
00096   double getOverallZscore() const
00097   {
00098     if (observedCount <= 0)
00099       LFATAL("no zscore observations");
00100 
00101     return observedZscore / observedCount;
00102   }
00103 
00104 private:
00105   double currentZscore;
00106   double observedZscore;
00107   double maxZscore;
00108   int observedCount;
00109 };
00110 
00111 class PercentileScorer : public Scorer
00112 {
00113 public:
00114   PercentileScorer();
00115 
00116   virtual void accum(const Image<float>& eyeposmap, int pos);
00117 
00118   virtual std::string getScoreString(const std::string& name);
00119 
00120   double getCurrentPrctile() const
00121   {
00122     if (observedCount <= 0)
00123       LFATAL("no prctile observations");
00124 
00125     return currentPrctile;
00126   }
00127 
00128   double getOverallPrctile() const
00129   {
00130     if (observedCount <= 0)
00131       LFATAL("no prctile observations");
00132 
00133     return observedPrctile / observedCount;
00134   }
00135 
00136 private:
00137   double currentPrctile;
00138   double observedPrctile;
00139   int observedCount;
00140 };
00141 
00142 /// Saliency-weighted prediction error scorer
00143 class SwpeScorer : public Scorer
00144 {
00145 public:
00146   SwpeScorer();
00147 
00148   virtual void accum(const Image<float>& eyeposmap, int pos);
00149 
00150   virtual std::string getScoreString(const std::string& name);
00151 
00152 private:
00153   Dims itsDims;
00154   double itsEyeScore;
00155   double itsRandEyeScore;
00156   double itsRandMapScore;
00157   double itsFlatMapScore;
00158   int itsObservedCount;
00159 
00160   rutz::urand itsGenerator;
00161 };
00162 
00163 struct MulticastScorer
00164 {
00165   MulticastScorer();
00166 
00167   void score(const std::string& name,
00168              const Image<float>& eyeposmap, int pos);
00169 
00170   void showScore(const std::string& name);
00171 
00172   void writeScore(const std::string& name, std::ostream& os);
00173 
00174   int observedCount;
00175   PercentileScorer itsPrctileScorer;
00176   NssScorer itsNssScorer;
00177   KLScorer itsKLScorer;
00178   SwpeScorer itsSwpeScorer;
00179 };
00180 
00181 // ######################################################################
00182 /* So things look consistent in everyone's emacs... */
00183 /* Local Variables: */
00184 /* mode: c++ */
00185 /* indent-tabs-mode: nil */
00186 /* End: */
00187 
00188 #endif // TIGS_SCORER_H_DEFINED
Generated on Sun May 8 08:42:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3