00001 /*!@file Learn/LogLikelikhoodClassifier.H Log Likelihood Classifier for Histograms module */ 00002 // //////////////////////////////////////////////////////////////////// // 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 // //////////////////////////////////////////////////////////////////// // 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 // //////////////////////////////////////////////////////////////////// // 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 00030 // //////////////////////////////////////////////////////////////////// // 00031 // 00032 // Primary maintainer for this file: Dan Parks <danielfp@usc.edu> 00033 // $HeadURL$ 00034 // $Id$ 00035 // 00036 00037 #ifndef LOGLIKELIHOODCLASSIFIER_H_DEFINED 00038 #define LOGLIKELIHOODCLASSIFIER_H_DEFINED 00039 00040 #include <cstdlib> 00041 #include <deque> 00042 #include <map> 00043 00044 00045 00046 class LogLikelihoodClassifier 00047 { 00048 00049 public: 00050 LogLikelihoodClassifier(int k=5); 00051 00052 // Map of model histograms (multiple per model id) 00053 typedef std::map<int, std::vector<std::vector<float> > > MapModelVector; 00054 00055 //! Calculate log likelihood probability for this sample and model 00056 float calcLogLikelihood(const std::vector<float>& sample, const std::vector<float>& model); 00057 00058 //! Add a model exemplar for this id (ok to have multiple exemplars per class) 00059 void addModel(std::vector<float> hist, int id); 00060 00061 //! Set the models that will be used for this classifier 00062 void setModels(MapModelVector models); 00063 00064 //! Return the models that were used for this classifier 00065 MapModelVector getModels(); 00066 00067 //! Predict using classifier 00068 int predict(const std::vector<float>& hist); 00069 00070 //! Predict using classifier and return the full PDF across classes 00071 std::map<int,double> predictPDF(const std::vector<float>& hist); 00072 00073 //! Perform k-nearest neighbor vote that does a short circuited calculation using the best likelihoods to calculate the full PDF 00074 void nearestNeighborVotePDF(const std::map<int,std::list<float> >& logLikelihood, std::map<int,double>& pdf); 00075 00076 //! Get number of models 00077 uint getNumModels(); 00078 00079 protected: 00080 //! Store a list of model histograms for each model id 00081 MapModelVector itsModels; 00082 uint itsHistLength; 00083 uint itsK; 00084 }; 00085 00086 #endif 00087 00088 // ###################################################################### 00089 /* So things look consistent in everyone's emacs... */ 00090 /* Local Variables: */ 00091 /* indent-tabs-mode: nil */ 00092 /* End: */ 00093