Features.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _CFEATURES__H__
00013 #define _CFEATURES__H__
00014
00015 #include "lib/common.h"
00016 #include "base/SGObject.h"
00017 #include "preproc/PreProc.h"
00018 #include "features/FeatureTypes.h"
00019
00020 namespace shogun
00021 {
00022 class CPreProc;
00023 enum EFeatureType;
00024 enum EFeatureClass;
00025 enum EFeatureProperty;
00026 }
00027
00028 namespace shogun
00029 {
00030
00050 class CFeatures : public CSGObject
00051 {
00052 public:
00057 CFeatures(int32_t size=0);
00058
00060 CFeatures(const CFeatures& orig);
00061
00066 CFeatures(char* fname);
00067
00074 virtual CFeatures* duplicate() const=0 ;
00075
00076 virtual ~CFeatures();
00077
00084 virtual EFeatureType get_feature_type()=0;
00085
00092 virtual EFeatureClass get_feature_class()=0;
00093
00099 virtual int32_t add_preproc(CPreProc* p);
00100
00106 virtual CPreProc* del_preproc(int32_t num);
00107
00112 CPreProc* get_preproc(int32_t num);
00113
00118 inline void set_preprocessed(int32_t num) { preprocessed[num]=true; }
00119
00124 inline bool is_preprocessed(int32_t num) { return preprocessed[num]; }
00125
00130 int32_t get_num_preprocessed();
00131
00136 inline int32_t get_num_preproc() { return num_preproc; }
00137
00139 void clean_preprocs();
00140
00145 inline int32_t get_cache_size() { return cache_size; };
00146
00153 virtual int32_t get_num_vectors()=0 ;
00154
00163 virtual bool reshape(int32_t num_features, int32_t num_vectors) { return false; }
00164
00171 virtual int32_t get_size()=0;
00172
00174 void list_feature_obj();
00175
00181 virtual bool load(char* fname);
00182
00188 virtual bool save(char* fname);
00189
00195 bool check_feature_compatibility(CFeatures* f);
00196
00202 inline bool has_property(EFeatureProperty p) { return (properties & p) != 0; }
00203
00208 inline void set_property(EFeatureProperty p)
00209 {
00210 properties |= p;
00211 }
00212
00217 inline void unset_property(EFeatureProperty p)
00218 {
00219 properties &= (properties | p) ^ p;
00220 }
00221 #ifdef HAVE_BOOST_SERIALIZATION
00222 private:
00223
00224 friend class ::boost::serialization::access;
00225 template<class Archive>
00226 void save(Archive & ar, const unsigned int archive_version) const
00227 {
00228
00229 SG_DEBUG("archiving Features\n");
00230
00231 ar & ::boost::serialization::base_object<CSGObject>(*this);
00232
00233 ar & properties;
00234 ar & cache_size;
00235 ar & num_preproc;
00236
00237
00238
00239 for (int i=0; i < num_preproc; ++i) {
00240 ar & preprocessed[i];
00241 }
00242
00243 SG_DEBUG("done archiving Features\n");
00244
00245 }
00246
00247 template<class Archive>
00248 void load(Archive & ar, const unsigned int archive_version)
00249 {
00250
00251 SG_DEBUG("archiving Features\n");
00252
00253 ar & ::boost::serialization::base_object<CSGObject>(*this);
00254
00255 ar & properties;
00256 ar & cache_size;
00257 ar & num_preproc;
00258
00259
00260
00261
00262 if (num_preproc > 0)
00263 {
00264 preprocessed = new bool[num_preproc];
00265 for (int i=0; i< num_preproc; ++i){
00266 ar & preprocessed[i];
00267 }
00268
00269 }
00270
00271 SG_DEBUG("done archiving Features\n");
00272
00273 }
00274
00275 GLOBAL_BOOST_SERIALIZATION_SPLIT_MEMBER();
00276
00277
00278 #endif //HAVE_BOOST_SERIALIZATION
00279
00280 private:
00282 uint64_t properties;
00283
00285 int32_t cache_size;
00286
00288 CPreProc** preproc;
00289
00291 int32_t num_preproc;
00292
00294 bool* preprocessed;
00295 };
00296 }
00297 #endif