PolyFeatures.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "lib/common.h"
00012 #include "features/DotFeatures.h"
00013 #include "features/SimpleFeatures.h"
00014
00015
00016 namespace shogun
00017 {
00023 class CPolyFeatures : public CDotFeatures
00024 {
00025 public:
00032 CPolyFeatures(CSimpleFeatures<float64_t>* feat, int32_t degree, bool normalize);
00033
00034 virtual ~CPolyFeatures();
00035
00042 CPolyFeatures(const CPolyFeatures & orig){
00043 SG_PRINT("CPolyFeatures:\n");
00044 SG_NOTIMPLEMENTED;};
00045
00050 inline virtual int32_t get_dim_feature_space()
00051 {
00052 return m_output_dimensions;
00053 }
00054
00060 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00061 {
00062 return m_output_dimensions;
00063 }
00064
00069 inline virtual EFeatureType get_feature_type()
00070 {
00071 return F_UNKNOWN;
00072 }
00073
00078 inline virtual EFeatureClass get_feature_class()
00079 {
00080 return C_POLY;
00081 }
00082
00087 inline virtual int32_t get_num_vectors()
00088 {
00089 if (m_feat)
00090 return m_feat->get_num_vectors();
00091 else
00092 return 0;
00093
00094 }
00095
00102 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00103
00108 inline virtual int32_t get_size()
00109 {
00110 return sizeof(float64_t);
00111 }
00112
00117 CFeatures* duplicate() const;
00118
00123 inline virtual const char* get_name() const { return "PolyFeatures"; }
00124
00132 float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00133
00142 void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
00143
00144 protected:
00145
00147 void store_normalization_values();
00148
00150 void store_multi_index();
00151
00154 void enumerate_multi_index(const int32_t feat_idx, uint16_t** index, uint16_t* exponents, const int32_t degree);
00157 void store_multinomial_coefficients();
00158
00162 int32_t bico2(int32_t n, int32_t k);
00163
00166 int32_t bico(int32_t n, int32_t k);
00167
00174 int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
00175
00177 int32_t multinomialcoef(int32_t* exps, int32_t len);
00178
00180 float64_t gammln(float64_t xx);
00181
00183 float64_t factln(int32_t n);
00184
00185 protected:
00186
00188 CSimpleFeatures<float64_t>* m_feat;
00190 int32_t m_degree;
00192 bool m_normalize;
00194 int32_t m_input_dimensions;
00196 int32_t m_output_dimensions;
00199 uint16_t* m_multi_index;
00201 float64_t* m_multinomial_coefficients;
00203 float32_t* m_normalization_values;
00204
00205 };
00206 }