SHOGUN  v3.0.1
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
HashedSparseFeatures.h
浏览该文件的文档.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2013 Evangelos Anagnostopoulos
8  * Copyright (C) 2013 Evangelos Anagnostopoulos
9  */
10 
11 #ifndef _HASHED_SPARSEFEATURES_H__
12 #define _HASHED_SPARSEFEATURES_H__
13 
17 
18 namespace shogun
19 {
20 template <class ST> class CSparseFeatures;
21 template <class ST> class SGSparseVector;
22 class CDotFeatures;
23 
27 template <class ST> class CHashedSparseFeatures : public CDotFeatures
28 {
29 public:
30 
37  CHashedSparseFeatures(int32_t size=0, bool use_quadr = false, bool keep_lin_terms = true);
38 
46  CHashedSparseFeatures(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr = false,
47  bool keep_lin_terms = true);
48 
56  CHashedSparseFeatures(SGSparseMatrix<ST> matrix, int32_t d, bool use_quadr = false,
57  bool keep_lin_terms = true);
58 
66  CHashedSparseFeatures(CFile* loader, int32_t d, bool use_quadr = false,
67  bool keep_lin_terms = true);
68 
71 
73  virtual CFeatures* duplicate() const;
74 
76  virtual ~CHashedSparseFeatures();
77 
85  virtual int32_t get_dim_feature_space() const;
86 
96  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
97  int32_t vec_idx2);
98 
107  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
108  int32_t vec2_len);
109 
120  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
121  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
122 
128  virtual int32_t get_nnz_features_for_vector(int32_t num);
129 
141  virtual void* get_feature_iterator(int32_t vector_index);
142 
155  virtual bool get_next_feature(int32_t& index, float64_t& value,
156  void* iterator);
157 
163  virtual void free_feature_iterator(void* iterator);
164 
166  virtual const char* get_name() const;
167 
172  virtual EFeatureType get_feature_type() const;
173 
178  virtual EFeatureClass get_feature_class() const;
179 
184  virtual int32_t get_num_vectors() const;
185 
190  SGSparseVector<ST> get_hashed_feature_vector(int32_t vec_idx) const;
191 
200  static SGSparseVector<ST> hash_vector(SGVector<ST> vec, int32_t dim,
201  bool use_quadratic = false, bool keep_linear_terms = true);
202 
203 
212  static SGSparseVector<ST> hash_vector(SGSparseVector<ST> vec, int32_t dim,
213  bool use_quadratic = false, bool keep_linear_terms = true);
214 
215 private:
216  void init(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr, bool keep_lin_terms);
217 
218 protected:
219 
222 
224  int32_t dim;
225 
228 
231 };
232 }
233 
234 #endif // _HASHED_SPARSEFEATURES_H__
template class SGSparseMatrix
CSparseFeatures< ST > * sparse_feats
virtual int32_t get_dim_feature_space() const
CHashedSparseFeatures(int32_t size=0, bool use_quadr=false, bool keep_lin_terms=true)
virtual EFeatureType get_feature_type() const
Features that support dot products among other operations.
Definition: DotFeatures.h:41
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:35
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry&lt;T&gt;* vector is orde...
virtual int32_t get_nnz_features_for_vector(int32_t num)
double float64_t
Definition: common.h:48
This class is identical to the CDenseFeatures class except that it hashes each dimension to a new fea...
virtual float64_t dot(int32_t vec_idx1, CDotFeatures *df, int32_t vec_idx2)
A File access base class.
Definition: File.h:34
virtual void free_feature_iterator(void *iterator)
virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
virtual const char * get_name() const
virtual CFeatures * duplicate() const
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
virtual int32_t get_num_vectors() const
The class Features is the base class of all feature objects.
Definition: Features.h:62
virtual EFeatureClass get_feature_class() const
SGSparseVector< ST > get_hashed_feature_vector(int32_t vec_idx) const
virtual void * get_feature_iterator(int32_t vector_index)
virtual bool get_next_feature(int32_t &index, float64_t &value, void *iterator)
virtual float64_t dense_dot(int32_t vec_idx1, const float64_t *vec2, int32_t vec2_len)
static SGSparseVector< ST > hash_vector(SGVector< ST > vec, int32_t dim, bool use_quadratic=false, bool keep_linear_terms=true)

SHOGUN Machine Learning Toolbox - Documentation