|
SHOGUN v0.9.3
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2009 Jonas Behr 00008 * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 #ifndef _POLYFEATURES__H__ 00011 #define _POLYFEATURES__H__ 00012 00013 #include "lib/common.h" 00014 #include "features/DotFeatures.h" 00015 #include "features/SimpleFeatures.h" 00016 00017 00018 namespace shogun 00019 { 00025 class CPolyFeatures : public CDotFeatures 00026 { 00027 public: 00034 CPolyFeatures(CSimpleFeatures<float64_t>* feat, int32_t degree, bool normalize); 00035 00036 virtual ~CPolyFeatures(); 00037 00044 CPolyFeatures(const CPolyFeatures & orig){ 00045 SG_PRINT("CPolyFeatures:\n"); 00046 SG_NOTIMPLEMENTED;}; 00047 00052 inline virtual int32_t get_dim_feature_space() 00053 { 00054 return m_output_dimensions; 00055 } 00056 00062 virtual inline int32_t get_nnz_features_for_vector(int32_t num) 00063 { 00064 return m_output_dimensions; 00065 } 00066 00071 inline virtual EFeatureType get_feature_type() 00072 { 00073 return F_UNKNOWN; 00074 } 00075 00080 inline virtual EFeatureClass get_feature_class() 00081 { 00082 return C_POLY; 00083 } 00084 00089 inline virtual int32_t get_num_vectors() 00090 { 00091 if (m_feat) 00092 return m_feat->get_num_vectors(); 00093 else 00094 return 0; 00095 00096 } 00097 00104 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2); 00105 00110 inline virtual int32_t get_size() 00111 { 00112 return sizeof(float64_t); 00113 } 00114 00119 CFeatures* duplicate() const; 00120 00125 inline virtual const char* get_name() const { return "PolyFeatures"; } 00126 00134 float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len); 00135 00144 void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val); 00145 00147 struct poly_feature_iterator 00148 { 00150 uint16_t* vec; 00152 int32_t vidx; 00154 int32_t vlen; 00156 bool vfree; 00157 00159 int32_t index; 00160 00161 }; 00162 00172 virtual void* get_feature_iterator(int32_t vector_index) 00173 { 00174 SG_NOTIMPLEMENTED; 00175 return NULL; 00176 } 00177 00188 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator) 00189 { 00190 SG_NOTIMPLEMENTED; 00191 return NULL; 00192 } 00193 00199 virtual void free_feature_iterator(void* iterator) 00200 { 00201 SG_NOTIMPLEMENTED; 00202 } 00203 00204 protected: 00205 00207 void store_normalization_values(); 00208 00210 void store_multi_index(); 00211 00214 void enumerate_multi_index(const int32_t feat_idx, uint16_t** index, uint16_t* exponents, const int32_t degree); 00217 void store_multinomial_coefficients(); 00218 00222 int32_t bico2(int32_t n, int32_t k); 00223 00226 int32_t bico(int32_t n, int32_t k); 00227 00234 int32_t calc_feature_space_dimensions(int32_t N, int32_t D); 00235 00237 int32_t multinomialcoef(int32_t* exps, int32_t len); 00238 00240 float64_t gammln(float64_t xx); 00241 00243 float64_t factln(int32_t n); 00244 00245 protected: 00246 00248 CSimpleFeatures<float64_t>* m_feat; 00250 int32_t m_degree; 00252 bool m_normalize; 00254 int32_t m_input_dimensions; 00256 int32_t m_output_dimensions; 00259 uint16_t* m_multi_index; 00261 float64_t* m_multinomial_coefficients; 00263 float32_t* m_normalization_values; 00264 00265 }; 00266 } 00267 #endif // _POLYFEATURES__H__