Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _IMPLICITSPECFEATURES_H___
00013 #define _IMPLICITSPECFEATURES_H___
00014
00015 #include <shogun/lib/common.h>
00016 #include <shogun/io/SGIO.h>
00017 #include <shogun/features/DotFeatures.h>
00018 #include <shogun/features/StringFeatures.h>
00019
00020 namespace shogun
00021 {
00022
00023 template <class ST> class CStringFeatures;
00024
00030 class CImplicitWeightedSpecFeatures : public CDotFeatures
00031 {
00032 public:
00034 CImplicitWeightedSpecFeatures(void);
00035
00041 CImplicitWeightedSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true);
00042
00044 CImplicitWeightedSpecFeatures(const CImplicitWeightedSpecFeatures & orig);
00045
00046 virtual ~CImplicitWeightedSpecFeatures();
00047
00052 virtual CFeatures* duplicate() const;
00053
00061 inline virtual int32_t get_dim_feature_space() const
00062 {
00063 return spec_size;
00064 }
00065
00073 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2);
00074
00081 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00082
00091 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00092
00098 virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00099 {
00100 int32_t vlen=-1;
00101 bool free_vec;
00102 uint16_t* vec1=strings->get_feature_vector(num, vlen, free_vec);
00103 strings->free_feature_vector(vec1, num, free_vec);
00104 int32_t nnz=0;
00105 for (int32_t i=1; i<=degree; i++)
00106 nnz+=CMath::min(CMath::pow(alphabet_size,i), vlen);
00107 return nnz;
00108 }
00109
00114 inline virtual EFeatureType get_feature_type()
00115 {
00116 return F_UNKNOWN;
00117 }
00118
00123 inline virtual EFeatureClass get_feature_class()
00124 {
00125 return C_WEIGHTEDSPEC;
00126 }
00127
00132 inline virtual int32_t get_num_vectors() const
00133 {
00134 return num_strings;
00135 }
00136
00141 inline virtual int32_t get_size()
00142 {
00143 return sizeof(float64_t);
00144 }
00145
00150 bool set_wd_weights();
00151
00158 bool set_weights(float64_t* w, int32_t d);
00159
00160 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00161
00162 struct wspec_feature_iterator
00163 {
00165 uint16_t* vec;
00167 int32_t vidx;
00169 int32_t vlen;
00171 bool vfree;
00172
00177 int32_t offs;
00178 int32_t d;
00179 int32_t j;
00180 uint8_t mask;
00181 float64_t alpha;
00183 };
00184 #endif
00185
00195 virtual void* get_feature_iterator(int32_t vector_index);
00196
00207 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator);
00208
00214 virtual void free_feature_iterator(void* iterator);
00215
00217 inline virtual const char* get_name() const { return "ImplicitWeightedSpecFeatures"; }
00218
00219 protected:
00224 void compute_normalization_const();
00225
00226 protected:
00228 CStringFeatures<uint16_t>* strings;
00229
00231 float64_t* normalization_factors;
00233 int32_t num_strings;
00235 int32_t alphabet_size;
00236
00238 int32_t degree;
00240 int32_t spec_size;
00241
00243 float64_t* spec_weights;
00244 };
00245 }
00246 #endif // _IMPLICITSPECFEATURES_H___