Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _WDFEATURES_H___
00013 #define _WDFEATURES_H___
00014
00015 #include "lib/common.h"
00016 #include "features/DotFeatures.h"
00017 #include "features/StringFeatures.h"
00018
00019 namespace shogun
00020 {
00021 template <class ST> class CStringFeatures;
00022
00028 class CWDFeatures : public CDotFeatures
00029 {
00030 public:
00032 CWDFeatures(void);
00033
00040 CWDFeatures(CStringFeatures<uint8_t>* str, int32_t order, int32_t from_order);
00041
00043 CWDFeatures(const CWDFeatures & orig);
00044
00046 virtual ~CWDFeatures();
00047
00055 inline virtual int32_t get_dim_feature_space()
00056 {
00057 return w_dim;
00058 }
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, const float64_t* vec2, int32_t vec2_len);
00076
00085 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00086
00092 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00093 {
00094 int32_t vlen=-1;
00095 bool free_vec;
00096 uint8_t* vec=strings->get_feature_vector(num, vlen, free_vec);
00097 strings->free_feature_vector(vec, num, free_vec);
00098 return degree*vlen;
00099 }
00100
00102 struct wd_feature_iterator
00103 {
00105 uint8_t* vec;
00107 int32_t vidx;
00109 int32_t vlen;
00111 bool vfree;
00112
00117 int32_t lim;
00118 int32_t* val;
00119 int32_t asize;
00120 int32_t asizem1;
00121 int32_t offs;
00122 int32_t k;
00123 int32_t i;
00124 int32_t o;
00126 };
00127
00137 virtual void* get_feature_iterator(int32_t vector_index);
00138
00149 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00150
00156 virtual void free_feature_iterator(void* iterator);
00157
00162 virtual CFeatures* duplicate() const;
00163
00168 inline virtual EFeatureType get_feature_type()
00169 {
00170 return F_UNKNOWN;
00171 }
00172
00177 inline virtual EFeatureClass get_feature_class()
00178 {
00179 return C_WD;
00180 }
00181
00182 inline virtual int32_t get_num_vectors()
00183 {
00184 return num_strings;
00185 }
00186
00187 inline virtual int32_t get_size()
00188 {
00189 return sizeof(float64_t);
00190 }
00191
00194 void set_normalization_const(float64_t n=0);
00195
00197 inline float64_t get_normalization_const()
00198 {
00199 return normalization_const;
00200 }
00201
00203 inline virtual const char* get_name() const { return "WDFeatures"; }
00204
00211 void set_wd_weights(float64_t* weights, int32_t d)
00212 {
00213 ASSERT(d==degree);
00214
00215 for (int32_t i=0; i<degree; i++)
00216 wd_weights[i]=weights[i];
00217 }
00218
00220 void set_wd_weights();
00221
00222 protected:
00224 CStringFeatures<uint8_t>* strings;
00225
00227 int32_t degree;
00229 int32_t from_degree;
00231 int32_t string_length;
00233 int32_t num_strings;
00235 int32_t alphabet_size;
00237 int32_t w_dim;
00239 float64_t* wd_weights;
00240
00242 float64_t normalization_const;
00243
00244 };
00245 }
00246 #endif // _WDFEATURES_H___