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 .......: ltiFuzzyCMeans.h 00027 * authors ....: Jens Paustenbach 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 5.2.2002 00030 * revisions ..: $Id: ltiFuzzyCMeans.h,v 1.6 2006/02/07 18:17:40 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_FUZZY_C_MEANS_H_ 00034 #define _LTI_FUZZY_C_MEANS_H_ 00035 00036 00037 #include "ltiVector.h" 00038 #include "ltiMatrix.h" 00039 00040 #include "ltiCentroidClustering.h" 00041 00042 namespace lti { 00043 /** 00044 * this class implements the fuzzy C Means clustering algorithm. 00045 * <p> the class arbitrary picks a given number of points as centroids. 00046 * Between these centroids and the given points is a degree of membership 00047 * calculated. According to these memberships new centroids are calculated. 00048 * This is done until the convergence criterion is met. <p> The convergence 00049 * criterion could be either the the maximum number of allowed iterations or 00050 * the distance between the matrix of centroids of the last two iterations 00051 * <B> the classify method is not implemented, instead the classify method 00052 * of superclass is used which does not regard the memberships of the points 00053 * to the centroids </B> 00054 */ 00055 class fuzzyCMeans : public centroidClustering { 00056 public: 00057 /** 00058 * the parameters for the class fuzzyCMeans 00059 */ 00060 class parameters : public centroidClustering::parameters { 00061 public: 00062 /** 00063 * default constructor 00064 */ 00065 parameters(); 00066 00067 /** 00068 * copy constructor 00069 * @param other the parameters object to be copied 00070 */ 00071 parameters(const parameters& other); 00072 00073 /** 00074 * destructor 00075 */ 00076 virtual ~parameters(); 00077 00078 /** 00079 * returns name of this type 00080 */ 00081 const char* getTypeName() const; 00082 00083 /** 00084 * copy the contents of a parameters object 00085 * @param other the parameters object to be copied 00086 * @return a reference to this parameters object 00087 */ 00088 parameters& copy(const parameters& other); 00089 00090 /** 00091 * copy the contents of a parameters object 00092 * @param other the parameters object to be copied 00093 * @return a reference to this parameters object 00094 */ 00095 parameters& operator=(const parameters& other); 00096 00097 00098 /** 00099 * returns a pointer to a clone of the parameters 00100 */ 00101 virtual classifier::parameters* clone() const; 00102 00103 /** 00104 * write the parameters in the given ioHandler 00105 * @param handler the ioHandler to be used 00106 * @param complete if true (the default) the enclosing begin/end will 00107 * be also written, otherwise only the data block will be written. 00108 * @return true if write was successful 00109 */ 00110 virtual bool write(ioHandler& handler,const bool complete=true) const; 00111 00112 /** 00113 * read the parameters from the given ioHandler 00114 * @param handler the ioHandler to be used 00115 * @param complete if true (the default) the enclosing begin/end will 00116 * be also written, otherwise only the data block will be written. 00117 * @return true if write was successful 00118 */ 00119 virtual bool read(ioHandler& handler,const bool complete=true); 00120 00121 # ifdef _LTI_MSC_6 00122 /** 00123 * this function is required by MSVC only, as a workaround for a 00124 * very awful bug, which exists since MSVC V.4.0, and still by 00125 * V.6.0 with all bugfixes (so called "service packs") remains 00126 * there... This method is also public due to another bug, so please 00127 * NEVER EVER call this method directly: use read() instead 00128 */ 00129 bool readMS(ioHandler& handler,const bool complete=true); 00130 00131 /** 00132 * this function is required by MSVC only, as a workaround for a 00133 * very awful bug, which exists since MSVC V.4.0, and still by 00134 * V.6.0 with all bugfixes (so called "service packs") remains 00135 * there... This method is also public due to another bug, so please 00136 * NEVER EVER call this method directly: use write() instead 00137 */ 00138 bool writeMS(ioHandler& handler,const bool complete=true) const; 00139 # endif 00140 00141 // ------------------------------------------------ 00142 // the parameters 00143 // ------------------------------------------------ 00144 00145 00146 /** 00147 * bias the algorithm either towards hard clustering (nearby 1) or 00148 * fuzzy clustering (bigger 1); this parameter must be bigger than 1 00149 */ 00150 double fuzzifier; 00151 00152 /** 00153 * norm in which the distances are measured, valid options are L1 and L2 00154 */ 00155 eDistanceMeasure norm; 00156 00157 /** 00158 * the algorithm terminates if the distance between the new centroids 00159 * and the old centroids is smaller than epsilon 00160 */ 00161 double epsilon; 00162 00163 /** 00164 * maximum number of Iteration before the algorithm terminates 00165 */ 00166 int maxIterations; 00167 00168 /** 00169 * the number of clusters the algorithm creates 00170 */ 00171 int nbOfClusters; 00172 00173 }; 00174 00175 /** 00176 * default constructor 00177 */ 00178 fuzzyCMeans(); 00179 00180 /** 00181 * copy constructor 00182 * @param other the object to be copied 00183 */ 00184 fuzzyCMeans(const fuzzyCMeans& other); 00185 00186 /** 00187 * destructor 00188 */ 00189 virtual ~fuzzyCMeans(); 00190 00191 /** 00192 * returns the name of this type ("fuzzyCMeans") 00193 */ 00194 virtual const char* getTypeName() const; 00195 00196 /** 00197 * copy data of "other" clustering. 00198 * @param other the clustering to be copied 00199 * @return a reference to this clustering object 00200 */ 00201 fuzzyCMeans& copy(const fuzzyCMeans& other); 00202 00203 /** 00204 * alias for copy member 00205 * @param other the clustering to be copied 00206 * @return a reference to this clustering object 00207 */ 00208 fuzzyCMeans& operator=(const fuzzyCMeans& other); 00209 00210 /** 00211 * returns a pointer to a clone of this clustering. 00212 */ 00213 virtual classifier* clone() const; 00214 00215 /** 00216 * returns used parameters 00217 */ 00218 const parameters& getParameters() const; 00219 00220 /** 00221 * set the parameters of the classifier, calls setParameters of the 00222 * superclass and tests if the parameter norm is valid. If not a status 00223 * string is set. 00224 */ 00225 bool setParameters(const classifier::parameters& theParams); 00226 00227 /** 00228 * Unsupervised training. The vectors in the <code>input</code> 00229 * matrix will be put into groups according to the training 00230 * algorithm. Additionally, an integer indicating the class each 00231 * point belongs to is returned. <p> By default this method uses 00232 * the other train method train(const dmatrix&) and then 00233 * calls classify(const dvector&) to get the ids for each 00234 * trainvector. These ids are then returned. 00235 * @param input the matrix with the input vectors (each row is a training 00236 * vector) 00237 * @param ids vector of class ids for each input point 00238 * @return true if successful, false otherwise. (if false you can check 00239 * the error message with getStatusString()) 00240 */ 00241 virtual bool train(const dmatrix& input, 00242 ivector& ids); 00243 00244 /** 00245 * Unsupervised training. 00246 * The vectors in the <code>input</code> matrix 00247 * will be clustered using each specific method. 00248 * @param input the matrix with the input vectors (each row is a training 00249 * vector) 00250 * @return true if successful, false otherwise. (if false you can check 00251 * the error message with getStatusString()) 00252 */ 00253 virtual bool train(const dmatrix& input); 00254 00255 }; 00256 } 00257 00258 #endif