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

ltiUciDataReader.h

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 .......: ltiUciDataReader.h
00027  * authors ....: Peter Doerfler, Jens Paustenbach
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 18.3.2002
00030  * revisions ..: $Id: ltiUciDataReader.h,v 1.8 2006/02/08 12:08:36 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_UCI_DATA_READER_H_
00034 #define _LTI_UCI_DATA_READER_H_
00035 
00036 #include <fstream>
00037 
00038 #include "ltiMatrix.h"
00039 #include "ltiVector.h"
00040 
00041 #include "ltiIOFunctor.h"
00042 
00043 namespace lti {
00044   /**
00045    * Reads data in the form as it is often found in standard data sets:
00046    * Raw data either just a matrix of doubles with each row a feature
00047    * vector, or rows containing feature vectors and an id as last element
00048    * of the row.
00049    *
00050    * This %functor needs the number of dimensions, the existence of
00051    * ids and the filename as parameters. The according data from that file is
00052    * returned by the apply method.
00053    */
00054   class uciDataReader : public ioFunctor {
00055   public:
00056     /**
00057      * the parameters for the class uciDataReader
00058      */
00059     class parameters : public ioFunctor::parameters {
00060     public:
00061       /**
00062        * default constructor
00063        */
00064       parameters();
00065 
00066       /**
00067        * copy constructor
00068        * @param other the parameters object to be copied
00069        */
00070       parameters(const parameters& other);
00071 
00072       /**
00073        * destructor
00074        */
00075       ~parameters();
00076 
00077       /**
00078        * returns name of this type
00079        */
00080       const char* getTypeName() const;
00081 
00082       /**
00083        * copy the contents of a parameters object
00084        * @param other the parameters object to be copied
00085        * @return a reference to this parameters object
00086        */
00087       parameters& copy(const parameters& other);
00088 
00089       /**
00090        * copy the contents of a parameters object
00091        * @param other the parameters object to be copied
00092        * @return a reference to this parameters object
00093        */
00094       parameters& operator=(const parameters& other);
00095 
00096 
00097       /**
00098        * returns a pointer to a clone of the parameters
00099        */
00100       virtual functor::parameters* clone() const;
00101 
00102       /**
00103        * write the parameters in the given ioHandler
00104        * @param handler the ioHandler to be used
00105        * @param complete if true (the default) the enclosing begin/end will
00106        *        be also written, otherwise only the data block will be written.
00107        * @return true if write was successful
00108        */
00109       virtual bool write(ioHandler& handler,const bool complete=true) const;
00110 
00111       /**
00112        * read the parameters from the given ioHandler
00113        * @param handler the ioHandler to be used
00114        * @param complete if true (the default) the enclosing begin/end will
00115        *        be also written, otherwise only the data block will be written.
00116        * @return true if write was successful
00117        */
00118       virtual bool read(ioHandler& handler,const bool complete=true);
00119 
00120 #     ifdef _LTI_MSC_6
00121       /**
00122        * this function is required by MSVC only, as a workaround for a
00123        * very awful bug, which exists since MSVC V.4.0, and still by
00124        * V.6.0 with all bugfixes (so called "service packs") remains
00125        * there...  This method is also public due to another bug, so please
00126        * NEVER EVER call this method directly: use read() instead
00127        */
00128       bool readMS(ioHandler& handler,const bool complete=true);
00129 
00130       /**
00131        * this function is required by MSVC only, as a workaround for a
00132        * very awful bug, which exists since MSVC V.4.0, and still by
00133        * V.6.0 with all bugfixes (so called "service packs") remains
00134        * there...  This method is also public due to another bug, so please
00135        * NEVER EVER call this method directly: use write() instead
00136        */
00137       bool writeMS(ioHandler& handler,const bool complete=true) const;
00138 #     endif
00139 
00140       // ------------------------------------------------
00141       // the parameters
00142       // ------------------------------------------------
00143 
00144       /**
00145        * true if there is an id indicating the class of the feature vector
00146        * at the end of each line
00147        */
00148       bool hasIds;
00149 
00150       /**
00151        * the number of dimensions of each feature vector
00152        */
00153       int numberOfDimensions;
00154 
00155       /**
00156        * true if there is a header. The header has in its first line the
00157        * number of points, and in the second line the number of dimensions.
00158        */
00159       bool hasHeader;
00160 
00161     };
00162 
00163     /**
00164      * default constructor
00165      */
00166     uciDataReader();
00167 
00168     /**
00169      * sets the filename
00170      */
00171     uciDataReader(std::string filename);
00172 
00173     /**
00174      * sets the parameters filename, numberOfDimensions and hasIds
00175      */
00176     uciDataReader(std::string filename, int nbDimensions, bool bIds=true,
00177                   bool hasHeader=false);
00178 
00179     /**
00180      * copy constructor
00181      * @param other the object to be copied
00182      */
00183     uciDataReader(const uciDataReader& other);
00184 
00185     /**
00186      * destructor
00187      */
00188     virtual ~uciDataReader();
00189 
00190     /**
00191      * returns the name of this type ("uciDataReader")
00192      */
00193     virtual const char* getTypeName() const;
00194 
00195     /**
00196      * Reads data from the file given in the parameters.
00197      * @param data the feature vectors
00198      * @return true if apply successful or false otherwise.
00199      */
00200     bool apply(dmatrix& data) const;
00201 
00202     /**
00203      * Reads data and ids from the file given in the parameters. If
00204      * hasIds is false <code>ids</code> is empty.
00205      * @param data the feature vectors
00206      * @param ids ids of the feature vectors
00207      * @return true if apply successful or false otherwise.
00208      */
00209     bool apply(dmatrix& data, ivector& ids) const;
00210 
00211     /**
00212      * Reads data from the file given in the parameters.
00213      * @param data the feature vectors
00214      * @return true if apply successful or false otherwise.
00215      */
00216     bool apply(fmatrix& data) const;
00217 
00218     /**
00219      * Reads data and ids from the file given in the parameters. If
00220      * hasIds is false <code>ids</code> is empty.
00221      * @param data the feature vectors
00222      * @param ids ids of the feature vectors
00223      * @return true if apply successful or false otherwise.
00224      */
00225     bool apply(fmatrix& data, ivector& ids) const;
00226 
00227     /**
00228      * copy data of "other" functor.
00229      * @param other the functor to be copied
00230      * @return a reference to this functor object
00231      */
00232     uciDataReader& copy(const uciDataReader& other);
00233 
00234     /**
00235      * alias for copy member
00236      * @param other the functor to be copied
00237      * @return a reference to this functor object
00238      */
00239     uciDataReader& operator=(const uciDataReader& other);
00240 
00241     /**
00242      * returns a pointer to a clone of this functor.
00243      */
00244     virtual functor* clone() const;
00245 
00246     /**
00247      * returns used parameters
00248      */
00249     const parameters& getParameters() const;
00250 
00251   };
00252 }
00253 
00254 #endif

Generated on Sat Apr 10 15:26:19 2010 for LTI-Lib by Doxygen 1.6.1