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 * Subset support written (W) 2011 Heiko Strathmann 00010 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00011 */ 00012 00013 #ifndef _CFEATURES__H__ 00014 #define _CFEATURES__H__ 00015 00016 #include <shogun/lib/common.h> 00017 #include <shogun/io/File.h> 00018 #include <shogun/base/SGObject.h> 00019 #include <shogun/preprocessor/Preprocessor.h> 00020 #include <shogun/features/FeatureTypes.h> 00021 #include <shogun/features/Subset.h> 00022 00023 namespace shogun 00024 { 00025 class CFile; 00026 class CPreprocessor; 00027 class CKernel; 00028 enum EFeatureType; 00029 enum EFeatureClass; 00030 enum EFeatureProperty; 00031 } 00032 00033 namespace shogun 00034 { 00035 00059 class CFeatures : public CSGObject 00060 { 00061 void init(void); 00062 00063 public: 00068 CFeatures(int32_t size=0); 00069 00071 CFeatures(const CFeatures& orig); 00072 00077 CFeatures(CFile* loader); 00078 00085 virtual CFeatures* duplicate() const=0; 00086 00087 virtual ~CFeatures(); 00088 00095 virtual EFeatureType get_feature_type()=0; 00096 00103 virtual EFeatureClass get_feature_class()=0; 00104 00110 virtual int32_t add_preprocessor(CPreprocessor* p); 00111 00117 virtual CPreprocessor* del_preprocessor(int32_t num); 00118 00123 CPreprocessor* get_preprocessor(int32_t num); 00124 00129 inline void set_preprocessed(int32_t num) { preprocessed[num]=true; } 00130 00135 inline bool is_preprocessed(int32_t num) { return preprocessed[num]; } 00136 00141 int32_t get_num_preprocessed(); 00142 00147 inline int32_t get_num_preprocessors() const { return num_preproc; } 00148 00150 void clean_preprocessors(); 00151 00156 inline int32_t get_cache_size() { return cache_size; }; 00157 00164 virtual int32_t get_num_vectors() const=0; 00165 00174 virtual bool reshape(int32_t num_features, int32_t num_vectors) 00175 { 00176 SG_NOTIMPLEMENTED; 00177 return false; 00178 } 00179 00186 virtual int32_t get_size()=0; 00187 00189 void list_feature_obj(); 00190 00195 virtual void load(CFile* loader) 00196 { 00197 SG_SET_LOCALE_C; 00198 SG_NOTIMPLEMENTED; 00199 SG_RESET_LOCALE; 00200 } 00201 00206 virtual void save(CFile* writer) 00207 { 00208 SG_SET_LOCALE_C; 00209 SG_NOTIMPLEMENTED; 00210 SG_RESET_LOCALE; 00211 } 00212 00218 bool check_feature_compatibility(CFeatures* f); 00219 00225 inline bool has_property(EFeatureProperty p) { return (properties & p) != 0; } 00226 00231 inline void set_property(EFeatureProperty p) 00232 { 00233 properties |= p; 00234 } 00235 00240 inline void unset_property(EFeatureProperty p) 00241 { 00242 properties &= (properties | p) ^ p; 00243 } 00244 00250 virtual void set_subset(CSubset* subset); 00251 00254 virtual void remove_subset(); 00255 00257 virtual void subset_changed_post() {} 00258 00264 inline index_t subset_idx_conversion(index_t idx) const 00265 { 00266 return m_subset ? m_subset->subset_idx_conversion(idx) : idx; 00267 } 00268 00272 inline bool has_subset() const { return m_subset!=NULL; } 00273 00283 virtual CFeatures* copy_subset(SGVector<index_t> indices) 00284 { 00285 SG_ERROR("copy_subset and therefore model storage of CMachine " 00286 "(required for cross-validation and model-selection is ", 00287 "not yet implemented for feature type %s\n", get_name()); 00288 return NULL; 00289 } 00290 00291 private: 00293 uint64_t properties; 00294 00296 int32_t cache_size; 00297 00299 CPreprocessor** preproc; 00300 00302 int32_t num_preproc; 00303 00305 bool* preprocessed; 00306 00307 protected: 00308 00310 CSubset* m_subset; 00311 }; 00312 } 00313 #endif