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 <shogun/lib/common.h>
00016 #include <shogun/features/DotFeatures.h>
00017 #include <shogun/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() const
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
00101 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00102
00103 struct wd_feature_iterator
00104 {
00106 uint8_t* vec;
00108 int32_t vidx;
00110 int32_t vlen;
00112 bool vfree;
00113
00118 int32_t lim;
00119 int32_t* val;
00120 int32_t asize;
00121 int32_t asizem1;
00122 int32_t offs;
00123 int32_t k;
00124 int32_t i;
00125 int32_t o;
00127 };
00128 #endif
00129
00139 virtual void* get_feature_iterator(int32_t vector_index);
00140
00151 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00152
00158 virtual void free_feature_iterator(void* iterator);
00159
00164 virtual CFeatures* duplicate() const;
00165
00170 inline virtual EFeatureType get_feature_type()
00171 {
00172 return F_UNKNOWN;
00173 }
00174
00179 inline virtual EFeatureClass get_feature_class()
00180 {
00181 return C_WD;
00182 }
00183
00184 inline virtual int32_t get_num_vectors() const
00185 {
00186 return num_strings;
00187 }
00188
00189 inline virtual int32_t get_size()
00190 {
00191 return sizeof(float64_t);
00192 }
00193
00196 void set_normalization_const(float64_t n=0);
00197
00199 inline float64_t get_normalization_const()
00200 {
00201 return normalization_const;
00202 }
00203
00205 inline virtual const char* get_name() const { return "WDFeatures"; }
00206
00213 void set_wd_weights(float64_t* weights, int32_t d)
00214 {
00215 ASSERT(d==degree);
00216
00217 for (int32_t i=0; i<degree; i++)
00218 wd_weights[i]=weights[i];
00219 }
00220
00222 void set_wd_weights();
00223
00224 protected:
00226 CStringFeatures<uint8_t>* strings;
00227
00229 int32_t degree;
00231 int32_t from_degree;
00233 int32_t string_length;
00235 int32_t num_strings;
00237 int32_t alphabet_size;
00239 int32_t w_dim;
00241 float64_t* wd_weights;
00242
00244 float64_t normalization_const;
00245
00246 };
00247 }
00248 #endif // _WDFEATURES_H___