SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparsePolyFeatures.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 #ifndef _SPARSEPOLYFEATURES__H__
11 #define _SPARSEPOLYFEATURES__H__
12 
13 #include <shogun/lib/common.h>
16 
17 namespace shogun
18 {
25 {
26  public:
29 
38  CSparsePolyFeatures(CSparseFeatures<float64_t>* feat, int32_t degree, bool normalize, int32_t hash_bits);
39 
40  virtual ~CSparsePolyFeatures();
41 
49 
54  inline virtual int32_t get_dim_feature_space() const;
55 
61  virtual inline int32_t get_nnz_features_for_vector(int32_t num);
62 
67  inline virtual EFeatureType get_feature_type() const;
68 
73  inline virtual EFeatureClass get_feature_class() const;
74 
79  inline virtual int32_t get_num_vectors() const;
80 
88  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
89 
94  inline virtual int32_t get_size() const;
95 
96  #ifndef DOXYGEN_SHOULD_SKIP_THIS
97 
98  struct sparse_poly_feature_iterator
99  {
101  uint16_t* vec;
103  int32_t vidx;
105  int32_t vlen;
107  bool vfree;
108 
110  int32_t index;
111  };
112  #endif
113 
123  virtual void* get_feature_iterator(int32_t vector_index);
124 
135  bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
136 
142  void free_feature_iterator(void* iterator);
143 
148  CFeatures* duplicate() const;
149 
154  inline virtual const char* get_name() const { return "SparsePolyFeatures"; }
155 
163  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
164 
173  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
174 
175  protected:
178 
179  protected:
183  int32_t m_degree;
193  uint32_t mask;
195  int32_t m_hash_bits;
196  private:
198  void init();
199 
200  private:
202  int32_t m_normalization_values_len;
203 };
204 }
205 #endif // _SPARSEPOLYFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation