SHOGUN
v1.1.0
|
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-2008 Soeren Sonnenburg 00008 * Written (W) 1999-2008 Gunnar Raetsch 00009 * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society 00010 */ 00011 00012 #ifndef __GUIFEATURES__H 00013 #define __GUIFEATURES__H 00014 00015 #include <shogun/lib/config.h> 00016 #include <shogun/base/SGObject.h> 00017 #include <shogun/features/Labels.h> 00018 #include <shogun/features/Features.h> 00019 #include <shogun/features/RealFileFeatures.h> 00020 #include <shogun/features/TOPFeatures.h> 00021 #include <shogun/features/FKFeatures.h> 00022 #include <shogun/features/StringFeatures.h> 00023 #include <shogun/features/SimpleFeatures.h> 00024 #include <shogun/features/SparseFeatures.h> 00025 #include <shogun/features/CombinedFeatures.h> 00026 #include <shogun/features/CombinedDotFeatures.h> 00027 #include <shogun/features/WDFeatures.h> 00028 #include <shogun/features/ExplicitSpecFeatures.h> 00029 #include <shogun/features/ImplicitWeightedSpecFeatures.h> 00030 00031 namespace shogun 00032 { 00033 class CSGInterface; 00034 00036 class CGUIFeatures : public CSGObject 00037 { 00039 enum EFeatureType 00040 { 00041 Simple, 00042 Sparse 00043 }; 00044 00045 public: 00047 CGUIFeatures() {}; 00051 CGUIFeatures(CSGInterface* interface); 00053 ~CGUIFeatures(); 00054 00056 inline CFeatures *get_train_features() { return train_features; } 00058 inline CFeatures *get_test_features() { return test_features; } 00059 00063 inline bool set_train_features(CFeatures* f) 00064 { 00065 //invalidate_train(); 00066 SG_UNREF(train_features); 00067 SG_REF(f); 00068 train_features=f; 00069 return true; 00070 } 00071 00075 inline bool set_test_features(CFeatures* f) 00076 { 00077 //invalidate_test(); 00078 SG_UNREF(test_features); 00079 SG_REF(f); 00080 test_features=f; 00081 return true; 00082 } 00083 00087 void add_train_features(CFeatures* f); 00091 void add_test_features(CFeatures* f); 00095 void add_train_dotfeatures(CDotFeatures* f); 00099 void add_test_dotfeatures(CDotFeatures* f); 00100 00102 bool del_last_feature_obj(char* target); 00103 00105 void invalidate_train(); 00107 void invalidate_test(); 00108 00110 bool load( 00111 char* filename, char* fclass, char* type, char* target, 00112 int32_t size, int32_t comp_features); 00114 bool save(char* filename, char* type, char* target); 00116 bool clean(char* target); 00118 bool reshape(char* target, int32_t num_feat, int32_t num_vec); 00119 00121 CFeatures* get_convert_features(char* target); 00123 bool set_convert_features(CFeatures* features, char* target); 00124 00128 CSparseFeatures<float64_t>* convert_simple_real_to_sparse_real( 00129 CSimpleFeatures<float64_t>* src); 00133 CStringFeatures<char>* convert_simple_char_to_string_char( 00134 CSimpleFeatures<char>* src); 00139 CSimpleFeatures<float64_t>* convert_simple_char_to_simple_align( 00140 CSimpleFeatures<char>* src, 00141 float64_t gap_cost=0); 00145 CSimpleFeatures<float64_t>* convert_simple_word_to_simple_salzberg( 00146 CSimpleFeatures<uint16_t>* src); 00147 00151 CTOPFeatures* convert_string_word_to_simple_top( 00152 CStringFeatures<uint16_t>* src); 00156 CFKFeatures* convert_string_word_to_simple_fk( 00157 CStringFeatures<uint16_t>* src); 00161 CSimpleFeatures<float64_t>* convert_sparse_real_to_simple_real( 00162 CSparseFeatures<float64_t>* src); 00167 CExplicitSpecFeatures* convert_string_byte_to_spec_word( 00168 CStringFeatures<uint16_t>* src, bool use_norm); 00169 00178 template <class CT, class ST> 00179 CStringFeatures<ST>* convert_string_char_to_string_generic( 00180 CStringFeatures<CT>* src, 00181 int32_t order=1, int32_t start=0, int32_t gap=0, char rev='f', CAlphabet* alpha=NULL) 00182 { 00183 if (src && src->get_feature_class()==C_STRING) 00184 { 00185 //create dense features with 0 cache 00186 SG_INFO("Converting CT STRING features to ST STRING ones (order=%i).\n",order); 00187 bool free_alpha=false; 00188 00189 if (!alpha) 00190 { 00191 CAlphabet* a = src->get_alphabet(); 00192 00193 if ( a && a->get_alphabet() == DNA ) 00194 alpha=new CAlphabet(RAWDNA); 00195 else 00196 alpha=new CAlphabet(a); 00197 00198 free_alpha=true; 00199 SG_UNREF(a); 00200 } 00201 00202 CStringFeatures<ST>* sf=new CStringFeatures<ST>(alpha); 00203 if (sf && sf->obtain_from_char_features(src, start, order, gap, rev=='r')) 00204 { 00205 SG_INFO("Conversion was successful.\n"); 00206 return sf; 00207 } 00208 00209 if (free_alpha) 00210 SG_UNREF(alpha); 00211 SG_UNREF(sf); 00212 } 00213 else 00214 SG_ERROR("No features of class/type STRING/CT available.\n"); 00215 00216 return NULL; 00217 } 00218 00219 00221 bool set_reference_features(char* target); 00222 00224 inline virtual const char* get_name() const { return "GUIFeatures"; } 00225 00226 protected: 00228 CSGInterface* ui; 00230 CFeatures *train_features; 00232 CFeatures *test_features; 00234 CFeatures *ref_features; 00235 }; 00236 } 00237 #endif