SingleChannelSurprise.C

Go to the documentation of this file.
00001 /*!@file Surprise/SingleChannelSurprise.C Channel for a single stream of processing. */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Surprise/SingleChannelSurprise.C $
00035 // $Id: SingleChannelSurprise.C 11562 2009-08-08 00:35:40Z dberg $
00036 //
00037 
00038 #include "Surprise/SingleChannelSurprise.H"
00039 
00040 #include "Channels/ChannelOpts.H"
00041 #include "Channels/SingleChannel.H"
00042 #include "Component/ModelOptionDef.H"
00043 #include "Component/OptionManager.H"
00044 #include "Surprise/SurpriseOpts.H"
00045 #include "Raster/Raster.H"
00046 #include "Image/ShapeOps.H"
00047 #include "Image/Normalize.H"
00048 #include "Image/MathOps.H"
00049 #include "rutz/demangle.h"
00050 
00051 #include <iostream>
00052 #include <fstream>
00053 #include <typeinfo>
00054 
00055 // ######################################################################
00056 template <class SMODEL>
00057 SingleChannelSurprise<SMODEL>::
00058 SingleChannelSurprise(OptionManager& mgr) :
00059   SubmapAlgorithm(mgr, "Single Channel Surprise", "SingleChannelSurprise"),
00060   itsSQlen(&OPT_SingleChannelSurpriseSQlen, this),
00061   itsUpdateFac(&OPT_SingleChannelSurpriseUpdFac, this),
00062   itsNeighUpdateFac(&OPT_SingleChannelSurpriseNeighUpdFac, this),
00063   itsInitialVal("SingleChannelSurpriseIniVal", this, 0.0),
00064   itsInitialVar("SingleChannelSurpriseIniVar", this, 25.0),
00065   itsBgVal("SingleChannelSurpriseBgVal", this, 5.0),
00066   itsNeighSigma(&OPT_SingleChannelSurpriseNeighSigma, this),
00067   itsLocSigma(&OPT_SingleChannelSurpriseLocSigma, this),
00068   itsTakeSTMax(&OPT_SingleChannelSurpriseTakeSTMax, this),
00069   itsLogged(&OPT_SingleChannelSurpriseLogged, this),
00070   itsLevelSpec(&OPT_LevelSpec, this),
00071   itsProbe(&OPT_SingleChannelSurpriseProbe, this),
00072   itsSLfac(&OPT_SingleChannelSurpriseSLfac, this),
00073   itsSSfac(&OPT_SingleChannelSurpriseSSfac, this),
00074   itsJointKLBiasTypeStr(&OPT_SingleChannelSurpriseKLBias, this),
00075   itsSmap(), itsLogEntry(0U)
00076 {
00077   this->setDescriptiveName(std::string("Single Channel ") +
00078                            rutz::demangled_name(typeid(SMODEL)));
00079   this->setTagName(std::string("SingleChannel") +
00080                    rutz::demangled_name(typeid(SMODEL)));
00081 }
00082 
00083 // ######################################################################
00084 template <class SMODEL>
00085 SingleChannelSurprise<SMODEL>::~SingleChannelSurprise()
00086 { }
00087 
00088 // ######################################################################
00089 template <class SMODEL>
00090 void SingleChannelSurprise<SMODEL>::start1()
00091 {
00092   int maxind = itsLevelSpec.getVal().maxIndex();
00093 
00094   if(!strcmp(itsJointKLBiasTypeStr.getVal().c_str(),"Static"))
00095     itsJointKLBiasType = SU_KL_STATIC;
00096   else
00097     itsJointKLBiasType = SU_KL_NONE;
00098 
00099   SurpriseMap<SMODEL> initial;
00100   initial.init(itsSQlen.getVal(), itsUpdateFac.getVal(),
00101                itsNeighUpdateFac.getVal(),
00102                itsInitialVal.getVal() + itsBgVal.getVal(),
00103                itsInitialVar.getVal(), itsNeighSigma.getVal(),
00104                itsLocSigma.getVal(), itsProbe.getVal(),
00105                itsSLfac.getVal(), itsSSfac.getVal(),
00106                itsJointKLBiasType, itsTakeSTMax.getVal());
00107 
00108   for (int i = 0; i < maxind; i ++) itsSmap.push_back(initial);
00109 }
00110 
00111 // ######################################################################
00112 template <class SMODEL>
00113 Image<float> SingleChannelSurprise<SMODEL>::getSurpriseMap(const uint index,
00114                                                    const Image<float>& submap)
00115 {
00116   Image<double> submapd = submap;
00117   if (itsBgVal.getVal()) submapd += itsBgVal.getVal(); // add bg firing rate
00118 
00119   // create a SurpriseImage from the submap:
00120   Image<double> var(submap.getDims(), NO_INIT);
00121   var.clear(itsInitialVar.getVal());
00122 
00123   SurpriseImage<SMODEL> sample(itsUpdateFac.getVal(), submapd, var);
00124 
00125   // now inject that into our models and get the surprise:
00126   return Image<float>(itsSmap[index].surprise(sample));
00127 }
00128 
00129 // ######################################################################
00130 template <class SMODEL>
00131 Image<float> SingleChannelSurprise<SMODEL>::
00132 compute(const SingleChannel& chan, const uint i)
00133 {
00134 // implementation that computes surprise at full map resolution
00135 // return chan.postProcessMap(this->getSurpriseMap(i, chan.getRawCSmap(i)), i)
00136   return this->getSurpriseMap
00137     (i, chan.postProcessMap(chan.getRawCSmap(i), i));
00138 }
00139 
00140 // ######################################################################
00141 // Explicit instantiations:
00142 
00143 template class SingleChannelSurprise<SurpriseModelSG>;
00144 template class SingleChannelSurprise<SurpriseModelSP>;
00145 template class SingleChannelSurprise<SurpriseModelSP1>;
00146 template class SingleChannelSurprise<SurpriseModelSPC>;
00147 template class SingleChannelSurprise<SurpriseModelSPF>;
00148 template class SingleChannelSurprise<SurpriseModelCS>;
00149 template class SingleChannelSurprise<SurpriseModelGG>;
00150 template class SingleChannelSurprise<SurpriseModelPM>;
00151 template class SingleChannelSurprise<SurpriseModelOD>;
00152 
00153 
00154 // ######################################################################
00155 /* So things look consistent in everyone's emacs... */
00156 /* Local Variables: */
00157 /* indent-tabs-mode: nil */
00158 /* End: */
Generated on Sun May 8 08:06:52 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3