DotFeatures.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _DOTFEATURES_H___
00012 #define _DOTFEATURES_H___
00013
00014 #include "lib/common.h"
00015 #include "features/Features.h"
00016
00017 namespace shogun
00018 {
00038 class CDotFeatures : public CFeatures
00039 {
00040 public:
00041
00046 CDotFeatures(int32_t size=0) : CFeatures(size), combined_weight(1.0)
00047 {
00048 set_property(FP_DOT);
00049 }
00050
00052 CDotFeatures(const CDotFeatures & orig) :
00053 CFeatures(orig), combined_weight(orig.combined_weight) {}
00054
00059 CDotFeatures(char* fname) : CFeatures(fname) {}
00060
00061 virtual ~CDotFeatures() { }
00062
00070 virtual int32_t get_dim_feature_space()=0;
00071
00078 virtual float64_t dot(int32_t vec_idx1, int32_t vec_idx2)=0;
00079
00086 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len)=0;
00087
00096 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t* vec2, int32_t vec2_len, bool abs_val=false)=0;
00097
00109 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);
00110
00111
00114 static void* dense_dot_range_helper(void* p);
00115
00123 virtual int32_t get_nnz_features_for_vector(int32_t num)=0;
00124
00129 inline float64_t get_combined_feature_weight() { return combined_weight; }
00130
00135 inline void set_combined_feature_weight(float64_t nw) { combined_weight=nw; }
00136
00144 virtual void get_feature_matrix(float64_t** dst, int32_t* num_feat, int32_t* num_vec);
00145
00146 protected:
00153 inline void display_progress(int32_t start, int32_t stop, int32_t v)
00154 {
00155 int32_t num_vectors=stop-start;
00156 int32_t i=v-start;
00157
00158 if ( (i% (num_vectors/100+1))== 0)
00159 SG_PROGRESS(v, 0.0, num_vectors-1);
00160 }
00161
00162 #ifdef HAVE_BOOST_SERIALIZATION
00163 friend class ::boost::serialization::access;
00164
00165
00166
00167 template<class Archive>
00168 void serialize(Archive & ar, const unsigned int archive_version)
00169 {
00170
00171 SG_DEBUG("archiving DotFeatures\n");
00172
00173 ar & ::boost::serialization::base_object<CFeatures>(*this);
00174 ar & combined_weight;
00175
00176 SG_DEBUG("done with DotFeatures\n");
00177 }
00178
00179 #endif //HAVE_BOOST_SERIALIZATION
00180
00181 protected:
00182
00184 float64_t combined_weight;
00185 };
00186 }
00187 #endif // _DOTFEATURES_H___