latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiMultivariateGaussian.h 00027 * authors ....: Jens Paustenbach 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 14.5.2002 00030 * revisions ..: $Id: ltiMultivariateGaussian.h,v 1.9 2007/01/10 02:26:20 alvarado Exp $ 00031 */ 00032 00033 #ifndef _LTI_MULTIVARIATE_GAUSSIAN_H_ 00034 #define _LTI_MULTIVARIATE_GAUSSIAN_H_ 00035 00036 00037 #include "ltiVector.h" 00038 #include "ltiMatrix.h" 00039 #include "ltiGaussDist.h" 00040 #include "ltiEigenSystem.h" 00041 #include "ltiMatrixDecomposition.h" 00042 #include "list" 00043 00044 namespace lti { 00045 /** 00046 * this class generates either one point from a given covarianceMatrix 00047 * and centre or it generates a given number of points according to 00048 * these parameters. 00049 * The points are drawn from a gaussian distribution 00050 * <p> The apply methods expect the %parameters directly, the %parameters 00051 * for the draw method must be set in the parameter class 00052 * <p> Only draw(const int& number) is implemented. 00053 * draw() is only reimplemented to make sure that the function of the 00054 * parent class isn't used. This function return always 0. 00055 * To draw only one point use draw(const int& number) with number=1 00056 */ 00057 class multivariateGaussian : public continuousRandomDistribution { 00058 public: 00059 /** 00060 * the parameters for the class multivariateGaussian 00061 */ 00062 class parameters : public continuousRandomDistribution::parameters { 00063 public: 00064 /** 00065 * default constructor 00066 */ 00067 parameters(); 00068 00069 /** 00070 * copy constructor 00071 * @param other the parameters object to be copied 00072 */ 00073 parameters(const parameters& other); 00074 00075 /** 00076 * destructor 00077 */ 00078 ~parameters(); 00079 00080 /** 00081 * returns name of this type 00082 */ 00083 const char* getTypeName() const; 00084 00085 /** 00086 * copy the contents of a parameters object 00087 * @param other the parameters object to be copied 00088 * @return a reference to this parameters object 00089 */ 00090 parameters& copy(const parameters& other); 00091 00092 /** 00093 * copy the contents of a parameters object 00094 * @param other the parameters object to be copied 00095 * @return a reference to this parameters object 00096 */ 00097 parameters& operator=(const parameters& other); 00098 00099 00100 /** 00101 * returns a pointer to a clone of the parameters 00102 */ 00103 virtual functor::parameters* clone() const; 00104 00105 /** 00106 * write the parameters in the given ioHandler 00107 * @param handler the ioHandler to be used 00108 * @param complete if true (the default) the enclosing begin/end will 00109 * be also written, otherwise only the data block will be written. 00110 * @return true if write was successful 00111 */ 00112 virtual bool write(ioHandler& handler,const bool complete=true) const; 00113 00114 /** 00115 * read the parameters from the given ioHandler 00116 * @param handler the ioHandler to be used 00117 * @param complete if true (the default) the enclosing begin/end will 00118 * be also written, otherwise only the data block will be written. 00119 * @return true if write was successful 00120 */ 00121 virtual bool read(ioHandler& handler,const bool complete=true); 00122 00123 # ifdef _LTI_MSC_6 00124 /** 00125 * this function is required by MSVC only, as a workaround for a 00126 * very awful bug, which exists since MSVC V.4.0, and still by 00127 * V.6.0 with all bugfixes (so called "service packs") remains 00128 * there... This method is also public due to another bug, so please 00129 * NEVER EVER call this method directly: use read() instead 00130 */ 00131 bool readMS(ioHandler& handler,const bool complete=true); 00132 00133 /** 00134 * this function is required by MSVC only, as a workaround for a 00135 * very awful bug, which exists since MSVC V.4.0, and still by 00136 * V.6.0 with all bugfixes (so called "service packs") remains 00137 * there... This method is also public due to another bug, so please 00138 * NEVER EVER call this method directly: use write() instead 00139 */ 00140 bool writeMS(ioHandler& handler,const bool complete=true) const; 00141 # endif 00142 00143 // ------------------------------------------------ 00144 // the parameters 00145 // ------------------------------------------------ 00146 00147 /** 00148 * the centre point of the distribution 00149 */ 00150 dvector centre; 00151 00152 /** 00153 * the covariance for the distribution 00154 */ 00155 dmatrix covarianceMatrix; 00156 00157 }; 00158 00159 /** 00160 * default constructor 00161 */ 00162 multivariateGaussian(); 00163 00164 /** 00165 * copy constructor 00166 * @param other the object to be copied 00167 */ 00168 multivariateGaussian(const multivariateGaussian& other); 00169 00170 /** 00171 * destructor 00172 */ 00173 virtual ~multivariateGaussian(); 00174 00175 /** 00176 * returns the name of this type ("multivariateGaussian") 00177 */ 00178 virtual const char* getTypeName() const; 00179 00180 00181 /** 00182 * computes one point from a gaussian distribution with the given 00183 * parameters. The resulting point is left in dest 00184 * operates on the given %parameter. 00185 * @param mean dvector with the centre. 00186 * @param covarianceMatrix dmatrix with the covariances 00187 * @param dest dvector with the resulting point 00188 * @return true if apply successful or false otherwise. 00189 */ 00190 bool apply(const dvector& mean, const dmatrix& covarianceMatrix, 00191 dvector& dest) const; 00192 00193 /** 00194 * creates either one cluster of a set of clusters with the given 00195 * number of points the covarianceMatrix . 00196 * @param mean dvector with the centre. 00197 * @param covarianceMatrix dmatrix with the covariances 00198 * @param number int with the number of points to create 00199 * @param dest dmatrix with the resulting points in its rows 00200 * @return true if apply successful or false otherwise. 00201 */ 00202 bool apply(const dvector& mean, const dmatrix& covarianceMatrix, 00203 const int& number, dmatrix& dest) const; 00204 00205 /** 00206 * Apply 00207 * 00208 * @param mean list of dvectors with the centres. 00209 * @param covarianceMatrix list of dmatrix with the covariances 00210 * @param numbers list of int with the number of points to create in 00211 * each cluster 00212 * @param dest list of dmatrix with the resulting points in its rows 00213 * a one dmatrix for each cluster 00214 */ 00215 bool apply(std::list<dvector>& mean, std::list<dmatrix>& covarianceMatrix, 00216 std::list<int>& numbers, std::list<dmatrix>& dest) const; 00217 00218 /** 00219 * Apply 00220 * 00221 * @param mean list of dvector with the centres. 00222 * @param covarianceMatrix list of dmatrix with the covariances 00223 * @param numbers list of int with the number of points to create 00224 * in each cluster 00225 * @param dest dmatrix with the resulting points in its rows 00226 */ 00227 bool apply(std::list<dvector>& mean, std::list<dmatrix>& covarianceMatrix, 00228 std::list<int>& numbers, dmatrix& dest) const; 00229 00230 00231 00232 /** 00233 * In this context this method doesn't make any sense, so it 00234 * returns 0.Don't use. Use draw(const int& number) instead 00235 * and set number equal to one; this returns also only one point 00236 * in a Matrix with only one row 00237 * This function was reimplented, because the function is implemented in 00238 * the parent class, and this function can't be used at this place. 00239 */ 00240 double draw() const; 00241 00242 /** 00243 * computes a number of points with the %parameters set in the 00244 * parameters object 00245 * @param number int with the number of points to create 00246 * @returns return a dmatrix with the points in its rows. 00247 */ 00248 dmatrix draw(const int& number) const; 00249 00250 /** 00251 * copy data of "other" functor. 00252 * @param other the functor to be copied 00253 * @return a reference to this functor object 00254 */ 00255 multivariateGaussian& copy(const multivariateGaussian& other); 00256 00257 /** 00258 * alias for copy member 00259 * @param other the functor to be copied 00260 * @return a reference to this functor object 00261 */ 00262 multivariateGaussian& operator=(const multivariateGaussian& other); 00263 00264 /** 00265 * returns a pointer to a clone of this functor. 00266 */ 00267 virtual functor* clone() const; 00268 00269 /** 00270 * returns used parameters 00271 */ 00272 const parameters& getParameters() const; 00273 00274 protected: 00275 /** 00276 * random functor used for generation of points 00277 */ 00278 gaussianDistribution *gaussFunc; 00279 00280 /** 00281 * get the eigenvalues and eigenvectors 00282 */ 00283 jacobi<double> *eigenFunc; 00284 00285 /** 00286 * compute determinate 00287 */ 00288 luDecomposition<double> *detFunc; 00289 00290 00291 }; 00292 } 00293 00294 #endif