SurpriseModel.H

Go to the documentation of this file.
00001 /*!@file Surprise/SurpriseModel.H a local (single-point) model of surprise */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Surprise/SurpriseModel.H $
00035 // $Id: SurpriseModel.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef SURPRISEMODEL_H_DEFINED
00039 #define SURPRISEMODEL_H_DEFINED
00040 
00041 #include "Image/Point2D.H"
00042 #include "Image/Image.H"
00043 #include "Util/MathFunctions.H"
00044 
00045 enum SU_KL_BIAS
00046   {
00047     SU_KL_NONE,
00048     SU_KL_STATIC
00049   };
00050 
00051 // ######################################################################
00052 //! A local (single-point) surprise model
00053 /*! This the base class and it cannot be implemented as some of its
00054   functions are purely virtual. It defines the basic interface. See
00055   the derivative classes for actual implementations. */
00056 class SurpriseModel
00057 {
00058 public:
00059   //! Constructor
00060   /*! Build a new SurpriseModel object and initialize it as if an
00061     infinitely long sequence of samples had been previously received
00062     by the model.
00063     @param updatefac factor by which the current model is combine with
00064     a new model on an update. Valid values are in [0..1]
00065     @param sampleval the value of the samples previously received.
00066     @param samplevar a variance expressing the intrinsic variability
00067     in the measurement of those samples. */
00068   SurpriseModel(const double updatefac = 0.5, const double sampleval = 0.0,
00069                 const double samplevar = 1.0);
00070 
00071   // default copy-construction and copy operators OK.
00072 
00073   //! Virtual destructor ensures proper destruction of derived classes
00074   virtual ~SurpriseModel();
00075 
00076   //! Reset to initial state
00077   virtual void reset() = 0;
00078 
00079   //! Change intial state parameters
00080   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00081                     const double samplevar = 1.0);
00082 
00083   //! Reset our update factor
00084   virtual void resetUpdFac(const double updfac);
00085 
00086   //! Load given sample mean and variance
00087   virtual void load(const double sampleval = 0.0,
00088                     const double samplevar = 1.0) = 0;
00089 
00090   //! Compute surprise between us and another model
00091   /*! Surprise is the KL distance between our current model and what
00092     that model will become once we update it with the sample passed in
00093     as argument.  For the update, our current model is weighted by
00094     itsUpdateFac while the new model by (1.0-itsUpdateFac). Programmer
00095     note: derived classes will not provide a direct overload of this
00096     (and other) base functions, as instead they will implement
00097     functions with basically the same syntax but using an argument of
00098     the derived class. Since an implementation is not provided for
00099     this base function, you will get an error at link time if you call
00100     the derived functions with a base-class argument. */
00101   virtual double surprise(const SurpriseModel& sample);
00102 
00103   //! Pre compute hyper parameters before combineFrom
00104   /*! Some models may need to update their hyper parameters BEFORE
00105     calling combineFrom. Particularly if the parameters have a covariance
00106     measure which must be updated before the models are combined
00107   */
00108   virtual void preComputeHyperParams(const SurpriseModel& sample);
00109 
00110   //! Initialize us as a weighted combination of the given map of models
00111   /*! @param models an array of models, one model at each pixel of the image.
00112     @param weights the weight to be given to each model. Weights should sum
00113     to 1.0 and this is not checked for here for computational efficiency. */
00114   virtual void combineFrom(const Image<SurpriseModel>& models,
00115                            const Image<float>& weights);
00116 
00117   //! Initialize us as a weighted combination of the given map of models
00118   /*! @param models an array of models, one model at each pixel of the image.
00119     @param weights the weight to be given to each model. Weights
00120     should sum to 1.0 and this is not checked for here for
00121     computational efficiency. In this version, the weight image should
00122     have double+1 the width and height of the Surprise image, and the
00123     weight for the current point will be taken at the center of the
00124     weight map, etc.
00125     @param pos indicates the 2D coordinates of the center of the
00126     neighborhood in the Image
00127     @param minw is the minimum weight below which we just don't include a
00128     model in the update*/
00129   virtual void combineFrom(const Image<SurpriseModel>& models,
00130                            const Image<float>& weights,
00131                            const Point2D<int>& pos,
00132                            const int width, const int height, const int offset);
00133 
00134   //! Set up biases if needed for KL
00135   virtual void setBias(const double slfac,
00136                        const double ssfac,
00137                        const SU_KL_BIAS klbias);
00138   //! get our mean
00139   virtual double getMean() const = 0;
00140 
00141   //! get our variance
00142   virtual double getVar() const = 0;
00143 
00144   //! get our UpdateFac
00145   virtual double getUpdateFac() const = 0;
00146 
00147 
00148 
00149 protected:
00150   double itsUpdateFac;  //!< our update factor
00151   double itsInitialVal; //!< our initial value
00152   double itsInitialVar; //!< our initial variance
00153 };
00154 
00155 // ######################################################################
00156 //! A single-Gaussian SurpriseModel
00157 /*! This is a very simple SurpriseModel consisting of a single
00158   Gaussian, which is updated in a sliding-average manner. */
00159 class SurpriseModelSG : public SurpriseModel
00160 {
00161 public:
00162   //! Constructor. See base class for details.
00163   SurpriseModelSG(const double updatefac = 0.5, const double sampleval = 0.0,
00164                   const double samplevar = 1.0);
00165 
00166   //! Virtual destructor ensures proper destruction of derived classes
00167   virtual ~SurpriseModelSG();
00168 
00169   //! Reset to initial state
00170   virtual void reset();
00171 
00172   //! Change intial state parameters
00173   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00174                     const double samplevar = 1.0);
00175 
00176   //! Load given sample mean and variance
00177   virtual void load(const double sampleval, const double samplevar = 1.0);
00178 
00179   //! Compute surprise between us and another model
00180   virtual double surprise(const SurpriseModelSG& other);
00181 
00182   //! Is empty in this model
00183   virtual void preComputeHyperParams(const SurpriseModelSG& sample);
00184 
00185   //! Initialize us as a weighted combination of the given map of models
00186   virtual void combineFrom(const Image<SurpriseModelSG>& models,
00187                            const Image<float>& weights);
00188 
00189   //! Initialize us as a weighted combination of the given map of models
00190   virtual void combineFrom(const Image<SurpriseModelSG>& models,
00191                            const Image<float>& weights,
00192                            const Point2D<int>& pos,
00193                            const int width, const int height, const int offset);
00194 
00195   //! get our mean
00196   virtual double getMean() const;
00197 
00198   //! get our variance
00199   virtual double getVar() const;
00200 
00201   //! get our UpdateFac
00202   virtual double getUpdateFac() const;
00203 
00204 protected:
00205   int itsN;        //!< our sample N
00206   double itsMean;  //!< our current Gaussian mean
00207   double itsVar;   //!< our current Gaussian variance
00208 };
00209 
00210 // ######################################################################
00211 //! A single-Poisson/Gamma SurpriseModel
00212 /*! This is a very simple SurpriseModel consisting of a single Gamma
00213   prior over Poisson, which is updated in a sliding-average manner. */
00214 class SurpriseModelSP : public SurpriseModel
00215 {
00216 public:
00217   //! Constructor. See base class for details.
00218   SurpriseModelSP(const double updatefac = 0.5, const double sampleval = 0.0,
00219                   const double samplevar = 1.0 /* ignored */);
00220 
00221   //! Virtual destructor ensures proper destruction of derived classes
00222   virtual ~SurpriseModelSP();
00223 
00224   //! Reset to initial state
00225   virtual void reset();
00226 
00227   //! Change intial state parameters
00228   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00229                     const double samplevar = 1.0 /* ignored */);
00230 
00231   //! Load given sample mean and variance
00232   virtual void load(const double sampleval, const double samplevar = 1.0);
00233 
00234   //! Compute surprise between us and another model
00235   virtual double surprise(const SurpriseModelSP& other);
00236 
00237   //! Is empty in this model
00238   virtual void preComputeHyperParams(const SurpriseModelSP& sample);
00239 
00240   //! Initialize us as a weighted combination of the given map of models
00241   virtual void combineFrom(const Image<SurpriseModelSP>& models,
00242                            const Image<float>& weights);
00243 
00244   //! Initialize us as a weighted combination of the given map of models
00245   virtual void combineFrom(const Image<SurpriseModelSP>& models,
00246                            const Image<float>& weights,
00247                            const Point2D<int>& pos,
00248                            const int width, const int height, const int offset);
00249 
00250   //! get our mean
00251   virtual double getMean() const;
00252 
00253   //! get our variance
00254   virtual double getVar() const;
00255 
00256   //! get our UpdateFac
00257   virtual double getUpdateFac() const;
00258 
00259   //! get our alpha
00260   double getAlpha() const;
00261 
00262   //! get out beta
00263   double getBeta() const;
00264 
00265   //! Pre set model alpha values
00266   void preSetAlpha();
00267 
00268 protected:
00269   int itsN;             //!< our sample N
00270   double itsAlpha;      //!< our current Gamma alpha
00271   double itsBeta;       //!< our current Gamma beta
00272 
00273 };
00274 // ######################################################################
00275 //! A single-Poisson/Gamma SurpriseModel
00276 /*! This is a very simple SurpriseModel consisting of a single Gamma
00277   prior over Poisson, which is updated in a sliding-average manner.
00278 
00279   In this implementation surprise is calculated before the alpha and
00280   beta parameters decay so that there is no baseline surprise when the
00281   prior and posterior are the same.*/
00282 
00283 class SurpriseModelSP1 : public SurpriseModel
00284 {
00285 public:
00286   //! Constructor. See base class for details.
00287   SurpriseModelSP1(const double updatefac = 0.5, const double sampleval = 0.0,
00288                    const double samplevar = 1.0 /* ignored */);
00289 
00290   //! Virtual destructor ensures proper destruction of derived classes
00291   virtual ~SurpriseModelSP1();
00292 
00293   //! Reset to initial state
00294   virtual void reset();
00295 
00296   //! Change intial state parameters
00297   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00298                     const double samplevar = 1.0 /* ignored */);
00299 
00300   //! Load given sample mean and variance
00301   virtual void load(const double sampleval, const double samplevar = 1.0);
00302 
00303   //! Compute surprise between us and another model
00304   virtual double surprise(const SurpriseModelSP1& other);
00305 
00306   //! Is empty in this model
00307   virtual void preComputeHyperParams(const SurpriseModelSP1& sample);
00308 
00309   //! Initialize us as a weighted combination of the given map of models
00310   virtual void combineFrom(const Image<SurpriseModelSP1>& models,
00311                            const Image<float>& weights);
00312 
00313   //! Initialize us as a weighted combination of the given map of models
00314   virtual void combineFrom(const Image<SurpriseModelSP1>& models,
00315                            const Image<float>& weights,
00316                            const Point2D<int>& pos,
00317                            const int width, const int height, const int offset);
00318 
00319   //! get our mean
00320   virtual double getMean() const;
00321 
00322   //! get our variance
00323   virtual double getVar() const;
00324 
00325   //! get our UpdateFac
00326   virtual double getUpdateFac() const;
00327 
00328   //! get our alpha
00329   double getAlpha() const;
00330 
00331   //! get out beta
00332   double getBeta() const;
00333 
00334   //! Pre set model alpha values
00335   void preSetAlpha();
00336 
00337 protected:
00338   int itsN;             //!< our sample N
00339   double itsAlpha;      //!< our current Gamma alpha
00340   double itsBeta;       //!< our current Gamma beta
00341 
00342 };
00343 
00344 
00345 // ######################################################################
00346 //! A single-Poisson/Gamma SurpriseModel
00347 /*! This is a very simple SurpriseModel consisting of a single Gamma
00348   prior over Poisson, which is updated in a sliding-average manner.
00349 
00350   This variant fixes the beta term which is useful for multi frame inputs
00351 
00352 */
00353 class SurpriseModelSPC : public SurpriseModel
00354 {
00355 public:
00356   //! Constructor. See base class for details.
00357   SurpriseModelSPC(const double updatefac = 0.5, const double sampleval = 0.0,
00358                    const double samplevar = 1.0 /* ignored */);
00359 
00360   //! Virtual destructor ensures proper destruction of derived classes
00361   virtual ~SurpriseModelSPC();
00362 
00363   //! Reset to initial state
00364   virtual void reset();
00365 
00366   //! Change intial state parameters
00367   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00368                     const double samplevar = 1.0 /* ignored */);
00369 
00370   //! Load given sample mean and variance
00371   virtual void load(const double sampleval, const double samplevar = 1.0);
00372 
00373   //! Compute surprise between us and another model
00374   virtual double surprise(const SurpriseModelSPC& other);
00375 
00376   //! Is empty in this model
00377   virtual void preComputeHyperParams(const SurpriseModelSPC& sample);
00378 
00379   //! Initialize us as a weighted combination of the given map of models
00380   virtual void combineFrom(const Image<SurpriseModelSPC>& models,
00381                            const Image<float>& weights);
00382 
00383   //! Initialize us as a weighted combination of the given map of models
00384   virtual void combineFrom(const Image<SurpriseModelSPC>& models,
00385                            const Image<float>& weights,
00386                            const Point2D<int>& pos,
00387                            const int width, const int height, const int offset);
00388 
00389   //! get our mean
00390   virtual double getMean() const;
00391 
00392   //! get our variance
00393   virtual double getVar() const;
00394 
00395   //! get our UpdateFac
00396   virtual double getUpdateFac() const;
00397 
00398   //! get our alpha
00399   double getAlpha() const;
00400 
00401   //! get out beta
00402   double getBeta() const;
00403 
00404   //! Pre set model alpha values
00405   void preSetAlpha();
00406 
00407 protected:
00408   int    itsN;          //!< our sample N
00409   double itsAlpha;      //!< our current Gamma alpha
00410   double itsBeta;
00411 };
00412 
00413 // ######################################################################
00414 //! A single-Poisson/Gamma SurpriseModel
00415 /*! This is a very simple SurpriseModel consisting of a single Gamma
00416   prior over Poisson, which is updated in a sliding-average manner.
00417 
00418   This variant floats the beta term which may be useful for multi frame inputs
00419 
00420   <<Experimental>>
00421 
00422 */
00423 class SurpriseModelSPF : public SurpriseModel
00424 {
00425 public:
00426   //! Constructor. See base class for details.
00427   SurpriseModelSPF(const double updatefac = 0.5, const double sampleval = 0.0,
00428                    const double samplevar = 1.0 /* ignored */);
00429 
00430   //! Virtual destructor ensures proper destruction of derived classes
00431   virtual ~SurpriseModelSPF();
00432 
00433   //! Reset to initial state
00434   virtual void reset();
00435 
00436   //! Change intial state parameters
00437   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00438                     const double samplevar = 1.0 /* ignored */);
00439 
00440   //! Load given sample mean and variance
00441   virtual void load(const double sampleval, const double samplevar = 1.0);
00442 
00443   //! Compute surprise between us and another model
00444   virtual double surprise(const SurpriseModelSPF& other);
00445 
00446   //! Is empty in this model
00447   virtual void preComputeHyperParams(const SurpriseModelSPF& sample);
00448 
00449   //! Initialize us as a weighted combination of the given map of models
00450   virtual void combineFrom(const Image<SurpriseModelSPF>& models,
00451                            const Image<float>& weights);
00452 
00453   //! Initialize us as a weighted combination of the given map of models
00454   virtual void combineFrom(const Image<SurpriseModelSPF>& models,
00455                            const Image<float>& weights,
00456                            const Point2D<int>& pos,
00457                            const int width, const int height, const int offset);
00458 
00459   //! get our mean
00460   virtual double getMean() const;
00461 
00462   //! get our variance
00463   virtual double getVar() const;
00464 
00465   //! get our UpdateFac
00466   virtual double getUpdateFac() const;
00467 
00468   //! get our alpha
00469   double getAlpha() const;
00470 
00471   //! get out beta
00472   double getBeta() const;
00473 
00474   //! Pre set model alpha values
00475   void preSetAlpha();
00476 
00477 protected:
00478   int    itsN;          //!< our sample N
00479   double itsAlpha;      //!< our current Gamma alpha
00480   double itsBeta;
00481   double itsLastS;
00482   double itsSFac;
00483 };
00484 
00485 // ######################################################################
00486 //! A Chi-Square SurpriseModel
00487 /*! This is a very simple SurpriseModel consisting of a single Gamma
00488   prior over Poisson, which is updated in a sliding-average manner.
00489   Beta is fixed as 1/2 so this is a special case where the Gamma is
00490   the Chi Square distribution.
00491 */
00492 class SurpriseModelCS : public SurpriseModel
00493 {
00494 public:
00495   //! Constructor. See base class for details.
00496   SurpriseModelCS(const double updatefac = 0.5, const double sampleval = 0.0,
00497                   const double samplevar = 1.0 /* ignored */);
00498 
00499   //! Virtual destructor ensures proper destruction of derived classes
00500   virtual ~SurpriseModelCS();
00501 
00502   //! Reset to initial state
00503   virtual void reset();
00504 
00505   //! Change intial state parameters
00506   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00507                     const double samplevar = 1.0 /* ignored */);
00508 
00509   //! Load given sample mean and variance
00510   virtual void load(const double sampleval, const double samplevar = 1.0);
00511 
00512   //! Compute surprise between us and another model
00513   virtual double surprise(const SurpriseModelCS& other);
00514 
00515   //! Is empty in this model
00516   virtual void preComputeHyperParams(const SurpriseModelCS& sample);
00517 
00518   //! Initialize us as a weighted combination of the given map of models
00519   virtual void combineFrom(const Image<SurpriseModelCS>& models,
00520                            const Image<float>& weights);
00521 
00522   //! Initialize us as a weighted combination of the given map of models
00523   virtual void combineFrom(const Image<SurpriseModelCS>& models,
00524                            const Image<float>& weights,
00525                            const Point2D<int>& pos,
00526                            const int width, const int height, const int offset);
00527 
00528   //! get our mean
00529   virtual double getMean() const;
00530 
00531   //! get our variance
00532   virtual double getVar() const;
00533 
00534   //! get our UpdateFac
00535   virtual double getUpdateFac() const;
00536 
00537   //! get our alpha
00538   double getAlpha() const;
00539 
00540   //! get out beta
00541   double getBeta() const;
00542 
00543   //! Pre set model alpha values
00544   void preSetAlpha();
00545 
00546 protected:
00547   int itsN;             //!< our sample N
00548   double itsAlpha;      //!< our current Gamma alpha
00549   double itsBeta;       //!< our current Gamma beta
00550 
00551 };
00552 
00553 // ######################################################################
00554 //! A joint Gamma/Gaussian SurpriseModel
00555 /*! This is a very simple SurpriseModel consisting of a single Gamma
00556   prior over Poisson (time), which is updated in a sliding-average manner.
00557   space is updated as a gaussian and the two are combined as a joint
00558   KL to compute surprise*/
00559 class SurpriseModelGG : public SurpriseModel
00560 {
00561 public:
00562   //! Constructor. See base class for details.
00563   SurpriseModelGG(const double updatefac = 0.5, const double sampleval = 0.0,
00564                   const double samplevar = 1.0 /* ignored */);
00565 
00566   //! Virtual destructor ensures proper destruction of derived classes
00567   virtual ~SurpriseModelGG();
00568 
00569   //! Reset to initial state
00570   virtual void reset();
00571 
00572   //! Change intial state parameters
00573   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00574                     const double samplevar = 1.0 /* ignored */);
00575 
00576   //! Load given sample mean and variance
00577   virtual void load(const double sampleval, const double samplevar = 1.0);
00578 
00579   //! Compute surprise between us and another model
00580   virtual double surprise(const SurpriseModelGG& other);
00581 
00582   //! Is empty in this model
00583   virtual void preComputeHyperParams(const SurpriseModelGG& sample);
00584 
00585   //! Initialize us as a weighted combination of the given map of models
00586   virtual void combineFrom(const Image<SurpriseModelGG>& models,
00587                            const Image<float>& weights);
00588 
00589   //! Initialize us as a weighted combination of the given map of models
00590   virtual void combineFrom(const Image<SurpriseModelGG>& models,
00591                            const Image<float>& weights,
00592                            const Point2D<int>& pos,
00593                            const int width, const int height, const int offset);
00594 
00595   //! get our mean
00596   virtual double getMean() const;
00597 
00598   //! get our variance
00599   virtual double getVar() const;
00600 
00601   //! get our UpdateFac
00602   virtual double getUpdateFac() const;
00603 
00604   //! Set up biases if needed for KL
00605   virtual void setBias(const double slfac,
00606                        const double ssfac,
00607                        const SU_KL_BIAS klbias);
00608 
00609   //! get our alpha
00610   double getAlpha() const;
00611 
00612   //! get out beta
00613   double getBeta() const;
00614 
00615 protected:
00616   bool itsCombineFromRun; //!< Make sure we run combineFrom each iter
00617   int itsN;               //!< our sample N
00618   SU_KL_BIAS itsJointKLBiasType; //!< enum for kl bias type
00619   double itsAlpha;        //!< our current Gamma alpha    (time)
00620   double itsBeta;         //!< our current Gamma beta     (time)
00621   double itsMean;         //!< our current Gauss mean     (space)
00622   double itsVar;          //!< our current Gauss variance (space)
00623   double itsSig;          //!< our current sigma          (space)
00624   double itsSum;          //!< Holds the sum from combineFrom
00625   double itsSS;           //!< Holds the sum of squares from combineFrom
00626   double itsWeightSum;    //!< Holds the weight sum from combineFrom
00627   double itsSLfac;        //!< Temporal bias to apply if needed
00628   double itsSSfac;        //!< Spatial bias to apply if needed
00629 
00630 };
00631 
00632 // ######################################################################
00633 //! A single-Poisson/Gamma SurpriseModel with inertia
00634 /*! This is a very simple SurpriseModel consisting of a single Gamma
00635   prior over Poisson, which is updated in a sliding-average manner. */
00636 class SurpriseModelPM : public SurpriseModel
00637 {
00638 public:
00639   //! Constructor. See base class for details.
00640   SurpriseModelPM(const double updatefac = 0.5, const double sampleval = 0.0,
00641                   const double samplevar = 1.0 /* ignored */);
00642 
00643   //! Virtual destructor ensures proper destruction of derived classes
00644   virtual ~SurpriseModelPM();
00645 
00646   //! Reset to initial state
00647   virtual void reset();
00648 
00649   //! Change intial state parameters
00650   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00651                     const double samplevar = 1.0 /* ignored */);
00652 
00653   //! Load given sample mean and variance
00654   virtual void load(const double sampleval, const double samplevar = 1.0);
00655 
00656   //! Compute surprise between us and another model
00657   virtual double surprise(const SurpriseModelPM& other);
00658 
00659   //! pre compute alpha and beta terms before calling combine from
00660   virtual void preComputeHyperParams(const SurpriseModelPM& sample);
00661 
00662   //! Initialize us as a weighted combination of the given map of models
00663   virtual void combineFrom(const Image<SurpriseModelPM>& models,
00664                            const Image<float>& weights);
00665 
00666   //! Initialize us as a weighted combination of the given map of models
00667   virtual void combineFrom(const Image<SurpriseModelPM>& models,
00668                            const Image<float>& weights,
00669                            const Point2D<int>& pos,
00670                            const int width, const int height, const int offset);
00671 
00672   //! get our mean
00673   virtual double getMean() const;
00674 
00675   //! get our variance
00676   virtual double getVar() const;
00677 
00678   //! get our UpdateFac
00679   virtual double getUpdateFac() const;
00680 
00681 protected:
00682   int    itsN;           //!< our sample N
00683 
00684   double itsSample;
00685   double itsAlpha0;      //!< our current Gamma alpha
00686   double itsAlpha1;      //!< our current Gamma alpha
00687   double itsAlpha2;      //!< our current Gamma alpha
00688   double itsBeta0;       //!< our current Gamma beta
00689   double itsBeta1;       //!< our current Gamma beta
00690   double itsBeta2;       //!< our current Gamma beta
00691   double itsInitBeta;    //!< Initial Value of beta
00692   double itsExpectAlpha1;//!< The expected value of alpha1
00693   double itsExpectAlpha2;//!< The expected value of alpha2
00694   double itsXBar1;       //!< The estimated value of alpha1
00695   double itsXBar2;       //!< The estimated value of alpha2
00696   double itsLgamma1;     //!< Computing lgamma is expensive, so we keep it
00697   double itsLgamma2;     //!< Computing lgamma is expensive, so we keep it
00698 };
00699 
00700 // ######################################################################
00701 //! A single-Poisson Outlier-based model
00702 /*! This is not really a true SurpriseModel, but rather an information
00703   model based on outlier detection using a single adaptive Poisson
00704   model. */
00705 class SurpriseModelOD : public SurpriseModel
00706 {
00707 public:
00708   //! Constructor. See base class for details.
00709   SurpriseModelOD(const double updatefac = 0.5, const double sampleval = 0.0,
00710                   const double samplevar = 1.0 /* ignored */);
00711 
00712   //! Virtual destructor ensures proper destruction of derived classes
00713   virtual ~SurpriseModelOD();
00714 
00715   //! Reset to initial state
00716   virtual void reset();
00717 
00718   //! Change intial state parameters
00719   virtual void init(const double updatefac = 0.5, const double sampleval = 0.0,
00720                     const double samplevar = 1.0 /* ignored */);
00721 
00722   //! Load given sample mean and variance
00723   virtual void load(const double sampleval, const double samplevar = 1.0);
00724 
00725   //! Compute surprise between us and another model
00726   virtual double surprise(const SurpriseModelOD& other);
00727 
00728   //! Is empty in this model
00729   virtual void preComputeHyperParams(const SurpriseModelOD& sample);
00730 
00731   //! Initialize us as a weighted combination of the given map of models
00732   virtual void combineFrom(const Image<SurpriseModelOD>& models,
00733                            const Image<float>& weights);
00734 
00735   //! Initialize us as a weighted combination of the given map of models
00736   virtual void combineFrom(const Image<SurpriseModelOD>& models,
00737                            const Image<float>& weights,
00738                            const Point2D<int>& pos,
00739                            const int width, const int height, const int offset);
00740 
00741   //! get our mean
00742   virtual double getMean() const;
00743 
00744   //! get our variance
00745   virtual double getVar() const;
00746 
00747   //! get our UpdateFac
00748   virtual double getUpdateFac() const;
00749 
00750 protected:
00751   int itsN;          //!< our sample N
00752   double itsLambda;  //!< our current Poisson lambda
00753 };
00754 
00755 #endif
00756 
00757 // ######################################################################
00758 /* So things look consistent in everyone's emacs... */
00759 /* Local Variables: */
00760 /* indent-tabs-mode: nil */
00761 /* End: */
Generated on Sun May 8 08:06:54 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3