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/SimpleFeatures.h>
00016
00017
00018 namespace shogun
00019 {
00025 class CPolyFeatures : public CDotFeatures
00026 {
00027 public:
00029 CPolyFeatures(void);
00030
00037 CPolyFeatures(CSimpleFeatures<float64_t>* feat, int32_t degree, bool normalize);
00038
00039 virtual ~CPolyFeatures();
00040
00047 CPolyFeatures(const CPolyFeatures & orig){
00048 SG_PRINT("CPolyFeatures:\n");
00049 SG_NOTIMPLEMENTED;};
00050
00055 inline virtual int32_t get_dim_feature_space() const
00056 {
00057 return m_output_dimensions;
00058 }
00059
00065 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00066 {
00067 return m_output_dimensions;
00068 }
00069
00074 inline virtual EFeatureType get_feature_type()
00075 {
00076 return F_UNKNOWN;
00077 }
00078
00083 inline virtual EFeatureClass get_feature_class()
00084 {
00085 return C_POLY;
00086 }
00087
00092 inline virtual int32_t get_num_vectors() const
00093 {
00094 if (m_feat)
00095 return m_feat->get_num_vectors();
00096 else
00097 return 0;
00098
00099 }
00100
00108 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00109
00114 inline virtual int32_t get_size()
00115 {
00116 return sizeof(float64_t);
00117 }
00118
00123 CFeatures* duplicate() const;
00124
00129 inline virtual const char* get_name() const { return "PolyFeatures"; }
00130
00138 float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00139
00148 void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val);
00149
00150 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00151
00152 struct poly_feature_iterator
00153 {
00155 uint16_t* vec;
00157 int32_t vidx;
00159 int32_t vlen;
00161 bool vfree;
00162
00164 int32_t index;
00165
00166 };
00167 #endif
00168
00178 virtual void* get_feature_iterator(int32_t vector_index)
00179 {
00180 SG_NOTIMPLEMENTED;
00181 return NULL;
00182 }
00183
00194 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)
00195 {
00196 SG_NOTIMPLEMENTED;
00197 return NULL;
00198 }
00199
00205 virtual void free_feature_iterator(void* iterator)
00206 {
00207 SG_NOTIMPLEMENTED;
00208 }
00209
00210 protected:
00211
00213 void store_normalization_values();
00214
00216 void store_multi_index();
00217
00220 void enumerate_multi_index(const int32_t feat_idx, uint16_t** index, uint16_t* exponents, const int32_t degree);
00223 void store_multinomial_coefficients();
00224
00228 int32_t bico2(int32_t n, int32_t k);
00229
00232 int32_t bico(int32_t n, int32_t k);
00233
00240 int32_t calc_feature_space_dimensions(int32_t N, int32_t D);
00241
00243 int32_t multinomialcoef(int32_t* exps, int32_t len);
00244
00246 float64_t gammln(float64_t xx);
00247
00249 float64_t factln(int32_t n);
00250
00251 protected:
00252
00254 CSimpleFeatures<float64_t>* m_feat;
00256 int32_t m_degree;
00258 bool m_normalize;
00260 int32_t m_input_dimensions;
00262 int32_t m_output_dimensions;
00265 uint16_t* m_multi_index;
00267 float64_t* m_multinomial_coefficients;
00269 float32_t* m_normalization_values;
00270 private:
00271 index_t multi_index_length;
00272 index_t multinomial_coefficients_length;
00273 index_t normalization_values_length;
00274
00276 void register_parameters();
00277
00278 };
00279 }
00280 #endif // _POLYFEATURES__H__