Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _HASHEDWDFEATURESTRANSPOSED_H___
00012 #define _HASHEDWDFEATURESTRANSPOSED_H___
00013
00014 #include <shogun/lib/common.h>
00015 #include <shogun/features/DotFeatures.h>
00016 #include <shogun/features/StringFeatures.h>
00017 #include <shogun/lib/Hash.h>
00018
00019 namespace shogun
00020 {
00021 template <class ST> class CStringFeatures;
00022
00028 class CHashedWDFeaturesTransposed : public CDotFeatures
00029 {
00030 public:
00032 CHashedWDFeaturesTransposed(void);
00033
00042 CHashedWDFeaturesTransposed(CStringFeatures<uint8_t>* str, int32_t start_order,
00043 int32_t order, int32_t from_order, int32_t hash_bits=12);
00044
00046 CHashedWDFeaturesTransposed(const CHashedWDFeaturesTransposed & orig);
00047
00049 virtual ~CHashedWDFeaturesTransposed();
00050
00058 inline virtual int32_t get_dim_feature_space() const
00059 {
00060 return w_dim;
00061 }
00062
00070 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00071
00078 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00079
00091 virtual void dense_dot_range(float64_t* output, int32_t start, int32_t stop, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b);
00092
00104 virtual void dense_dot_range_subset(int32_t* sub_index, int32_t num, float64_t* output, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b);
00105
00106
00115 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00116
00122 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00123 {
00124 return w_dim/alphabet_size;
00125 }
00126
00131 virtual CFeatures* duplicate() const;
00132
00137 inline virtual EFeatureType get_feature_type()
00138 {
00139 return F_UNKNOWN;
00140 }
00141
00146 inline virtual EFeatureClass get_feature_class()
00147 {
00148 return C_WD;
00149 }
00150
00151 inline virtual int32_t get_num_vectors() const
00152 {
00153 return num_strings;
00154 }
00155
00156 inline virtual int32_t get_size()
00157 {
00158 return sizeof(float64_t);
00159 }
00160
00163 void set_normalization_const(float64_t n=0);
00164
00166 inline float64_t get_normalization_const()
00167 {
00168 return normalization_const;
00169 }
00170
00171 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00172
00173 struct hashed_wd_transposed_feature_iterator
00174 {
00176 uint16_t* vec;
00178 int32_t vidx;
00180 int32_t vlen;
00182 bool vfree;
00183
00185 int32_t index;
00186
00187 };
00188 #endif
00189
00199 virtual void* get_feature_iterator(int32_t vector_index)
00200 {
00201 SG_NOTIMPLEMENTED;
00202 return NULL;
00203 }
00204
00215 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)
00216 {
00217 SG_NOTIMPLEMENTED;
00218 return NULL;
00219 }
00220
00226 virtual void free_feature_iterator(void* iterator)
00227 {
00228 SG_NOTIMPLEMENTED;
00229 }
00230
00232 inline virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; }
00233
00234 protected:
00235
00237 void set_wd_weights();
00238 static void* dense_dot_range_helper(void* p);
00239
00240 protected:
00242 CStringFeatures<uint8_t>* strings;
00243
00245 SGString<uint8_t>* transposed_strings;
00246
00248 int32_t degree;
00250 int32_t start_degree;
00252 int32_t from_degree;
00254 int32_t string_length;
00256 int32_t num_strings;
00258 int32_t alphabet_size;
00260 int32_t w_dim;
00262 int32_t partial_w_dim;
00264 float64_t* wd_weights;
00266 uint32_t mask;
00268 int32_t m_hash_bits;
00269
00271 float64_t normalization_const;
00272 };
00273 }
00274 #endif // _HASHEDWDFEATURESTRANSPOSED_H___