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 .......: ltiUnsupervisedClassifier.h 00027 * authors ....: Peter Doerfler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 29.08.2001 00030 * revisions ..: $Id: ltiUnsupervisedClassifier.h,v 1.4 2006/02/07 18:27:50 ltilib Exp $ 00031 */ 00032 00033 00034 #ifndef _LTI_UNSUPERVISEDCLASSIFIER_H_ 00035 #define _LTI_UNSUPERVISEDCLASSIFIER_H_ 00036 00037 #include "ltiClassifier.h" 00038 #include "ltiVector.h" 00039 #include "ltiMatrix.h" 00040 00041 namespace lti { 00042 00043 /** 00044 * Abstract class, parent of all unsupervised classifiers. 00045 * This class defines the interface for all unsupervised train methods. 00046 */ 00047 class unsupervisedClassifier : public classifier { 00048 00049 public: 00050 00051 // -------------------------------------------------- 00052 // unsupervisedClassifier::parameters 00053 // -------------------------------------------------- 00054 00055 /** 00056 * the parameters for the class unsupervisedClassifier are the 00057 * same as for classifier, except that the default value of 00058 * mulipleMode is changed to outputTemplate::Ignore. 00059 */ 00060 class parameters : public classifier::parameters { 00061 public: 00062 00063 /** 00064 * default constructor. Changes the defaults value of 00065 * parameters.multipleMode to outputTemplate::Ignore. 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 virtual ~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 * Alias for copy 00094 */ 00095 inline parameters& operator=(const parameters& other) { 00096 return copy(other); 00097 } 00098 00099 }; 00100 00101 /** 00102 * default constructor 00103 */ 00104 unsupervisedClassifier(); 00105 00106 /** 00107 * copy constructor 00108 * @param other the object to be copied 00109 */ 00110 unsupervisedClassifier(const unsupervisedClassifier& other); 00111 00112 /** 00113 * returns the name of this type ("unsupervisedClassifier") 00114 */ 00115 virtual const char* getTypeName() const; 00116 00117 /** 00118 * copy data of "other" functor. 00119 * @param other the functor to be copied 00120 * @return a reference to this functor object 00121 */ 00122 unsupervisedClassifier& copy(const unsupervisedClassifier& other); 00123 00124 /** 00125 * returns used parameters 00126 */ 00127 const parameters& getParameters() const; 00128 00129 /** 00130 * Unsupervised training. 00131 * The vectors in the <code>input</code> matrix 00132 * will be clustered using each specific method. 00133 * @param input the matrix with the input vectors (each row is a training 00134 * vector) 00135 * @return true if successful, false otherwise. (if false you can check 00136 * the error message with getStatusString()) 00137 */ 00138 virtual bool train(const dmatrix& input) =0; 00139 00140 /** 00141 * Unsupervised training. The vectors in the <code>input</code> 00142 * matrix will be put into groups according to the training 00143 * algorithm. Additionally, an integer indicating the class each 00144 * point belongs to is returned. 00145 * 00146 * By default this method uses the other train method 00147 * (see train(const dmatrix&)) and then calls 00148 * classifier::classify(const dvector&) to get the ids for each 00149 * train-vector. These ids are then returned. 00150 * 00151 * @param input the matrix with the input vectors 00152 * (each row is a training vector) 00153 * @param ids vector of class ids for each input point 00154 * @return true if successful, false otherwise. (if false you can check 00155 * the error message with getStatusString()) */ 00156 virtual bool train(const dmatrix& input, ivector& ids); 00157 00158 /** 00159 * Classification. 00160 * Classifies the feature and returns the outputVector with 00161 * the classification result. 00162 * @param feature the %vector to be classified 00163 * @param result the result of the classification 00164 * @return false if an error occurred during classification else true 00165 */ 00166 virtual bool 00167 classify(const dvector& feature, outputVector& result) const =0; 00168 00169 protected: 00170 00171 /** 00172 * Randomly selects numberOfPoints points (rows) from the data matrix. 00173 * If nubmerOfPoints is greater than the number of points in data, 00174 * points will be multiply selected. 00175 * @param data contains points to select from in rows 00176 * @param numberOfPoints number of points expected as result 00177 * @param randomPoints the points randomly selected from data 00178 * @return false if something went wrong, else true 00179 */ 00180 bool selectRandomPoints(const dmatrix& data, 00181 int numberOfPoints, 00182 dmatrix& randomPoints); 00183 }; 00184 } 00185 00186 #endif