SHOGUN
v3.2.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) 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 <shogun/lib/common.h> 00015 #include <shogun/features/DotFeatures.h> 00016 #include <shogun/features/StringFeatures.h> 00017 00018 namespace shogun 00019 { 00020 template <class ST> class CStringFeatures; 00021 00026 class CExplicitSpecFeatures : public CDotFeatures 00027 { 00028 public: 00030 CExplicitSpecFeatures(); 00031 00037 CExplicitSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true); 00038 00040 CExplicitSpecFeatures(const CExplicitSpecFeatures & orig); 00041 00043 virtual ~CExplicitSpecFeatures(); 00044 00049 virtual CFeatures* duplicate() const; 00050 00058 virtual int32_t get_dim_feature_space() const; 00059 00067 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00068 00075 virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len); 00076 00085 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, 00086 float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00087 00088 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00089 00090 struct explicit_spec_feature_iterator 00091 { 00093 uint16_t* vec; 00095 int32_t vidx; 00097 int32_t vlen; 00099 bool vfree; 00100 00102 int32_t index; 00103 00104 }; 00105 #endif 00106 00116 virtual void* get_feature_iterator(int32_t vector_index); 00117 00128 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator); 00129 00135 virtual void free_feature_iterator(void* iterator); 00136 00142 virtual int32_t get_nnz_features_for_vector(int32_t num); 00143 00148 virtual EFeatureType get_feature_type() const; 00149 00154 virtual EFeatureClass get_feature_class() const; 00155 00160 virtual int32_t get_num_vectors() const; 00161 00163 virtual const char* get_name() const { return "ExplicitSpecFeatures"; } 00164 00165 protected: 00170 void obtain_kmer_spectrum(CStringFeatures<uint16_t>* str); 00171 00173 void delete_kmer_spectrum(); 00174 00175 protected: 00177 bool use_normalization; 00179 int32_t num_strings; 00181 int32_t alphabet_size; 00182 00184 int32_t spec_size; 00186 float64_t** k_spectrum; 00187 }; 00188 } 00189 #endif // _EXPLICITSPECFEATURES_H___