00001 /*!@file VFAT/covEstimate.H quick estimator for coveriance matrix 00002 */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/covEstimate.H $ 00036 // $Id: covEstimate.H 6003 2005-11-29 17:22:45Z rjpeters $ 00037 // 00038 // ############################################################ 00039 // ############################################################ 00040 // ##### --- VFAT --- 00041 // ##### Vision Feature Analysis Tool: 00042 // ##### T. Nathan Mundhenk nathan@mundhenk.com 00043 // ##### Laurent Itt itti@pollux.usc.edu 00044 // ##### 00045 // ############################################################ 00046 // ############################################################ 00047 00048 #ifndef COVESTIMATE_H_DEFINED 00049 #define COVESTIMATE_H_DEFINED 00050 00051 #include <vector> 00052 #include "Image/Pixels.H" 00053 #include "Image/Point2D.H" 00054 #include "Image/All.H" 00055 #include "VFAT/covHolder.H" 00056 00057 //! This method attmepts to estimate eignen values and vectors 00058 /*! The basic idea behind this class is to estimate a gaussian envolope 00059 around some given data but do so by avoiding matrix inversion and 00060 multiplicaition. Instead, we estimate values and gain an order of 00061 complexity in speed. 00062 */ 00063 00064 template <class T> class covEstimate 00065 { 00066 private: 00067 //! Pointer to raw data matrix in vector form 00068 std::vector<std::vector<T> > *cov_inputSpace; 00069 //! Pointer to map of raw data matrix in vector form 00070 std::vector<std::vector<T*> > *cov_inputSpacePtr; 00071 //! Pointer to map of raw data matrix in vector form, float cast form 00072 std::vector<std::vector<float*> > *cov_FinputSpacePtr; 00073 //! work matrix to rotate and translate 00074 std::vector<std::vector<T> > cov_transSpace; 00075 //! temporary rotation space 00076 std::vector<std::vector<T> > cov_rotSpace; 00077 //! container for mean translated during computation of P 00078 std::vector<T> cov_meanTranslate; 00079 //! container for mean Rotated during computation of P 00080 std::vector<T> cov_meanRot; 00081 //! sum of squares for independant data set after rotation/translation 00082 std::vector<T> cov_sumSquare; 00083 //! list of rotations from forward rotation, used to reverse rotate stdSpace 00084 std::vector<int> cov_list_i; 00085 //! list of rotations from forward rotation, used to reverse rotate stdSpace 00086 std::vector<int> cov_list_j; 00087 //! size of cov_list for reverse rotations 00088 int cov_listSize; 00089 //! size of input space, obtained from cov_inputSpace 00090 //unsigned int cov_iSpaceSize; 00091 //! size of transformation space, obtained from cov_transSpace 00092 //unsigned int cov_tSpaceSize; 00093 //! dimension of this space 00094 unsigned long cov_dim; 00095 //! samples in this space 00096 unsigned long cov_samples; 00097 //! tracks current status of algorithm 00098 float cov_currentStep; 00099 //! tells if we are working from a vector or a vector map (pointers) 00100 bool cov_usePtr; 00101 //! use special pointer for float entry when T = double 00102 bool cov_useFloatSpecial; 00103 //! tell if we are going to use the more simple method with dual interactions 00104 bool cov_doSimple; 00105 //! temp vector 00106 std::vector<T> cov_tempTS; 00107 //! (1) find mean value (centroid) in matrix 00108 void findMean(); 00109 //! (1a) OPTIONAL find the min and max values 00110 void findMinMax(); 00111 //! (2) translate space to new coordinates 00112 void translateSpace(); 00113 //! (3) find covarience reducing rotations and rotate space 00114 void findRotatios(bool doSimple); 00115 //! (4) find variance of matrix using assumption of independance 00116 void findVariance(); 00117 //! this is a pointer to the covHolder input 00118 covHolder<T> *cov_covHolder; 00119 public: 00120 //! Default constructor, call and input pointer to first matrix 00121 covEstimate(std::vector<std::vector<T> > &_inputSpace,covHolder<T> &_ch); 00122 //! for backward compatibility 00123 covEstimate(std::vector<std::vector<T*> > &_inputSpace,covHolder<T> &_ch); 00124 //! Default constructor, call and input pointer to first matrix 00125 covEstimate(); 00126 //! Default destructor, call and input pointer to first matrix 00127 ~covEstimate(); 00128 //! given the stored covarienc matrix what is the prob. of some point P 00129 /*! @param sample This a new sample point in the same space as cov matrix 00130 @param stop How early to stop from end of list in diminsions 00131 */ 00132 T getP(std::vector<T> sample, covHolder<T> &_ch, int stop); 00133 //! obtain the distance between this point and the mean found in covEstimate 00134 /*! @param sample This a new sample point in the same space as cov matrix 00135 */ 00136 T getD(std::vector<T> sample, covHolder<T> &_ch, int stop); 00137 //! obtain the inverse distance between this point and the other 00138 T getD(std::vector<T> *point1,std::vector<T> *point2, 00139 std::vector<T> *biasSet, bool useGuass); 00140 //! match clusters from mean values 00141 /*! This will take in a set of mean values about each cluster and 00142 match clusters from one set to clusters in another set based upon 00143 mean values. 00144 @param ch1 this is a list of covHolders for set 1 00145 @param size1 this is the size of the first list 00146 @param ch2 this is a list of covHolders for set 2 00147 @param size2 this is the size of the second list 00148 */ 00149 void matchPmean(std::vector<covHolder<T> > *chNew, long sizeNew, 00150 std::vector<covHolder<T> > *chOld, long sizeOld, 00151 long minSize); 00152 //! match clusters from mean values 00153 /*! This will take in a set of mean values about each cluster and 00154 match clusters from one set to clusters in another set based upon 00155 mean values. This one accumulates Classes. 00156 @param ch1 this is a list of covHolders for set 1 00157 @param size1 this is the size of the first list 00158 @param ch2 this is a list of covHolders for set 2 00159 @param size2 this is the size of the second list 00160 */ 00161 void matchPmeanAccum(std::vector<covHolder<T> > *ch, unsigned int *sizeCH, 00162 std::vector<covHolder<T> > *accum, unsigned int *sizeAccum, 00163 long minSize); 00164 //! find the gaussian P for some data 00165 T gauss(T X, T mu, T std); 00166 //! run covestimator with input data 00167 void run(); 00168 //! (1a) call to insert new matrix, force (clear) resize if nessesary 00169 void setNew(std::vector<std::vector<T> > &_inputSpace, 00170 bool doResize, covHolder<T> &_ch, T initVal); 00171 //! (1a) call to insert new matrix, force (clear) resize if nessesary 00172 void setNew(std::vector<std::vector<T*> > &_inputSpace, 00173 bool doResize, covHolder<T> &_ch, T initVal); 00174 //! (1a) call to insert new matrix, force (clear) resize if nessesary 00175 void setNew(std::vector<std::vector<T> > &_inputSpace, 00176 T initVal, int samples, int dim, covHolder<T> &_ch, 00177 bool _resize); 00178 //! (1a) call to insert new matrix, force (clear) resize if nessesary 00179 void setNew(std::vector<std::vector<T*> > &_inputSpace, 00180 T initVal, int samples, int dim, covHolder<T> &_ch, 00181 bool _resize); 00182 //! set new, but lets us set a float when T = double etc. 00183 void setNewF(std::vector<std::vector<float*> > &_inputSpace, 00184 T initVal, int samples, int dim, covHolder<T> &_ch, 00185 bool _resize); 00186 //! (aux) resize and clear all matrices 00187 /*! this should not be called directly, but may if you wish 00188 @param dimensions This is the dimension of the input matrix 00189 @param samples This is the number of samples taken 00190 @param zero This is what value you would like to set all elements to 00191 */ 00192 void resize(unsigned int _dimensions, unsigned int _samples, T zero); 00193 //! (aux) print debugging data 00194 void printDebug(); 00195 //! (aux) this will return an image slice of the matrix in its current form 00196 /*! This takes a 2D snapshot of the space along the two dimensions provided 00197 @param spaceSize, this is the "size" of the image to be returned as a square of size X x X 00198 00199 */ 00200 void printEigenVals(); 00201 Image<float> returnMatrixSlice(int dim1, int dim2, int spaceSize); 00202 //! (aux) this shows how the covarience matrix fits over the data 00203 Image<float> returnCovSlice(int dim1, int dim2, int spaceSize, 00204 bool inorm = false); 00205 Image<float> returnCovSlice(int dim1, int dim2, Image<float> &img, 00206 bool inorm = false); 00207 00208 //! dump the covMatrix to files, this will append the output to these files 00209 void dumpMatrix(std::string fileName, int index, std::string ID); 00210 //! dump the covMatrix to files, this will append the output to these files 00211 void dumpMatrix(std::string fileName, covHolder<T> &_ch, int index, std::string ID); 00212 //! return the sample size 00213 unsigned long getSampleSize(); 00214 00215 }; 00216 #endif 00217 00218 00219