SHOGUN v0.9.0
|
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: 00028 CSparsePolyFeatures(void); 00029 00038 CSparsePolyFeatures(CSparseFeatures<float64_t>* feat, int32_t degree, bool normalize, int32_t hash_bits); 00039 00040 virtual ~CSparsePolyFeatures(); 00041 00048 CSparsePolyFeatures(const CSparsePolyFeatures & orig){ 00049 SG_PRINT("CSparsePolyFeatures:\n"); 00050 SG_NOTIMPLEMENTED;}; 00051 00056 inline virtual int32_t get_dim_feature_space() 00057 { 00058 return m_output_dimensions; 00059 } 00060 00066 virtual inline int32_t get_nnz_features_for_vector(int32_t num) 00067 { 00068 int32_t vlen; 00069 bool do_free; 00070 TSparseEntry<float64_t>* vec = m_feat->get_sparse_feature_vector(num, vlen, do_free); 00071 m_feat->free_feature_vector(vec, vlen, do_free); 00072 return vlen*(vlen+1)/2; 00073 } 00074 00079 inline virtual EFeatureType get_feature_type() 00080 { 00081 return F_UNKNOWN; 00082 } 00083 00088 inline virtual EFeatureClass get_feature_class() 00089 { 00090 return C_POLY; 00091 } 00092 00097 inline virtual int32_t get_num_vectors() 00098 { 00099 if (m_feat) 00100 return m_feat->get_num_vectors(); 00101 else 00102 return 0; 00103 00104 } 00105 00113 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00114 00119 inline virtual int32_t get_size() 00120 { 00121 return sizeof(float64_t); 00122 } 00123 00125 struct sparse_poly_feature_iterator 00126 { 00128 uint16_t* vec; 00130 int32_t vidx; 00132 int32_t vlen; 00134 bool vfree; 00135 00137 int32_t index; 00138 00139 }; 00140 00150 virtual void* get_feature_iterator(int32_t vector_index) 00151 { 00152 SG_NOTIMPLEMENTED; 00153 return NULL; 00154 } 00155 00166 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator) 00167 { 00168 SG_NOTIMPLEMENTED; 00169 return NULL; 00170 } 00171 00177 virtual void free_feature_iterator(void* iterator) 00178 { 00179 SG_NOTIMPLEMENTED; 00180 } 00181 00186 CFeatures* duplicate() const; 00187 00192 inline virtual const char* get_name() const { return "SparsePolyFeatures"; } 00193 00201 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len); 00202 00211 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00212 00213 protected: 00215 void store_normalization_values(); 00216 00217 protected: 00219 CSparseFeatures<float64_t>* m_feat; 00221 int32_t m_degree; 00223 bool m_normalize; 00225 int32_t m_input_dimensions; 00227 int32_t m_output_dimensions; 00229 float64_t* m_normalization_values; 00231 uint32_t mask; 00233 int32_t m_hash_bits; 00234 }; 00235 } 00236 #endif // _SPARSEPOLYFEATURES__H__