GentleBoost.H

Go to the documentation of this file.
00001 /*!@file Learn/GentleBoost.H GentleBoost Multi-Class Classifier */
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 GENTLEBOOST_H_DEFINED
00038 #define GENTLEBOOST_H_DEFINED
00039 
00040 #include "Learn/DecisionTree.H"
00041 #include "GentleBoostBinary.H"
00042 #include "Util/Assert.H"
00043 #include "Util/log.H"
00044 #include "Util/SortUtil.H"
00045 #include <limits>
00046 #include <math.h>
00047 #include <stdio.h>
00048 #include <map>
00049 #include <iostream>
00050 #include <fstream>
00051 
00052 // The data is assumed to be in data[N][M] dimensions where N is the # of dimensions, and M is the # of samples
00053 
00054 //! Multi-Class Gentle-AdaBoost using a One vs All, MAX wins voting scheme
00055 class GentleBoost
00056 {
00057 public:
00058   GentleBoost(int maxTreeSize=1);
00059   // Multi Class Boost
00060   //! Get PDF map of each class, with a vector of each observation
00061   std::map<int,std::vector<float> > predictPDF(const std::vector<std::vector<float> >& data);
00062   //! Get the most likely class for a particular index in a set of observations
00063   int getMostLikelyClass(const std::map<int,std::vector<float> >& pdf, int index);
00064   //! Get the most likely class for a set of observations
00065   std::vector<int> getMostLikelyClass(const std::map<int,std::vector<float> >& pdf);
00066   //! Get most likely class per observation
00067   std::vector<int> predict(const std::vector<std::vector<float> >& data);
00068   //! Train a set of binary (1vsAll) GentleBoost classifiers on the given data
00069   void train(const std::vector<std::vector<float> >& data, const std::vector<int>& labels, int maxIters);
00070   //! Convert class id labels to binary per class labels
00071   std::map<int,std::vector<int> > convertLabels(const std::vector<int>& labels);
00072   //! Remove all training
00073   void clear();
00074   //! Convenience function to transpose the data dimensions, since the ordering is unusual
00075   std::vector<std::vector<float> > transpose(const std::vector<std::vector<float> >& data);
00076   //! Convenience function to print the underlying decision trees for each 1vsAll Classifier
00077   void printAllTrees();
00078   //! Create a string representation of the heirarchy
00079   void writeAllTrees(std::ostream& outstream);
00080   //! Read a string representation of the heirarchy and build the class
00081   void readAllTrees(std::istream& instream);
00082   //! Load a BOOSTed system from a file
00083   void load(std::string file);
00084   //! Save a BOOSTed system to a file
00085   void save(std::string file);
00086 
00087 private:
00088   // Limit the size of the underlying trees (number of splits)
00089   int itsMaxTreeSize;
00090   std::map<int,GentleBoostBinary> itsLearners;
00091 };
00092 
00093 
00094 
00095 #endif // GENTLEBOOST_H_DEFINED
Generated on Sun May 8 08:40:58 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3