SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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/config.h>
14 
15 #include <shogun/lib/common.h>
18 
19 
20 namespace shogun
21 {
28 {
29  public:
31  CPolyFeatures();
32 
39  CPolyFeatures(CDenseFeatures<float64_t>* feat, int32_t degree, bool normalize);
40 
41  virtual ~CPolyFeatures();
42 
49  CPolyFeatures(const CPolyFeatures & orig);
50 
55  virtual int32_t get_dim_feature_space() const;
56 
62  virtual int32_t get_nnz_features_for_vector(int32_t num);
63 
68  virtual EFeatureType get_feature_type() const;
69 
74  virtual EFeatureClass get_feature_class() const;
75 
80  virtual int32_t get_num_vectors() const;
81 
89  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
90 
95  CFeatures* duplicate() const;
96 
101  virtual const char* get_name() const { return "PolyFeatures"; }
102 
110  float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
111 
120  void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
121 
122  #ifndef DOXYGEN_SHOULD_SKIP_THIS
123 
124  struct poly_feature_iterator
125  {
127  uint16_t* vec;
129  int32_t vidx;
131  int32_t vlen;
133  bool vfree;
134 
136  int32_t index;
137 
138  };
139  #endif
140 
150  virtual void* get_feature_iterator(int32_t vector_index);
151 
162  virtual bool get_next_feature(int32_t& index, float64_t& value,
163  void* iterator);
164 
170  virtual void free_feature_iterator(void* iterator);
171 
172  protected:
173 
176 
178  void store_multi_index();
179 
182  void enumerate_multi_index(const int32_t feat_idx, uint16_t** index,
183  uint16_t* exponents, const int32_t degree);
187 
191  int32_t bico2(int32_t n, int32_t k);
192 
195  int32_t bico(int32_t n, int32_t k);
196 
203  int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
204 
206  int32_t multinomialcoef(int32_t* exps, int32_t len);
207 
210 
212  float64_t factln(int32_t n);
213 
214  protected:
215 
219  int32_t m_degree;
228  uint16_t* m_multi_index;
233  private:
234  index_t multi_index_length;
235  index_t multinomial_coefficients_length;
236  index_t normalization_values_length;
237 
239  void register_parameters();
240 };
241 }
242 #endif // _POLYFEATURES__H__
virtual EFeatureType get_feature_type() const
virtual const char * get_name() const
Definition: PolyFeatures.h:101
virtual int32_t get_dim_feature_space() const
int32_t index_t
Definition: common.h:62
int32_t bico2(int32_t n, int32_t k)
int32_t bico(int32_t n, int32_t k)
void store_multinomial_coefficients()
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
virtual void free_feature_iterator(void *iterator)
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
uint16_t * m_multi_index
Definition: PolyFeatures.h:228
Features that support dot products among other operations.
Definition: DotFeatures.h:44
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:38
float32_t * m_normalization_values
Definition: PolyFeatures.h:232
void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val)
CFeatures * duplicate() const
void enumerate_multi_index(const int32_t feat_idx, uint16_t **index, uint16_t *exponents, const int32_t degree)
double float64_t
Definition: common.h:50
float64_t * m_multinomial_coefficients
Definition: PolyFeatures.h:230
CDenseFeatures< float64_t > * m_feat
Definition: PolyFeatures.h:217
virtual int32_t get_nnz_features_for_vector(int32_t num)
float64_t factln(int32_t n)
virtual void * get_feature_iterator(int32_t vector_index)
float float32_t
Definition: common.h:49
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
virtual int32_t get_num_vectors() const
float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
int32_t calc_feature_space_dimensions(int32_t N, int32_t D)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
float64_t gammln(float64_t xx)
virtual EFeatureClass get_feature_class() const
implement DotFeatures for the polynomial kernel
Definition: PolyFeatures.h:27
int32_t multinomialcoef(int32_t *exps, int32_t len)

SHOGUN Machine Learning Toolbox - Documentation