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:
00031
00038 CWDFeatures(CStringFeatures<uint8_t>* str, int32_t order, int32_t from_order);
00039
00041 CWDFeatures(const CWDFeatures & orig);
00042
00044 virtual ~CWDFeatures();
00045
00053 inline virtual int32_t get_dim_feature_space()
00054 {
00055 return w_dim;
00056 }
00057
00064 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00065
00072 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00073
00082 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00083
00089 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00090 {
00091 int32_t vlen=-1;
00092 bool free_vec;
00093 uint8_t* vec=strings->get_feature_vector(num, vlen, free_vec);
00094 strings->free_feature_vector(vec, num, free_vec);
00095 return degree*vlen;
00096 }
00097
00099 struct wd_feature_iterator
00100 {
00102 uint8_t* vec;
00104 int32_t vidx;
00106 int32_t vlen;
00108 bool vfree;
00109
00114 int32_t lim;
00115 int32_t* val;
00116 int32_t asize;
00117 int32_t asizem1;
00118 int32_t offs;
00119 int32_t k;
00120 int32_t i;
00121 int32_t o;
00123 };
00124
00134 virtual void* get_feature_iterator(int32_t vector_index);
00135
00146 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00147
00153 virtual void free_feature_iterator(void* iterator);
00154
00159 virtual CFeatures* duplicate() const;
00160
00165 inline virtual EFeatureType get_feature_type()
00166 {
00167 return F_UNKNOWN;
00168 }
00169
00174 inline virtual EFeatureClass get_feature_class()
00175 {
00176 return C_WD;
00177 }
00178
00179 inline virtual int32_t get_num_vectors()
00180 {
00181 return num_strings;
00182 }
00183
00184 inline virtual int32_t get_size()
00185 {
00186 return sizeof(float64_t);
00187 }
00188
00191 void set_normalization_const(float64_t n=0);
00192
00194 inline float64_t get_normalization_const()
00195 {
00196 return normalization_const;
00197 }
00198
00200 inline virtual const char* get_name() const { return "WDFeatures"; }
00201
00208 void set_wd_weights(float64_t* weights, int32_t d)
00209 {
00210 ASSERT(d==degree);
00211
00212 for (int32_t i=0; i<degree; i++)
00213 wd_weights[i]=weights[i];
00214 }
00215
00217 void set_wd_weights();
00218
00219 protected:
00221 CStringFeatures<uint8_t>* strings;
00222
00224 int32_t degree;
00226 int32_t from_degree;
00228 int32_t string_length;
00230 int32_t num_strings;
00232 int32_t alphabet_size;
00234 int32_t w_dim;
00236 float64_t* wd_weights;
00237
00239 float64_t normalization_const;
00240
00241 };
00242 }
00243 #endif // _WDFEATURES_H___