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 .......: ltiCombination.h 00027 * authors ....: Pablo Alvarado, Peter Doerfler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 5.9.2001 00030 * revisions ..: $Id: ltiCombination.h,v 1.7 2006/02/07 18:14:50 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_COMBINATION_H_ 00034 #define _LTI_COMBINATION_H_ 00035 00036 #include "ltiClassifier.h" 00037 #include "ltiFunctor.h" 00038 00039 namespace lti { 00040 /** 00041 * This class is used to combine several results of different 00042 * classifier::output objects. 00043 * 00044 * There are many possibilities to do this. All of them will use 00045 * internaly the classifier::sortedOutput type to compute the 00046 * probability for each class. You can just combine linearly the 00047 * results or use the probabilistic Borda count to consider also how 00048 * sure is a classifier of its result. 00049 * 00050 * Probabilistic Borda Count is documented in S. Syberichs. 00051 * "Entscheidungs-Fusion zur 3D-Objekterkennung in einem 00052 * hierarchischen Klassifikationssystem", Diplomarbeit, Lehrstuhl 00053 * für Technische Informatik, RWTH-Aachen, Juni 2001 00054 */ 00055 class combination : public functor { 00056 public: 00057 00058 00059 /** 00060 * the parameters for the class combination 00061 */ 00062 class parameters : public functor::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 * Possible types of combination strategies. 00149 * The ProbabilisticBordaCount is described in the diploma thesis of 00150 * Stefan Syberichs at the LTI, RWTH Aachen: "Decision Fusion for 3D 00151 * Object Recognition in a Hierarchical Classification System". 00152 */ 00153 enum eCombinationStrategy { 00154 Linear, 00155 ProbabilisticBordaCount 00156 }; 00157 00158 /** 00159 * Strategy used for combination. Default Linear. 00160 * @see eCombinationStrategy 00161 */ 00162 eCombinationStrategy combinationStrategy; 00163 00164 /** 00165 * Normalize the result of the combination 00166 * Default: true 00167 */ 00168 bool normalize; 00169 00170 /** 00171 * Normalize the outputVectors to be combined before combination. 00172 * Default false. Usually, the inputs are normalized anyway. 00173 */ 00174 bool normalizeInputs; 00175 00176 /** 00177 * The inputs can be weighted. If this value is true, the corresponding 00178 * %vector weights must be set as well. Default false. 00179 */ 00180 bool useWeights; 00181 00182 /** 00183 * The weights in case of weighted combination. Default empty. 00184 */ 00185 dvector weights; 00186 }; 00187 00188 /** 00189 * default constructor 00190 */ 00191 combination(); 00192 00193 /** 00194 * copy constructor 00195 * @param other the object to be copied 00196 */ 00197 combination(const combination& other); 00198 00199 /** 00200 * destructor 00201 */ 00202 virtual ~combination(); 00203 00204 /** 00205 * returns the name of this type ("combination") 00206 */ 00207 virtual const char* getTypeName() const; 00208 00209 /** 00210 * Combine the given list of classifier::outputVector objects into one 00211 * outputVector object according to the parameter settings. 00212 * 00213 * @param src list of classifier::outputvector objects with the partial 00214 * classification results. 00215 * 00216 * @param dest classifier::outputvector where the result will be left. 00217 * @return true if apply successful or false otherwise. 00218 */ 00219 bool apply(const std::list<classifier::outputVector>& src, 00220 classifier::outputVector& dest) const; 00221 00222 /** 00223 * Combine the given list of classifier::outputVector objects into one 00224 * outputVector object according to the parameter settings. No matter 00225 * what the parameters are, the given weights will be used for 00226 * combination. 00227 * 00228 * @param src list of classifier::outputvector objects with the partial 00229 * classification results. 00230 * @param weights used for weighting the inputs in same order. 00231 * @param dest classifier::outputvector where the result will be left. 00232 * @return true if apply successful or false otherwise. 00233 */ 00234 bool apply(const std::list<classifier::outputVector>& src, 00235 const dvector& weights, 00236 classifier::outputVector& dest) const; 00237 00238 /** 00239 * copy data of "other" functor. 00240 * @param other the functor to be copied 00241 * @return a reference to this functor object 00242 */ 00243 combination& copy(const combination& other); 00244 00245 /** 00246 * alias for copy member 00247 * @param other the functor to be copied 00248 * @return a reference to this functor object 00249 */ 00250 combination& operator=(const combination& other); 00251 00252 /** 00253 * returns a pointer to a clone of this functor. 00254 */ 00255 virtual functor* clone() const; 00256 00257 /** 00258 * returns used parameters 00259 */ 00260 const parameters& getParameters() const; 00261 00262 protected: 00263 00264 /** 00265 * Calculates the sum of the outputVectors contained in src and 00266 * leaves the result in dest. Returns false if the %vectors in src 00267 * are not compatible, ie contain the same labels. 00268 * @param src list of outputVectors to be summed up 00269 * @param dest result of the sum 00270 * @return false if values in list are incompatible 00271 */ 00272 bool sumOfVectors(const std::list<classifier::outputVector> src, 00273 classifier::outputVector& dest) const; 00274 00275 /** 00276 * Calculates the weighted sum of the outputVectors contained in src and 00277 * leaves the result in dest. Returns false if the %vectors in src 00278 * are not compatible, ie contain the same labels. 00279 * @param src list of outputVectors to be summed up 00280 * @param weights used for weighting the outputVectors in src 00281 * @param dest result of the sum 00282 * @return false if values in list are incompatible 00283 */ 00284 bool sumOfVectors(const std::list<classifier::outputVector> src, 00285 const dvector& weights, 00286 classifier::outputVector& dest) const; 00287 00288 /** 00289 * First calculates the ProbablilisticBordaCount for each input 00290 * %vector then sums these measures and returns the sum in 00291 * dest. Returns false if the %vectors in src are not compatible, 00292 * ie contain the same labels. 00293 * @param src list of outputVectors to be summed up 00294 * @param dest result of the sum 00295 * @return false if values in list are incompatible 00296 */ 00297 bool probBordaCount(const std::list<classifier::outputVector> src, 00298 classifier::outputVector& dest) const; 00299 00300 /** 00301 * First calculates the ProbablilisticBordaCount for each input 00302 * %vector then sums these measures weighted by weights and returns the 00303 * sum in dest. Returns false if the %vectors in src are not compatible, 00304 * ie contain the same labels. 00305 * @param src list of outputVectors to be summed up 00306 * @param weights used for weighting the outputVectors in src 00307 * @param dest result of the sum 00308 * @return false if values in list are incompatible 00309 */ 00310 bool probBordaCount(const std::list<classifier::outputVector> src, 00311 const dvector& weights, 00312 classifier::outputVector& dest) const; 00313 00314 00315 /** 00316 * Checks whether all outputVectors contained in src are 00317 * compatible to each other and that none of them contains the 00318 * same label more than once. Returns true if everything is ok. 00319 */ 00320 bool 00321 noMultAndCompatible(const std::list<classifier::outputVector> src) const; 00322 00323 }; 00324 00325 } 00326 00327 #endif