SHOGUN
v2.0.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 00013 #ifndef _COMBINEDDOTFEATURES_H___ 00014 #define _COMBINEDDOTFEATURES_H___ 00015 00016 #include <shogun/lib/common.h> 00017 #include <shogun/lib/List.h> 00018 #include <shogun/features/DotFeatures.h> 00019 00020 namespace shogun 00021 { 00022 class CFeatures; 00023 class CList; 00024 class CListElement; 00044 class CCombinedDotFeatures : public CDotFeatures 00045 { 00046 public: 00048 CCombinedDotFeatures(); 00049 00051 CCombinedDotFeatures(const CCombinedDotFeatures & orig); 00052 00054 virtual ~CCombinedDotFeatures(); 00055 00060 inline virtual int32_t get_num_vectors() const 00061 { 00062 return num_vectors; 00063 } 00064 00069 inline virtual int32_t get_dim_feature_space() const 00070 { 00071 return num_dimensions; 00072 } 00073 00081 virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df, int32_t vec_idx2); 00082 00089 virtual float64_t dense_dot(int32_t vec_idx1, float64_t* vec2, int32_t vec2_len); 00090 00102 virtual void dense_dot_range(float64_t* output, int32_t start, 00103 int32_t stop, float64_t* alphas, float64_t* vec, 00104 int32_t dim, float64_t b); 00105 00117 virtual void dense_dot_range_subset(int32_t* sub_index, int32_t num, 00118 float64_t* output, float64_t* alphas, float64_t* vec, 00119 int32_t dim, float64_t b); 00120 00129 virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, 00130 float64_t* vec2, int32_t vec2_len, bool abs_val=false); 00131 00137 virtual int32_t get_nnz_features_for_vector(int32_t num); 00138 00143 inline virtual EFeatureType get_feature_type() const 00144 { 00145 return F_DREAL; 00146 } 00147 00152 inline virtual EFeatureClass get_feature_class() const 00153 { 00154 return C_COMBINED_DOT; 00155 } 00156 00161 inline virtual int32_t get_size() const 00162 { 00163 return sizeof(float64_t); 00164 } 00165 00166 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00167 00168 struct combined_feature_iterator 00169 { 00171 CDotFeatures* f; 00173 CListElement* current; 00175 void* iterator; 00177 int32_t vector_index; 00178 }; 00179 #endif 00180 00190 virtual void* get_feature_iterator(int32_t vector_index); 00191 00202 virtual bool get_next_feature(int32_t& index, float64_t& value, void* iterator); 00203 00209 virtual void free_feature_iterator(void* iterator); 00210 00215 virtual CFeatures* duplicate() const; 00216 00218 void list_feature_objs(); 00219 00224 CDotFeatures* get_first_feature_obj(); 00225 00231 CDotFeatures* get_first_feature_obj(CListElement*& current); 00232 00237 CDotFeatures* get_next_feature_obj(); 00238 00244 CDotFeatures* get_next_feature_obj(CListElement*& current); 00245 00250 CDotFeatures* get_last_feature_obj(); 00251 00257 bool insert_feature_obj(CDotFeatures* obj); 00258 00264 bool append_feature_obj(CDotFeatures* obj); 00265 00270 bool delete_feature_obj(); 00271 00276 int32_t get_num_feature_obj(); 00277 00281 virtual SGVector<float64_t> get_subfeature_weights(); 00282 00287 virtual void set_subfeature_weights(SGVector<float64_t> weights); 00288 00290 inline virtual const char* get_name() const { return "CombinedDotFeatures"; } 00291 00292 protected: 00294 void update_dim_feature_space_and_num_vec(); 00295 00296 private: 00297 void init(); 00298 00299 protected: 00301 CList* feature_list; 00302 00304 int32_t num_vectors; 00306 int32_t num_dimensions; 00307 }; 00308 } 00309 #endif // _DOTFEATURES_H___