LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiClustering.h

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 .......: ltiClustering.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 29.08.2001
00030  * revisions ..: $Id: ltiClustering.h,v 1.6 2006/02/07 18:14:11 ltilib Exp $
00031  */
00032 
00033 #include "ltiObject.h"
00034 #include "ltiUnsupervisedClassifier.h"
00035 
00036 
00037 #ifndef _LTI_CLUSTERING_H_
00038 #define _LTI_CLUSTERING_H_
00039 
00040 namespace lti {
00041 
00042   /**
00043    * Base class for all clustering algorithms. Clustering algorithms
00044    * can follow different training strategies as indicated by the
00045    * parameter clusterMode. Representations of the clusters are
00046    * modelled in subclasses of this class, e.g. centroidClustering.
00047    */
00048   class clustering : public unsupervisedClassifier {
00049 
00050   public:
00051 
00052     /**
00053      * parameters for clustering functors.
00054      * Provides a clusterMode which is of type eClusterMode
00055      */
00056     class parameters : public unsupervisedClassifier::parameters {
00057 
00058     public:
00059       /**
00060        * default constructor
00061        */
00062       parameters();
00063 
00064       /**
00065        * copy constructor
00066        * @param other the parameters %object to be copied
00067        */
00068       parameters(const parameters& other);
00069 
00070       /**
00071        * destructor
00072        */
00073       virtual ~parameters();
00074 
00075       /**
00076        * returns name of this type
00077        */
00078       const char* getTypeName() const;
00079 
00080       /**
00081        * copy the contents of a parameters %object
00082        * @param other the parameters %object to be copied
00083        * @return a reference to this parameters %object
00084        */
00085       parameters& copy(const parameters& other);
00086 
00087       /**
00088        * returns a pointer to a clone of the parameters
00089        */
00090       virtual classifier::parameters* clone() const;
00091 
00092       /**
00093        * write the parameters in the given ioHandler
00094        * @param handler the ioHandler to be used
00095        * @param complete if true (the default) the enclosing begin/end will
00096        *        be also written, otherwise only the data block will be written.
00097        * @return true if write was successful
00098        */
00099       virtual bool write(ioHandler& handler,const bool complete=true) const;
00100 
00101       /**
00102        * read the parameters from the given ioHandler
00103        * @param handler the ioHandler to be used
00104        * @param complete if true (the default) the enclosing begin/end will
00105        *        be also written, otherwise only the data block will be written.
00106        * @return true if write was successful
00107        */
00108       virtual bool read(ioHandler& handler,const bool complete=true);
00109 
00110 #     ifdef _LTI_MSC_6
00111       /**
00112        * this function is required by MSVC only, as a workaround for a
00113        * very awful bug, which exists since MSVC V.4.0, and still by
00114        * V.6.0 with all bugfixes (so called "service packs") remains
00115        * there...  This method is also public due to another bug, so please
00116        * NEVER EVER call this method directly: use read() instead
00117        */
00118       bool readMS(ioHandler& handler,const bool complete=true);
00119 
00120       /**
00121        * this function is required by MSVC only, as a workaround for a
00122        * very awful bug, which exists since MSVC V.4.0, and still by
00123        * V.6.0 with all bugfixes (so called "service packs") remains
00124        * there...  This method is also public due to another bug, so please
00125        * NEVER EVER call this method directly: use write() instead
00126        */
00127       bool writeMS(ioHandler& handler,const bool complete=true) const;
00128 #     endif
00129 
00130       // ------------------------------------------------
00131       // the parameters
00132       // ------------------------------------------------
00133 
00134       /**
00135        * Different methods for clustering data using basically the
00136        * same algorithm. Not all clusterModes must be available for
00137        * all clustering algorithms. See individual documentation. The
00138        * different modes have the following meaning: <p>
00139        * <dl>
00140        * <dt>batch</dt>
00141        * <dd>All data points must be available. Clusters are only updated
00142        *     after all available data has been considered.</dd>
00143        * <dt>sequential</dt>
00144        * <dd>Really sequential batch. Again all data must be available
00145        *     but clusters are updated after consideration of each data
00146        *     point. The update requires the knowledge of all other or
00147        *     previously considered data points.</dd>
00148        * <dt>online</dt>
00149        * <dd>Consideres the current data point only. Usually involves
00150        *     some learning rate etc.</dd>
00151        * <dt>miniBatch</dt>
00152        * <dd>A mix of sequential/online and batch. Build small batch blocks
00153        *     and do batch processing with them. Usually used instead of
00154        *     online to lessen effect of noise.</dd>
00155        * </dl>
00156        */
00157       enum eClusterMode {
00158         batch,
00159         sequential,
00160         online,
00161         miniBatch
00162       };
00163 
00164       /**
00165        * Kind of mode used for clustering. (Default batch)
00166        */
00167       eClusterMode clusterMode;
00168 
00169     };
00170 
00171     /**
00172      * default constructor
00173      */
00174     clustering();
00175 
00176     /**
00177      * copy constructor
00178      * @param other the %object to be copied
00179      */
00180     clustering(const clustering& other);
00181 
00182     /**
00183      * destructor
00184      */
00185     virtual ~clustering();
00186 
00187     /**
00188      * returns the name of this type ("clustering")
00189      */
00190     virtual const char* getTypeName() const;
00191 
00192     /**
00193      * copy data of "other" functor.
00194      * @param other the functor to be copied
00195      * @return a reference to this functor %object
00196      */
00197     clustering& copy(const clustering& other);
00198 
00199     /**
00200      * returns current parameters.
00201      */
00202     const parameters& getParameters() const;
00203 
00204     /**
00205      * train the clusterer with the vectors at the rows of input
00206      *
00207      * @param input the input data
00208      * @return true if successful, false otherwise.
00209      */
00210     virtual bool train(const dmatrix& input) =0;
00211 
00212     /**
00213      * train the clusterer with the vectors at the rows of input,
00214      * and return the cluster id for each of that vectors.
00215      *
00216      * @param input the input data
00217      * @param ids output vector where the cluster id per input vector will
00218      *        be stored.
00219      * @return true if successful, false otherwise.
00220      */
00221     virtual bool train(const dmatrix& input,
00222                        ivector& ids);
00223 
00224 
00225   };
00226 
00227 }
00228 
00229 #endif

Generated on Sat Apr 10 15:25:14 2010 for LTI-Lib by Doxygen 1.6.1