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) 2009 Soeren Sonnenburg 00008 * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _EXPLICITSPECFEATURES_H___ 00012 #define _EXPLICITSPECFEATURES_H___ 00013 00014 #include "lib/common.h" 00015 #include "lib/io.h" 00016 #include "features/DotFeatures.h" 00017 #include "features/StringFeatures.h" 00018 00019 namespace shogun 00020 { 00021 template <class ST> class CStringFeatures; 00022 00027 class CExplicitSpecFeatures : public CDotFeatures 00028 { 00029 public: 00030 00036 CExplicitSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true); 00037 00039 CExplicitSpecFeatures(const CExplicitSpecFeatures & orig); 00040 00042 virtual ~CExplicitSpecFeatures(); 00043 00048 virtual CFeatures* duplicate() const; 00049 00057 inline virtual int32_t get_dim_feature_space() 00058 { 00059 return spec_size; 00060 } 00061 00068 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2); 00069 00076 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len); 00077 00086 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00087 00093 virtual inline int32_t get_nnz_features_for_vector(int32_t num) 00094 { 00095 SG_NOTIMPLEMENTED; 00096 return 0; 00097 } 00098 00103 inline virtual EFeatureType get_feature_type() 00104 { 00105 return F_UNKNOWN; 00106 } 00107 00112 inline virtual EFeatureClass get_feature_class() 00113 { 00114 return C_SPEC; 00115 } 00116 00121 inline virtual int32_t get_num_vectors() 00122 { 00123 return num_strings; 00124 } 00125 00130 inline virtual int32_t get_size() 00131 { 00132 return sizeof(float64_t); 00133 } 00134 00136 inline virtual const char* get_name() const { return "ExplicitSpecFeatures"; } 00137 00138 protected: 00143 void obtain_kmer_spectrum(CStringFeatures<uint16_t>* str); 00144 00146 void delete_kmer_spectrum(); 00147 00148 protected: 00150 bool use_normalization; 00152 int32_t num_strings; 00154 int32_t alphabet_size; 00155 00157 int32_t spec_size; 00159 float64_t** k_spectrum; 00160 }; 00161 } 00162 #endif // _EXPLICITSPECFEATURES_H___