ImplicitWeightedSpecFeatures.h

Go to the documentation of this file.
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 Soeren Sonnenburg
00008  * Copyright (C) 2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef _IMPLICITSPECFEATURES_H___
00012 #define _IMPLICITSPECFEATURES_H___
00013 
00014 #include "lib/common.h"
00015 #include "lib/io.h"
00016 #include "features/DotFeatures.h"
00017 #include "features/StringFeatures.h"
00018 
00019 namespace shogun
00020 {
00021 
00022 template <class ST> class CStringFeatures;
00023 
00029 class CImplicitWeightedSpecFeatures : public CDotFeatures
00030 {
00031     public:
00032 
00038         CImplicitWeightedSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true);
00039 
00041         CImplicitWeightedSpecFeatures(const CImplicitWeightedSpecFeatures & orig);
00042 
00043         virtual ~CImplicitWeightedSpecFeatures();
00044 
00049         virtual CFeatures* duplicate() const;
00050 
00058         inline virtual int32_t get_dim_feature_space()
00059         {
00060             return spec_size;
00061         }
00062 
00069         virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00070 
00077         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00078 
00087         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00088 
00094         virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00095         {
00096             SG_NOTIMPLEMENTED;
00097             return 0;
00098         }
00099 
00104         inline virtual EFeatureType get_feature_type()
00105         {
00106             return F_UNKNOWN;
00107         }
00108 
00113         inline virtual EFeatureClass get_feature_class()
00114         {
00115             return C_WEIGHTEDSPEC;
00116         }
00117 
00122         inline virtual int32_t get_num_vectors()
00123         {
00124             return num_strings;
00125         }
00126 
00131         inline virtual int32_t get_size()
00132         {
00133             return sizeof(float64_t);
00134         }
00135 
00140         bool set_wd_weights();
00141 
00148         bool set_weights(float64_t* w, int32_t d);
00149 
00151         inline virtual const char* get_name() const { return "ImplicitWeightedSpecFeatures"; }
00152 
00153     protected:
00158         void compute_normalization_const();
00159 
00160     protected:
00162         CStringFeatures<uint16_t>* strings;
00163 
00165         float64_t* normalization_factors;
00167         int32_t num_strings;
00169         int32_t alphabet_size;
00170 
00172         int32_t degree;
00174         int32_t spec_size;
00175 
00177         float64_t* spec_weights;
00178 };
00179 }
00180 #endif // _IMPLICITSPECFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation