Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _POLYFEATURES__H__
00011 #define _POLYFEATURES__H__
00012
00013 #include <shogun/lib/common.h>
00014 #include <shogun/features/DotFeatures.h>
00015 #include <shogun/features/DenseFeatures.h>
00016
00017
00018 namespace shogun
00019 {
00025 class CPolyFeatures : public CDotFeatures
00026 {
00027 public:
00029 CPolyFeatures();
00030
00037 CPolyFeatures(CDenseFeatures<float64_t>* feat, int32_t degree, bool normalize);
00038
00039 virtual ~CPolyFeatures();
00040
00047 CPolyFeatures(const CPolyFeatures & orig);
00048
00053 virtual int32_t get_dim_feature_space() const;
00054
00060 virtual int32_t get_nnz_features_for_vector(int32_t num);
00061
00066 virtual EFeatureType get_feature_type() const;
00067
00072 virtual EFeatureClass get_feature_class() const;
00073
00078 virtual int32_t get_num_vectors() const;
00079
00087 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00088
00093 virtual int32_t get_size() const;
00094
00099 CFeatures* duplicate() const;
00100
00105 virtual const char* get_name() const { return "PolyFeatures"; }
00106
00114 float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00115
00124 void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
00125
00126 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00127
00128 struct poly_feature_iterator
00129 {
00131 uint16_t* vec;
00133 int32_t vidx;
00135 int32_t vlen;
00137 bool vfree;
00138
00140 int32_t index;
00141
00142 };
00143 #endif
00144
00154 virtual void* get_feature_iterator(int32_t vector_index);
00155
00166 virtual bool get_next_feature(int32_t& index, float64_t& value,
00167 void* iterator);
00168
00174 virtual void free_feature_iterator(void* iterator);
00175
00176 protected:
00177
00179 void store_normalization_values();
00180
00182 void store_multi_index();
00183
00186 void enumerate_multi_index(const int32_t feat_idx, uint16_t** index,
00187 uint16_t* exponents, const int32_t degree);
00190 void store_multinomial_coefficients();
00191
00195 int32_t bico2(int32_t n, int32_t k);
00196
00199 int32_t bico(int32_t n, int32_t k);
00200
00207 int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
00208
00210 int32_t multinomialcoef(int32_t* exps, int32_t len);
00211
00213 float64_t gammln(float64_t xx);
00214
00216 float64_t factln(int32_t n);
00217
00218 protected:
00219
00221 CDenseFeatures<float64_t>* m_feat;
00223 int32_t m_degree;
00225 bool m_normalize;
00227 int32_t m_input_dimensions;
00229 int32_t m_output_dimensions;
00232 uint16_t* m_multi_index;
00234 float64_t* m_multinomial_coefficients;
00236 float32_t* m_normalization_values;
00237 private:
00238 index_t multi_index_length;
00239 index_t multinomial_coefficients_length;
00240 index_t normalization_values_length;
00241
00243 void register_parameters();
00244 };
00245 }
00246 #endif // _POLYFEATURES__H__