SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashedWDFeatures.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 _HASHEDWDFEATURES_H___
12 #define _HASHEDWDFEATURES_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  CHashedWDFeatures(CStringFeatures<uint8_t>* str, int32_t start_order,
43  int32_t order, int32_t from_order, int32_t hash_bits=12);
44 
47 
49  virtual ~CHashedWDFeatures();
50 
58  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,
79  int32_t vec2_len);
80 
89  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
90  float64_t* vec2, int32_t vec2_len, bool abs_val=false);
91 
97  virtual int32_t get_nnz_features_for_vector(int32_t num);
98 
99  #ifndef DOXYGEN_SHOULD_SKIP_THIS
100 
101  struct hashed_wd_feature_iterator
102  {
104  uint16_t* vec;
106  int32_t vidx;
108  int32_t vlen;
110  bool vfree;
111 
113  int32_t index;
114 
115  };
116  #endif
117 
127  virtual void* get_feature_iterator(int32_t vector_index);
128 
139  virtual bool get_next_feature(int32_t& index, float64_t& value,
140  void* iterator);
141 
147  virtual void free_feature_iterator(void* iterator);
148 
153  virtual CFeatures* duplicate() const;
154 
160  {
161  return F_UNKNOWN;
162  }
163 
169  {
170  return C_WD;
171  }
172 
173  virtual int32_t get_num_vectors() const
174  {
175  return num_strings;
176  }
177 
181 
184  {
185  return normalization_const;
186  }
187 
189  virtual const char* get_name() const
190  {
191  return "HashedWDFeatures";
192  }
193 
194 protected:
195 
197  void set_wd_weights();
198 
199 protected:
202 
204  int32_t degree;
206  int32_t start_degree;
208  int32_t from_degree;
210  int32_t string_length;
212  int32_t num_strings;
214  int32_t alphabet_size;
216  int32_t w_dim;
218  int32_t partial_w_dim;
222  uint32_t mask;
224  int32_t m_hash_bits;
225 
228 };
229 }
230 #endif // _HASHEDWDFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation