latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 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 Digital Image/Signal Processing Library 00026 * file .......: ltiCentroidClustering.h 00027 * authors ....: Peter Doerfler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 29.08.2001 00030 * revisions ..: $Id: ltiCentroidClustering.h,v 1.5 2006/02/07 18:12:34 ltilib Exp $ 00031 */ 00032 00033 #include "ltiObject.h" 00034 #include "ltiClustering.h" 00035 00036 00037 #ifndef _LTI_CENTROIDCLUSTERING_H_ 00038 #define _LTI_CENTROIDCLUSTERING_H_ 00039 00040 namespace lti { 00041 00042 00043 /** 00044 * Base class for all clustering methods that use centroids or prototypes 00045 * for describing individual clusters. A classify(const dvector&) method 00046 * is implemented that should work for most subclasses. 00047 */ 00048 class centroidClustering : public clustering { 00049 00050 public: 00051 00052 /** 00053 * default constructor 00054 */ 00055 centroidClustering(); 00056 00057 /** 00058 * copy constructor 00059 * @param other the %object to be copied 00060 */ 00061 centroidClustering(const centroidClustering& other); 00062 00063 /** 00064 * destructor 00065 */ 00066 virtual ~centroidClustering(); 00067 00068 /** 00069 * returns the name of this type ("centroidClustering") 00070 */ 00071 virtual const char* getTypeName() const; 00072 00073 /** 00074 * copy data of "other" functor. 00075 * @param other the functor to be copied 00076 * @return a reference to this functor %object 00077 */ 00078 centroidClustering& copy(const centroidClustering& other); 00079 00080 /** 00081 * returns used parameters 00082 */ 00083 const parameters& getParameters() const; 00084 00085 /** 00086 * classifies a new data point. <p> 00087 * This method can be used by all centroid classifiers if they properly 00088 * initialize the classifier::output member. I.e. for each output unit 00089 * the list of probabilities may contain only one entry with probability 00090 * one and each id may be used only once. <p> 00091 * Since the classifier::output expects a probability vector as result 00092 * from the clustering method, the dissimilarity measure usually returned 00093 * must be converted to a similarity measure. Here, this is done by first 00094 * normalizing the vector of dissimilarities, then subtracting this vector 00095 * from a vector filled with ones and, finally, normalizing the result. 00096 * This operation yields similarity values between zero and one for 00097 * arbitrary scales of the feature space. Information about possible reject 00098 * cases is lost through the first normalizaton, though. 00099 * 00100 * @param feature vector to be classified 00101 * @param result result as described above 00102 * @return true if successful, false otherwise 00103 */ 00104 virtual bool classify(const dvector& feature, outputVector& result) const; 00105 00106 /** 00107 * Returns a const reference to the centroids of the clustering 00108 * @return const reference to the centroids 00109 */ 00110 const dmatrix& getCentroids() const; 00111 00112 /** 00113 * Declared so it wont be forgotten 00114 */ 00115 virtual bool train(const dmatrix& input) =0; 00116 00117 /** 00118 * Calls clustering::train(const dmatrix&, ivector&) 00119 */ 00120 virtual bool train(const dmatrix& input, 00121 ivector& ids); 00122 00123 /** 00124 * write the rbf classifier in the given ioHandler 00125 * @param handler the ioHandler to be used 00126 * @param complete if true (the default) the enclosing begin/end will 00127 * be also written, otherwise only the data block will be written. 00128 * @return true if write was successful 00129 */ 00130 virtual bool write(ioHandler& handler,const bool complete=true) const; 00131 00132 /** 00133 * read the rbf classifier from the given ioHandler 00134 * @param handler the ioHandler to be used 00135 * @param complete if true (the default) the enclosing begin/end will 00136 * be also written, otherwise only the data block will be written. 00137 * @return true if write was successful 00138 */ 00139 virtual bool read(ioHandler& handler,const bool complete=true); 00140 00141 protected: 00142 00143 /** 00144 * returns current parameters. (non const! -> protected) 00145 */ 00146 // parameters& getParameters() {return *params;}; 00147 00148 /** 00149 * matrix containing the centroids formed by the clustering method 00150 */ 00151 dmatrix centroids; 00152 00153 00154 private: 00155 00156 /** 00157 * Used for calculating a similarity measure from the dissimilarities 00158 * return by the clustering: 1-d 00159 */ 00160 static double probabilize(const double& d); 00161 00162 }; 00163 00164 } 00165 00166 #endif