SHOGUN
v3.2.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 <shogun/lib/common.h> 00014 #include <shogun/features/DotFeatures.h> 00015 #include <shogun/features/SparseFeatures.h> 00016 00017 namespace shogun 00018 { 00024 class CSparsePolyFeatures : public CDotFeatures 00025 { 00026 public: 00028 CSparsePolyFeatures(); 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 00054 virtual int32_t get_dim_feature_space() const; 00055 00061 virtual int32_t get_nnz_features_for_vector(int32_t num); 00062 00067 virtual EFeatureType get_feature_type() const; 00068 00073 virtual EFeatureClass get_feature_class() const; 00074 00079 virtual int32_t get_num_vectors() const; 00080 00088 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00089 00090 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00091 00092 struct sparse_poly_feature_iterator 00093 { 00095 uint16_t* vec; 00097 int32_t vidx; 00099 int32_t vlen; 00101 bool vfree; 00102 00104 int32_t index; 00105 }; 00106 #endif 00107 00117 virtual void* get_feature_iterator(int32_t vector_index); 00118 00129 bool get_next_feature(int32_t& index, float64_t& value, void* iterator); 00130 00136 void free_feature_iterator(void* iterator); 00137 00142 CFeatures* duplicate() const; 00143 00148 virtual const char* get_name() const { return "SparsePolyFeatures"; } 00149 00157 virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len); 00158 00167 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00168 00169 protected: 00171 void store_normalization_values(); 00172 00173 protected: 00175 CSparseFeatures<float64_t>* m_feat; 00177 int32_t m_degree; 00179 bool m_normalize; 00181 int32_t m_input_dimensions; 00183 int32_t m_output_dimensions; 00185 float64_t* m_normalization_values; 00187 uint32_t mask; 00189 int32_t m_hash_bits; 00190 private: 00192 void init(); 00193 00194 private: 00196 int32_t m_normalization_values_len; 00197 }; 00198 } 00199 #endif // _SPARSEPOLYFEATURES__H__