SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashedSparseFeatures.h
Go to the documentation of this file.
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 
14 #include <shogun/lib/config.h>
15 
19 
20 namespace shogun
21 {
22 template <class ST> class CSparseFeatures;
23 template <class ST> class SGSparseVector;
24 class CDotFeatures;
25 
29 template <class ST> class CHashedSparseFeatures : public CDotFeatures
30 {
31 public:
32 
39  CHashedSparseFeatures(int32_t size=0, bool use_quadr = false, bool keep_lin_terms = true);
40 
48  CHashedSparseFeatures(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr = false,
49  bool keep_lin_terms = true);
50 
58  CHashedSparseFeatures(SGSparseMatrix<ST> matrix, int32_t d, bool use_quadr = false,
59  bool keep_lin_terms = true);
60 
68  CHashedSparseFeatures(CFile* loader, int32_t d, bool use_quadr = false,
69  bool keep_lin_terms = true);
70 
73 
75  virtual CFeatures* duplicate() const;
76 
78  virtual ~CHashedSparseFeatures();
79 
87  virtual int32_t get_dim_feature_space() const;
88 
98  virtual float64_t dot(int32_t vec_idx1, CDotFeatures* df,
99  int32_t vec_idx2);
100 
109  virtual float64_t dense_dot(int32_t vec_idx1, const float64_t* vec2,
110  int32_t vec2_len);
111 
122  virtual void add_to_dense_vec(float64_t alpha, int32_t vec_idx1,
123  float64_t* vec2, int32_t vec2_len, bool abs_val = false);
124 
130  virtual int32_t get_nnz_features_for_vector(int32_t num);
131 
143  virtual void* get_feature_iterator(int32_t vector_index);
144 
157  virtual bool get_next_feature(int32_t& index, float64_t& value,
158  void* iterator);
159 
165  virtual void free_feature_iterator(void* iterator);
166 
168  virtual const char* get_name() const;
169 
174  virtual EFeatureType get_feature_type() const;
175 
180  virtual EFeatureClass get_feature_class() const;
181 
186  virtual int32_t get_num_vectors() const;
187 
192  SGSparseVector<ST> get_hashed_feature_vector(int32_t vec_idx) const;
193 
202  static SGSparseVector<ST> hash_vector(SGVector<ST> vec, int32_t dim,
203  bool use_quadratic = false, bool keep_linear_terms = true);
204 
205 
214  static SGSparseVector<ST> hash_vector(SGSparseVector<ST> vec, int32_t dim,
215  bool use_quadratic = false, bool keep_linear_terms = true);
216 
217 private:
218  void init(CSparseFeatures<ST>* feats, int32_t d, bool use_quadr, bool keep_lin_terms);
219 
220 protected:
221 
224 
226  int32_t dim;
227 
230 
233 };
234 }
235 
236 #endif // _HASHED_SPARSEFEATURES_H__

SHOGUN Machine Learning Toolbox - Documentation