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) 2009-2010 Soeren Sonnenburg 00008 * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 * Copyright (C) 2010 Berlin Institute of Technology 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(); 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 virtual int32_t get_dim_feature_space() const; 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, float64_t* vec2, int32_t vec2_len); 00079 00088 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, 00089 float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00090 00096 virtual int32_t get_nnz_features_for_vector(int32_t num); 00097 00102 virtual EFeatureType get_feature_type() const; 00103 00108 virtual EFeatureClass get_feature_class() const; 00109 00114 virtual int32_t get_num_vectors() const; 00115 00120 bool set_wd_weights(); 00121 00128 bool set_weights(float64_t* w, int32_t d); 00129 00130 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00131 00132 struct wspec_feature_iterator 00133 { 00135 uint16_t* vec; 00137 int32_t vidx; 00139 int32_t vlen; 00141 bool vfree; 00142 00147 int32_t offs; 00148 int32_t d; 00149 int32_t j; 00150 uint8_t mask; 00151 float64_t alpha; 00153 }; 00154 #endif 00155 00165 virtual void* get_feature_iterator(int32_t vector_index); 00166 00177 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator); 00178 00184 virtual void free_feature_iterator(void* iterator); 00185 00187 virtual const char* get_name() const { return "ImplicitWeightedSpecFeatures"; } 00188 00189 protected: 00194 void compute_normalization_const(); 00195 00196 protected: 00198 CStringFeatures<uint16_t>* strings; 00199 00201 float64_t* normalization_factors; 00203 int32_t num_strings; 00205 int32_t alphabet_size; 00206 00208 int32_t degree; 00210 int32_t spec_size; 00211 00213 float64_t* spec_weights; 00214 }; 00215 } 00216 #endif // _IMPLICITSPECFEATURES_H___