SHOGUN v0.9.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 _DOTFEATURES_H___ 00013 #define _DOTFEATURES_H___ 00014 00015 #include "lib/common.h" 00016 #include "lib/Time.h" 00017 #include "lib/Mathematics.h" 00018 #include "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()=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 00162 virtual void get_feature_matrix(float64_t** dst, int32_t* num_feat, int32_t* num_vec); 00163 00171 virtual void get_feature_vector(float64_t** dst, int32_t* len, int32_t num); 00172 00174 void benchmark_add_to_dense_vector(int32_t repeats=5); 00175 00177 void benchmark_dense_dot_range(int32_t repeats=5); 00178 00188 virtual void* get_feature_iterator(int32_t vector_index)=0; 00189 00200 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator)=0; 00201 00207 virtual void free_feature_iterator(void* iterator)=0; 00208 00209 protected: 00216 inline void display_progress(int32_t start, int32_t stop, int32_t v) 00217 { 00218 int32_t num_vectors=stop-start; 00219 int32_t i=v-start; 00220 00221 if ( (i% (num_vectors/100+1))== 0) 00222 SG_PROGRESS(v, 0.0, num_vectors-1); 00223 } 00224 00225 protected: 00226 00228 float64_t combined_weight; 00229 }; 00230 } 00231 #endif // _DOTFEATURES_H___