Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _DOTFEATURES_H___
00013 #define _DOTFEATURES_H___
00014
00015 #include <shogun/lib/common.h>
00016 #include <shogun/lib/Time.h>
00017 #include <shogun/mathematics/Math.h>
00018 #include <shogun/features/Features.h>
00019
00020 namespace shogun
00021 {
00043 class CDotFeatures : public CFeatures
00044 {
00045 void init(void);
00046
00047 public:
00048
00053 CDotFeatures(int32_t size=0);
00054
00056 CDotFeatures(const CDotFeatures & orig);
00057
00062 CDotFeatures(CFile* loader);
00063
00064 virtual ~CDotFeatures() { }
00065
00073 virtual int32_t get_dim_feature_space() const=0;
00074
00082 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2)=0;
00083
00090 virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2, int32_t vec2_len)=0;
00091
00100 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;
00101
00115 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);
00116
00128 virtual void dense_dot_range_subset(int32_t* sub_index, int32_t num, float64_t* output, float64_t* alphas, float64_t* vec, int32_t dim, float64_t b);
00129
00132 static void* dense_dot_range_helper(void* p);
00133
00141 virtual int32_t get_nnz_features_for_vector(int32_t num)=0;
00142
00147 inline float64_t get_combined_feature_weight() { return combined_weight; }
00148
00153 inline void set_combined_feature_weight(float64_t nw) { combined_weight=nw; }
00154
00159 SGMatrix<float64_t> get_computed_dot_feature_matrix();
00160
00165 SGVector<float64_t> get_computed_dot_feature_vector(int32_t num);
00166
00168 void benchmark_add_to_dense_vector(int32_t repeats=5);
00169
00171 void benchmark_dense_dot_range(int32_t repeats=5);
00172
00182 virtual void* get_feature_iterator(int32_t vector_index)=0;
00183
00194 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)=0;
00195
00201 virtual void free_feature_iterator(void* iterator)=0;
00202
00207 virtual SGVector<float64_t> get_mean();
00208
00213 virtual SGMatrix<float64_t> get_cov();
00214
00215 protected:
00222 inline void display_progress(int32_t start, int32_t stop, int32_t v)
00223 {
00224 int32_t num_vectors=stop-start;
00225 int32_t i=v-start;
00226
00227 if ( (i% (num_vectors/100+1))== 0)
00228 SG_PROGRESS(v, 0.0, num_vectors-1);
00229 }
00230
00231 protected:
00232
00234 float64_t combined_weight;
00235 };
00236 }
00237 #endif // _DOTFEATURES_H___