SHOGUN  3.2.1
 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/config.h>
15 
16 #include <shogun/lib/common.h>
19 #include <shogun/lib/Hash.h>
20 
21 namespace shogun
22 {
23 template<class ST> class CStringFeatures;
24 
31 {
32 public:
35 
44  CHashedWDFeatures(CStringFeatures<uint8_t>* str, int32_t start_order,
45  int32_t order, int32_t from_order, int32_t hash_bits=12);
46 
49 
51  virtual ~CHashedWDFeatures();
52 
60  virtual int32_t get_dim_feature_space() const
61  {
62  return w_dim;
63  }
64 
72  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
73 
80  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
81  int32_t vec2_len);
82 
91  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
92  float64_t* vec2, int32_t vec2_len, bool abs_val=false);
93 
99  virtual int32_t get_nnz_features_for_vector(int32_t num);
100 
101  #ifndef DOXYGEN_SHOULD_SKIP_THIS
102 
103  struct hashed_wd_feature_iterator
104  {
106  uint16_t* vec;
108  int32_t vidx;
110  int32_t vlen;
112  bool vfree;
113 
115  int32_t index;
116 
117  };
118  #endif
119 
129  virtual void* get_feature_iterator(int32_t vector_index);
130 
141  virtual bool get_next_feature(int32_t& index, float64_t& value,
142  void* iterator);
143 
149  virtual void free_feature_iterator(void* iterator);
150 
155  virtual CFeatures* duplicate() const;
156 
162  {
163  return F_UNKNOWN;
164  }
165 
171  {
172  return C_WD;
173  }
174 
175  virtual int32_t get_num_vectors() const
176  {
177  return num_strings;
178  }
179 
183 
186  {
187  return normalization_const;
188  }
189 
191  virtual const char* get_name() const
192  {
193  return "HashedWDFeatures";
194  }
195 
196 protected:
197 
199  void set_wd_weights();
200 
201 protected:
204 
206  int32_t degree;
208  int32_t start_degree;
210  int32_t from_degree;
212  int32_t string_length;
214  int32_t num_strings;
216  int32_t alphabet_size;
218  int32_t w_dim;
220  int32_t partial_w_dim;
224  uint32_t mask;
226  int32_t m_hash_bits;
227 
230 };
231 }
232 #endif // _HASHEDWDFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation