Features.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _CFEATURES__H__
00013 #define _CFEATURES__H__
00014 
00015 #include "lib/common.h"
00016 #include "lib/File.h"
00017 #include "base/SGObject.h"
00018 #include "preproc/PreProc.h"
00019 #include "features/FeatureTypes.h"
00020 
00021 namespace shogun
00022 {
00023     class CFile;
00024     class CPreProc;
00025     class CKernel;
00026     enum EFeatureType;
00027     enum EFeatureClass;
00028     enum EFeatureProperty;
00029 }
00030 
00031 namespace shogun
00032 {
00033 
00053 class CFeatures : public CSGObject
00054 {
00055     public:
00060         CFeatures(int32_t size=0);
00061 
00063         CFeatures(const CFeatures& orig);
00064 
00069         CFeatures(CFile* loader);
00070 
00077         virtual CFeatures* duplicate() const=0 ;
00078 
00079         virtual ~CFeatures();
00080 
00087         virtual EFeatureType get_feature_type()=0;
00088 
00095         virtual EFeatureClass get_feature_class()=0;
00096 
00102         virtual int32_t add_preproc(CPreProc* p);
00103 
00109         virtual CPreProc* del_preproc(int32_t num);
00110 
00115         CPreProc* get_preproc(int32_t num);
00116 
00121         inline void set_preprocessed(int32_t num) { preprocessed[num]=true; }
00122 
00127         inline bool is_preprocessed(int32_t num) { return preprocessed[num]; }
00128 
00133         int32_t get_num_preprocessed();
00134 
00139         inline int32_t get_num_preproc() { return num_preproc; }
00140 
00142         void clean_preprocs();
00143 
00148         inline int32_t get_cache_size() { return cache_size; };
00149 
00156         virtual int32_t get_num_vectors()=0 ;
00157 
00166         virtual bool reshape(int32_t num_features, int32_t num_vectors) { return false; }
00167 
00174         virtual int32_t get_size()=0;
00175 
00177         void list_feature_obj();
00178 
00183         virtual void load(CFile* loader)
00184         {
00185             SG_NOTIMPLEMENTED;
00186         }
00187 
00192         virtual void save(CFile* writer)
00193         {
00194             SG_NOTIMPLEMENTED;
00195         }
00196 
00202         bool check_feature_compatibility(CFeatures* f);
00203 
00209         inline bool has_property(EFeatureProperty p) { return (properties & p) != 0; }
00210 
00215         inline void set_property(EFeatureProperty p)
00216         {
00217             properties |= p;
00218         }
00219 
00224         inline void unset_property(EFeatureProperty p)
00225         {
00226             properties &= (properties | p) ^ p;
00227         }
00228 #ifdef HAVE_BOOST_SERIALIZATION
00229     private:
00230 
00231         friend class ::boost::serialization::access;
00232         template<class Archive>
00233             void save(Archive & ar, const unsigned int archive_version) const
00234             {
00235 
00236                 SG_DEBUG("archiving Features\n");
00237 
00238                 ar & ::boost::serialization::base_object<CSGObject>(*this);
00239 
00240                 ar & properties;
00241                 ar & cache_size;
00242                 ar & num_preproc;
00243 
00244                 //TODO
00245                 //ar & preproc;
00246                 for (int i=0; i < num_preproc; ++i) {
00247                     ar & preprocessed[i];
00248                 }
00249 
00250                 SG_DEBUG("done archiving Features\n");
00251 
00252             }
00253 
00254         template<class Archive>
00255             void load(Archive & ar, const unsigned int archive_version)
00256             {
00257 
00258                 SG_DEBUG("archiving Features\n");
00259 
00260                 ar & ::boost::serialization::base_object<CSGObject>(*this);
00261 
00262                 ar & properties;
00263                 ar & cache_size;
00264                 ar & num_preproc;
00265 
00266                 //TODO
00267                 //ar & preproc;
00268 
00269                 if (num_preproc > 0)
00270                 {
00271                     preprocessed = new bool[num_preproc];
00272                     for (int i=0; i< num_preproc; ++i){
00273                         ar & preprocessed[i];
00274                     }
00275 
00276                 }
00277 
00278                 SG_DEBUG("done archiving Features\n");
00279 
00280             }
00281 
00282         GLOBAL_BOOST_SERIALIZATION_SPLIT_MEMBER();
00283 
00284 
00285 #endif //HAVE_BOOST_SERIALIZATION
00286 
00287     private:
00289         uint64_t  properties;
00290 
00292         int32_t cache_size;
00293 
00295         CPreProc** preproc;
00296 
00298         int32_t num_preproc;
00299 
00301         bool* preprocessed;
00302 };
00303 }
00304 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation