SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashedWDFeaturesTransposed.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 
11 #ifndef _HASHEDWDFEATURESTRANSPOSED_H___
12 #define _HASHEDWDFEATURESTRANSPOSED_H___
13 
14 #include <shogun/lib/common.h>
17 #include <shogun/lib/Hash.h>
18 
19 namespace shogun
20 {
21 template <class ST> class CStringFeatures;
22 
29 {
30  public:
33 
42  CHashedWDFeaturesTransposed(CStringFeatures<uint8_t>* str, int32_t start_order,
43  int32_t order, int32_t from_order, int32_t hash_bits=12);
44 
47 
50 
58  inline virtual int32_t get_dim_feature_space() const
59  {
60  return w_dim;
61  }
62 
70  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
71 
78  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
79 
91  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);
92 
104  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);
105 
106 
115  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
116 
122  virtual inline int32_t get_nnz_features_for_vector(int32_t num)
123  {
124  return w_dim/alphabet_size;
125  }
126 
131  virtual CFeatures* duplicate() const;
132 
137  inline virtual EFeatureType get_feature_type() const
138  {
139  return F_UNKNOWN;
140  }
141 
146  inline virtual EFeatureClass get_feature_class() const
147  {
148  return C_WD;
149  }
150 
151  inline virtual int32_t get_num_vectors() const
152  {
153  return num_strings;
154  }
155 
156  inline virtual int32_t get_size() const
157  {
158  return sizeof(float64_t);
159  }
160 
164 
167  {
168  return normalization_const;
169  }
170 
171  #ifndef DOXYGEN_SHOULD_SKIP_THIS
172 
173  struct hashed_wd_transposed_feature_iterator
174  {
176  uint16_t* vec;
178  int32_t vidx;
180  int32_t vlen;
182  bool vfree;
183 
185  int32_t index;
186 
187  };
188  #endif
189 
199  virtual void* get_feature_iterator(int32_t vector_index);
200 
211  virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
212 
218  virtual void free_feature_iterator(void* iterator);
219 
221  inline virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; }
222 
223  protected:
224 
226  void set_wd_weights();
227  static void* dense_dot_range_helper(void* p);
228 
229  protected:
232 
235 
237  int32_t degree;
239  int32_t start_degree;
241  int32_t from_degree;
243  int32_t string_length;
245  int32_t num_strings;
247  int32_t alphabet_size;
249  int32_t w_dim;
251  int32_t partial_w_dim;
255  uint32_t mask;
257  int32_t m_hash_bits;
258 
261 };
262 }
263 #endif // _HASHEDWDFEATURESTRANSPOSED_H___

SHOGUN Machine Learning Toolbox - Documentation