POMDP.H

Go to the documentation of this file.
00001 /*!@file SceneUnderstanding/POMDP.H  partially observable Markov decision processes */
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/plugins/SceneUnderstanding/POMDP.H $
00035 // $Id: POMDP.H 13551 2010-06-10 21:56:32Z itti $
00036 //
00037 
00038 #ifndef POMDP_H_DEFINED
00039 #define POMDP_H_DEFINED
00040 
00041 #include "Image/OpenCVUtil.H"  // must be first to avoid conflicting defs of int64, uint64
00042 
00043 #include "Image/Image.H" // for uint
00044 #include "Image/ImageSet.H" // for uint
00045 #include "Image/Pixels.H" // for uint
00046 #include <vector>
00047 #include <string>
00048 #include <map>
00049 
00050 class POMDP
00051 {
00052 public:
00053 
00054   struct StateAction
00055   {
00056     int state;
00057     int action;
00058   };
00059 
00060   struct State
00061   {
00062     int x;
00063     int y;
00064     int stateID;
00065     float prob;
00066 
00067     State(int in_x, int in_y) :
00068       x(in_x), y(in_y)
00069     {
00070     }
00071   };
00072 
00073   enum OBJS {BACKGROUND, GOAL, AGENT, WALL, HOLE};
00074   enum ACTIONS {NORTH, SOUTH, EAST, WEST};
00075   POMDP();
00076 
00077   //! Destructor
00078   ~POMDP();
00079 
00080   //! which action to perform
00081   int getAction();
00082 
00083   //! make an observation, return if we have anything new
00084   bool makeObservation(const Image<PixRGB<byte> > &img);
00085 
00086   void init();
00087 
00088 
00089   //Observations
00090   Image<float> locateObject(const Image<float>& src, Image<float>& filter);
00091   Point2D<int> findObject(const Image<PixRGB<byte> > &img, const char* filename);
00092   std::vector<Point2D<int> > findMultipleObjects(const Image<PixRGB<byte> > &img, const char* filename);
00093 
00094   Point2D<int> getAgentState();
00095   Point2D<int> getGoalState();
00096 
00097   Image<byte> getStateSpace();
00098   void showTransitions();
00099   float getTransProb(int state, int action, int newState);  // p(s'|s,u)
00100 
00101   int doAction(const int state, const int act);
00102   float getReward(int state);
00103   void valueIteration();
00104   ACTIONS getAction(int state);
00105 
00106   //Get the proposed action
00107   int getPropAction();
00108 
00109   void doPolicy(const Point2D<int> &startPos);
00110 
00111   Image<float> getPerception(const uint obj);
00112   Image<float> makePrediction(const ACTIONS action);
00113   float updatePerception(const Image<PixRGB<byte> > &img);
00114   void updateStateTransitions(const ACTIONS action);
00115   bool goalReached();
00116   bool isExploring() { return itsExploring;}
00117 
00118   float bayesFilter(const int action, const Image<PixRGB<byte> > &img);
00119   float particleFilter(const int action, const Image<PixRGB<byte> > &img);
00120 
00121   float getEntropy(Image<float> &belif);
00122 
00123   //! The model of the object
00124   float getObjProb(const Image<PixRGB<byte> > &img,
00125       const State state, const int objID);
00126 
00127 
00128 
00129 
00130 private:
00131     Dims itsRetinaSize;
00132     Point2D<int> itsAgentState;
00133     Point2D<int> itsGoalState;
00134 
00135     float itsLastDistance;
00136     int itsLastAction;
00137     Image<byte> itsStateSpace;
00138     ImageSet<float> itsCurrentPercep;
00139     Image<float> itsPreviousPercep;
00140     Image<float> itsPrediction;
00141     std::vector<std::vector<std::vector<float> > > itsTransitions;
00142     Image<float> itsUtility;
00143     std::map<StateAction, int> itsStateTrans;
00144     bool itsExploring;
00145     std::vector<Image<PixRGB<byte> > > itsObjects;
00146 
00147     std::vector<State> itsParticleStateSpace;
00148 };
00149 
00150 // ######################################################################
00151 /* So things look consistent in everyone's emacs... */
00152 /* Local Variables: */
00153 /* indent-tabs-mode: nil */
00154 /* End: */
00155 
00156 #endif
Generated on Sun May 8 08:41:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3