SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PolyFeatures.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) 2009 Jonas Behr
8  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 #ifndef _POLYFEATURES__H__
11 #define _POLYFEATURES__H__
12 
13 #include <shogun/lib/common.h>
16 
17 
18 namespace shogun
19 {
26 {
27  public:
29  CPolyFeatures();
30 
37  CPolyFeatures(CDenseFeatures<float64_t>* feat, int32_t degree, bool normalize);
38 
39  virtual ~CPolyFeatures();
40 
47  CPolyFeatures(const CPolyFeatures & orig);
48 
53  virtual int32_t get_dim_feature_space() const;
54 
60  virtual int32_t get_nnz_features_for_vector(int32_t num);
61 
66  virtual EFeatureType get_feature_type() const;
67 
72  virtual EFeatureClass get_feature_class() const;
73 
78  virtual int32_t get_num_vectors() const;
79 
87  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
88 
93  CFeatures* duplicate() const;
94 
99  virtual const char* get_name() const { return "PolyFeatures"; }
100 
108  float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
109 
118  void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
119 
120  #ifndef DOXYGEN_SHOULD_SKIP_THIS
121 
122  struct poly_feature_iterator
123  {
125  uint16_t* vec;
127  int32_t vidx;
129  int32_t vlen;
131  bool vfree;
132 
134  int32_t index;
135 
136  };
137  #endif
138 
148  virtual void* get_feature_iterator(int32_t vector_index);
149 
160  virtual bool get_next_feature(int32_t& index, float64_t& value,
161  void* iterator);
162 
168  virtual void free_feature_iterator(void* iterator);
169 
170  protected:
171 
174 
176  void store_multi_index();
177 
180  void enumerate_multi_index(const int32_t feat_idx, uint16_t** index,
181  uint16_t* exponents, const int32_t degree);
185 
189  int32_t bico2(int32_t n, int32_t k);
190 
193  int32_t bico(int32_t n, int32_t k);
194 
201  int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
202 
204  int32_t multinomialcoef(int32_t* exps, int32_t len);
205 
208 
210  float64_t factln(int32_t n);
211 
212  protected:
213 
217  int32_t m_degree;
226  uint16_t* m_multi_index;
231  private:
232  index_t multi_index_length;
233  index_t multinomial_coefficients_length;
234  index_t normalization_values_length;
235 
237  void register_parameters();
238 };
239 }
240 #endif // _POLYFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation