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 00011 #ifndef _HASHEDWDFEATURESTRANSPOSED_H___ 00012 #define _HASHEDWDFEATURESTRANSPOSED_H___ 00013 00014 #include "lib/common.h" 00015 #include "features/DotFeatures.h" 00016 #include "features/StringFeatures.h" 00017 #include "lib/Hash.h" 00018 00019 namespace shogun 00020 { 00021 template <class ST> class CStringFeatures; 00022 00028 class CHashedWDFeaturesTransposed : public CDotFeatures 00029 { 00030 public: 00032 CHashedWDFeaturesTransposed(void); 00033 00042 CHashedWDFeaturesTransposed(CStringFeatures<uint8_t>* str, int32_t start_order, 00043 int32_t order, int32_t from_order, int32_t hash_bits=12); 00044 00046 CHashedWDFeaturesTransposed(const CHashedWDFeaturesTransposed & orig); 00047 00049 virtual ~CHashedWDFeaturesTransposed(); 00050 00058 inline virtual int32_t get_dim_feature_space() 00059 { 00060 return w_dim; 00061 } 00062 00070 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00071 00078 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len); 00079 00091 virtual void dense_dot_range(float64_t* output, int32_t start, int32_t stop, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b); 00092 00104 virtual void dense_dot_range_subset(int32_t* sub_index, int32_t num, float64_t* output, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b); 00105 00106 00115 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00116 00122 virtual inline int32_t get_nnz_features_for_vector(int32_t num) 00123 { 00124 return w_dim/alphabet_size; 00125 } 00126 00131 virtual CFeatures* duplicate() const; 00132 00137 inline virtual EFeatureType get_feature_type() 00138 { 00139 return F_UNKNOWN; 00140 } 00141 00146 inline virtual EFeatureClass get_feature_class() 00147 { 00148 return C_WD; 00149 } 00150 00151 inline virtual int32_t get_num_vectors() 00152 { 00153 return num_strings; 00154 } 00155 00156 inline virtual int32_t get_size() 00157 { 00158 return sizeof(float64_t); 00159 } 00160 00163 void set_normalization_const(float64_t n=0); 00164 00166 inline float64_t get_normalization_const() 00167 { 00168 return normalization_const; 00169 } 00170 00172 struct hashed_wd_transposed_feature_iterator 00173 { 00175 uint16_t* vec; 00177 int32_t vidx; 00179 int32_t vlen; 00181 bool vfree; 00182 00184 int32_t index; 00185 00186 }; 00187 00197 virtual void* get_feature_iterator(int32_t vector_index) 00198 { 00199 SG_NOTIMPLEMENTED; 00200 return NULL; 00201 } 00202 00213 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator) 00214 { 00215 SG_NOTIMPLEMENTED; 00216 return NULL; 00217 } 00218 00224 virtual void free_feature_iterator(void* iterator) 00225 { 00226 SG_NOTIMPLEMENTED; 00227 } 00228 00230 inline virtual const char* get_name() const { return "HashedWDFeaturesTransposed"; } 00231 00232 protected: 00233 00235 void set_wd_weights(); 00236 static void* dense_dot_range_helper(void* p); 00237 00238 protected: 00240 CStringFeatures<uint8_t>* strings; 00241 00243 TString<uint8_t>* transposed_strings; 00244 00246 int32_t degree; 00248 int32_t start_degree; 00250 int32_t from_degree; 00252 int32_t string_length; 00254 int32_t num_strings; 00256 int32_t alphabet_size; 00258 int32_t w_dim; 00260 int32_t partial_w_dim; 00262 float64_t* wd_weights; 00264 uint32_t mask; 00266 int32_t m_hash_bits; 00267 00269 float64_t normalization_const; 00270 }; 00271 } 00272 #endif // _HASHEDWDFEATURESTRANSPOSED_H___