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 template <class ST> class CStringFeatures;
00020 
00026 class CImplicitWeightedSpecFeatures : public CDotFeatures
00027 {
00028     public:
00029 
00035         CImplicitWeightedSpecFeatures(CStringFeatures<uint16_t>* str, bool normalize=true);
00036 
00038         CImplicitWeightedSpecFeatures(const CImplicitWeightedSpecFeatures & orig);
00039 
00040         virtual ~CImplicitWeightedSpecFeatures();
00041 
00046         virtual CFeatures* duplicate() const;
00047 
00055         inline virtual int32_t get_dim_feature_space()
00056         {
00057             return spec_size;
00058         }
00059 
00066         virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2);
00067 
00074         virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len);
00075 
00084         virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
00085 
00091         virtual inline int32_t get_nnz_features_for_vector(int32_t num)
00092         {
00093             SG_NOTIMPLEMENTED;
00094             return 0;
00095         }
00096 
00101         inline virtual EFeatureType get_feature_type()
00102         {
00103             return F_UNKNOWN;
00104         }
00105 
00110         inline virtual EFeatureClass get_feature_class()
00111         {
00112             return C_WEIGHTEDSPEC;
00113         }
00114 
00119         inline virtual int32_t get_num_vectors()
00120         {
00121             return num_strings;
00122         }
00123 
00128         inline virtual int32_t get_size()
00129         {
00130             return sizeof(float64_t);
00131         }
00132 
00137         bool set_wd_weights();
00138 
00145         bool set_weights(float64_t* w, int32_t d);
00146 
00148         inline virtual const char* get_name() const { return "ImplicitWeightedSpecFeatures"; }
00149 
00150     protected:
00155         void compute_normalization_const();
00156 
00157     protected:
00159         CStringFeatures<uint16_t>* strings;
00160 
00162         float64_t* normalization_factors;
00164         int32_t num_strings;
00166         int32_t alphabet_size;
00167 
00169         int32_t degree;
00171         int32_t spec_size;
00172 
00174         float64_t* spec_weights;
00175 };
00176 #endif // _IMPLICITSPECFEATURES_H___

SHOGUN Machine Learning Toolbox - Documentation