SHOGUN
v1.1.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 inline virtual int32_t get_dim_feature_space() const; 00055 00061 virtual inline int32_t get_nnz_features_for_vector(int32_t num); 00062 00067 inline virtual EFeatureType get_feature_type(); 00068 00073 inline virtual EFeatureClass get_feature_class(); 00074 00079 inline virtual int32_t get_num_vectors() const; 00080 00088 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00089 00094 inline virtual int32_t get_size(); 00095 00096 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00097 00098 struct sparse_poly_feature_iterator 00099 { 00101 uint16_t* vec; 00103 int32_t vidx; 00105 int32_t vlen; 00107 bool vfree; 00108 00110 int32_t index; 00111 }; 00112 #endif 00113 00123 virtual void* get_feature_iterator(int32_t vector_index); 00124 00135 bool get_next_feature(int32_t& index, float64_t& value, void* iterator); 00136 00142 void free_feature_iterator(void* iterator); 00143 00148 CFeatures* duplicate() const; 00149 00154 inline virtual const char* get_name() const { return "SparsePolyFeatures"; } 00155 00163 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len); 00164 00173 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00174 00175 protected: 00177 void store_normalization_values(); 00178 00179 protected: 00181 CSparseFeatures<float64_t>* m_feat; 00183 int32_t m_degree; 00185 bool m_normalize; 00187 int32_t m_input_dimensions; 00189 int32_t m_output_dimensions; 00191 float64_t* m_normalization_values; 00193 uint32_t mask; 00195 int32_t m_hash_bits; 00196 private: 00198 void init(); 00199 00200 private: 00202 int32_t m_normalization_values_len; 00203 }; 00204 } 00205 #endif // _SPARSEPOLYFEATURES__H__