SHOGUN  v3.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  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 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 
138  {
139  return F_UNKNOWN;
140  }
141 
147  {
148  return C_WD;
149  }
150 
151  virtual int32_t get_num_vectors() const
152  {
153  return num_strings;
154  }
155 
159 
162  {
163  return normalization_const;
164  }
165 
166  #ifndef DOXYGEN_SHOULD_SKIP_THIS
167 
168  struct hashed_wd_transposed_feature_iterator
169  {
171  uint16_t* vec;
173  int32_t vidx;
175  int32_t vlen;
177  bool vfree;
178 
180  int32_t index;
181 
182  };
183  #endif
184 
194  virtual void* get_feature_iterator(int32_t vector_index);
195 
206  virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
207 
213  virtual void free_feature_iterator(void* iterator);
214 
216  virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; }
217 
218  protected:
219 
221  void set_wd_weights();
222  static void* dense_dot_range_helper(void* p);
223 
224  protected:
227 
230 
232  int32_t degree;
234  int32_t start_degree;
236  int32_t from_degree;
238  int32_t string_length;
240  int32_t num_strings;
242  int32_t alphabet_size;
244  int32_t w_dim;
246  int32_t partial_w_dim;
250  uint32_t mask;
252  int32_t m_hash_bits;
253 
256 };
257 }
258 #endif // _HASHEDWDFEATURESTRANSPOSED_H___

SHOGUN Machine Learning Toolbox - Documentation