|
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) 2010 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 #ifndef _SPARSEPOLYFEATURES__H__ 00011 #define _SPARSEPOLYFEATURES__H__ 00012 00013 #include "lib/common.h" 00014 #include "features/DotFeatures.h" 00015 #include "features/SparseFeatures.h" 00016 00017 namespace shogun 00018 { 00024 class CSparsePolyFeatures : public CDotFeatures 00025 { 00026 public: 00035 CSparsePolyFeatures(CSparseFeatures<float64_t>* feat, int32_t degree, bool normalize, int32_t hash_bits); 00036 00037 virtual ~CSparsePolyFeatures(); 00038 00045 CSparsePolyFeatures(const CSparsePolyFeatures & orig){ 00046 SG_PRINT("CSparsePolyFeatures:\n"); 00047 SG_NOTIMPLEMENTED;}; 00048 00053 inline virtual int32_t get_dim_feature_space() 00054 { 00055 return m_output_dimensions; 00056 } 00057 00063 virtual inline int32_t get_nnz_features_for_vector(int32_t num) 00064 { 00065 int32_t vlen; 00066 bool do_free; 00067 TSparseEntry<float64_t>* vec = m_feat->get_sparse_feature_vector(num, vlen, do_free); 00068 m_feat->free_feature_vector(vec, vlen, do_free); 00069 return vlen*(vlen+1)/2; 00070 } 00071 00076 inline virtual EFeatureType get_feature_type() 00077 { 00078 return F_UNKNOWN; 00079 } 00080 00085 inline virtual EFeatureClass get_feature_class() 00086 { 00087 return C_POLY; 00088 } 00089 00094 inline virtual int32_t get_num_vectors() 00095 { 00096 if (m_feat) 00097 return m_feat->get_num_vectors(); 00098 else 00099 return 0; 00100 00101 } 00102 00109 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2); 00110 00115 inline virtual int32_t get_size() 00116 { 00117 return sizeof(float64_t); 00118 } 00119 00121 struct sparse_poly_feature_iterator 00122 { 00124 uint16_t* vec; 00126 int32_t vidx; 00128 int32_t vlen; 00130 bool vfree; 00131 00133 int32_t index; 00134 00135 }; 00136 00146 virtual void* get_feature_iterator(int32_t vector_index) 00147 { 00148 SG_NOTIMPLEMENTED; 00149 return NULL; 00150 } 00151 00162 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator) 00163 { 00164 SG_NOTIMPLEMENTED; 00165 return NULL; 00166 } 00167 00173 virtual void free_feature_iterator(void* iterator) 00174 { 00175 SG_NOTIMPLEMENTED; 00176 } 00177 00182 CFeatures* duplicate() const; 00183 00188 inline virtual const char* get_name() const { return "SparsePolyFeatures"; } 00189 00197 virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len); 00198 00207 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00208 00209 protected: 00211 void store_normalization_values(); 00212 00213 protected: 00215 CSparseFeatures<float64_t>* m_feat; 00217 int32_t m_degree; 00219 bool m_normalize; 00221 int32_t m_input_dimensions; 00223 int32_t m_output_dimensions; 00225 float64_t* m_normalization_values; 00227 uint32_t mask; 00229 int32_t m_hash_bits; 00230 }; 00231 } 00232 #endif // _SPARSEPOLYFEATURES__H__