SHOGUN  v2.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  virtual int32_t get_size() const;
94 
99  CFeatures* duplicate() const;
100 
105  inline virtual const char* get_name() const { return "PolyFeatures"; }
106 
114  float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
115 
124  void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
125 
126  #ifndef DOXYGEN_SHOULD_SKIP_THIS
127 
128  struct poly_feature_iterator
129  {
131  uint16_t* vec;
133  int32_t vidx;
135  int32_t vlen;
137  bool vfree;
138 
140  int32_t index;
141 
142  };
143  #endif
144 
154  virtual void* get_feature_iterator(int32_t vector_index);
155 
166  virtual bool get_next_feature(int32_t& index, float64_t& value,
167  void* iterator);
168 
174  virtual void free_feature_iterator(void* iterator);
175 
176  protected:
177 
180 
182  void store_multi_index();
183 
186  void enumerate_multi_index(const int32_t feat_idx, uint16_t** index,
187  uint16_t* exponents, const int32_t degree);
191 
195  int32_t bico2(int32_t n, int32_t k);
196 
199  int32_t bico(int32_t n, int32_t k);
200 
207  int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
208 
210  int32_t multinomialcoef(int32_t* exps, int32_t len);
211 
214 
216  float64_t factln(int32_t n);
217 
218  protected:
219 
223  int32_t m_degree;
232  uint16_t* m_multi_index;
237  private:
238  index_t multi_index_length;
239  index_t multinomial_coefficients_length;
240  index_t normalization_values_length;
241 
243  void register_parameters();
244 };
245 }
246 #endif // _POLYFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation