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 .......: ltiManualCrispDecisionTree.h 00027 * authors ....: Peter Doerfler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 25.2.2002 00030 * revisions ..: $Id: ltiManualCrispDecisionTree.h,v 1.6 2006/02/07 18:21:29 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_MANUAL_CRISP_DECISION_TREE_H_ 00034 #define _LTI_MANUAL_CRISP_DECISION_TREE_H_ 00035 00036 00037 #include "ltiMatrix.h" 00038 #include "ltiVector.h" 00039 00040 #include "ltiCrispDecisionTree.h" 00041 00042 namespace lti { 00043 /** 00044 * This class serves the manual construction of a crisp decision 00045 * tree with crispNodes that have univariate decision 00046 * functions. Instead of training data, the train method is given 00047 * the nodes' conditions and ids in pre-order. Only one element of 00048 * each row vector can be unequal to zero. This dimension and the 00049 * value are taken for the dimension and threshold of the 00050 * condition. Thus, only univariate decisions can be used. The 00051 * following example shows the data and id values of the train 00052 * method and the corresponding tree: 00053 * 00054 * \verbatim 00055 * +- -+ +- -+ 00056 * | 0 0 2 | | -1 | 00057 * | 1 0 0 | | -1 | 00058 * | 0 2 0 | | -1 | 00059 * | 0 1 0 | | -1 | 00060 * | 0 0 0 | | 2 | 00061 * data = | 0 0 1 | ids = | -1 | 00062 * | 0 0 0 | | 5 | 00063 * | 0 0 0 | | 0 | 00064 * | 0 0 0 | | 1 | 00065 * | 0 0 0 | | 3 | 00066 * | 0 0 0 | | 4 | 00067 * +- -+ +- -+ 00068 * \endverbatim 00069 * 00070 * \image html manualCrispDecisionTree.png 00071 * 00072 * The outputTemplate %object of the tree will be initialized with the 00073 * ids given in the ids vector. If other or multiple ids are desired, the 00074 * outputTemplate %object must be set manually. 00075 */ 00076 class manualCrispDecisionTree : public crispDecisionTree { 00077 public: 00078 /** 00079 * the parameters for the class manualCrispDecisionTree 00080 */ 00081 class parameters : public crispDecisionTree::parameters { 00082 public: 00083 /** 00084 * default constructor 00085 */ 00086 parameters(); 00087 00088 /** 00089 * copy constructor 00090 * @param other the parameters object to be copied 00091 */ 00092 parameters(const parameters& other); 00093 00094 /** 00095 * destructor 00096 */ 00097 virtual ~parameters(); 00098 00099 /** 00100 * returns name of this type 00101 */ 00102 const char* getTypeName() const; 00103 00104 /** 00105 * copy the contents of a parameters object 00106 * @param other the parameters object to be copied 00107 * @return a reference to this parameters object 00108 */ 00109 parameters& copy(const parameters& other); 00110 00111 /** 00112 * copy the contents of a parameters object 00113 * @param other the parameters object to be copied 00114 * @return a reference to this parameters object 00115 */ 00116 parameters& operator=(const parameters& other); 00117 00118 00119 /** 00120 * returns a pointer to a clone of the parameters 00121 */ 00122 virtual classifier::parameters* clone() const; 00123 00124 /** 00125 * write the parameters in the given ioHandler 00126 * @param handler the ioHandler to be used 00127 * @param complete if true (the default) the enclosing begin/end will 00128 * be also written, otherwise only the data block will be written. 00129 * @return true if write was successful 00130 */ 00131 virtual bool write(ioHandler& handler,const bool complete=true) const; 00132 00133 /** 00134 * read the parameters from the given ioHandler 00135 * @param handler the ioHandler to be used 00136 * @param complete if true (the default) the enclosing begin/end will 00137 * be also written, otherwise only the data block will be written. 00138 * @return true if write was successful 00139 */ 00140 virtual bool read(ioHandler& handler,const bool complete=true); 00141 00142 # ifdef _LTI_MSC_6 00143 /** 00144 * this function is required by MSVC only, as a workaround for a 00145 * very awful bug, which exists since MSVC V.4.0, and still by 00146 * V.6.0 with all bugfixes (so called "service packs") remains 00147 * there... This method is also public due to another bug, so please 00148 * NEVER EVER call this method directly: use read() instead 00149 */ 00150 bool readMS(ioHandler& handler,const bool complete=true); 00151 00152 /** 00153 * this function is required by MSVC only, as a workaround for a 00154 * very awful bug, which exists since MSVC V.4.0, and still by 00155 * V.6.0 with all bugfixes (so called "service packs") remains 00156 * there... This method is also public due to another bug, so please 00157 * NEVER EVER call this method directly: use write() instead 00158 */ 00159 bool writeMS(ioHandler& handler,const bool complete=true) const; 00160 # endif 00161 00162 // ------------------------------------------------ 00163 // the parameters 00164 // ------------------------------------------------ 00165 00166 //TODO: comment the parameters of your classifier 00167 // If you add more parameters manually, do not forget to do following: 00168 // 1. indicate in the default constructor the default values 00169 // 2. make sure that the copy member also copy your new parameters 00170 // 3. make sure that the read and write members also read and 00171 // write your parameters 00172 00173 00174 }; 00175 00176 /** 00177 * default constructor 00178 */ 00179 manualCrispDecisionTree(); 00180 00181 /** 00182 * copy constructor 00183 * @param other the object to be copied 00184 */ 00185 manualCrispDecisionTree(const manualCrispDecisionTree& other); 00186 00187 /** 00188 * destructor 00189 */ 00190 virtual ~manualCrispDecisionTree(); 00191 00192 /** 00193 * returns the name of this type ("manualCrispDecisionTree") 00194 */ 00195 virtual const char* getTypeName() const; 00196 00197 /** 00198 * copy data of "other" classifier. 00199 * @param other the classifier to be copied 00200 * @return a reference to this classifier object 00201 */ 00202 manualCrispDecisionTree& copy(const manualCrispDecisionTree& other); 00203 00204 /** 00205 * alias for copy member 00206 * @param other the classifier to be copied 00207 * @return a reference to this classifier object 00208 */ 00209 manualCrispDecisionTree& operator=(const manualCrispDecisionTree& other); 00210 00211 /** 00212 * returns a pointer to a clone of this classifier. 00213 */ 00214 virtual classifier* clone() const; 00215 00216 /** 00217 * returns used parameters 00218 */ 00219 const parameters& getParameters() const; 00220 00221 /** 00222 * See description of this class 00223 * @param input the conditions of the nodes 00224 * @param ids the ids of the nodes. 00225 * @return true if successful, false otherwise. (if false you can check 00226 * the error message with getStatusString()) 00227 */ 00228 virtual bool train(const dmatrix& input, 00229 const ivector& ids); 00230 00231 00232 //TODO: comment the attributes of your classifier 00233 // If you add more attributes manually, do not forget to do following: 00234 // 1. indicate in the default constructor the default values 00235 // 2. make sure that the copy member also copy your new attributes, or 00236 // to ensure there, that these attributes are properly initialized. 00237 00238 }; 00239 } 00240 00241 #endif