SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingSparseFeatures.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) 2011 Shashwat Lal Das
8  * Modifications (W) 2013 Thoralf Klein
9  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
10  */
11 #ifndef _STREAMING_SPARSEFEATURES__H__
12 #define _STREAMING_SPARSEFEATURES__H__
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/lib/common.h>
21 
22 namespace shogun
23 {
24 class CStreamingFile;
25 
48 template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
49 {
50 public:
51 
60 
70  bool is_labelled,
71  int32_t size);
72 
78  virtual ~CStreamingSparseFeatures();
79 
89  virtual void set_vector_reader();
90 
100  virtual void set_vector_and_label_reader();
101 
107  virtual void start_parser();
108 
114  virtual void end_parser();
115 
124  virtual bool get_next_example();
125 
132  T get_feature(int32_t index);
133 
140 
148  virtual float64_t get_label();
149 
156  virtual void release_example();
157 
162  virtual void reset_stream();
163 
175  int32_t set_num_features(int32_t num);
176 
184  virtual int32_t get_dim_feature_space() const;
185 
196  virtual float32_t dot(CStreamingDotFeatures *df);
197 
208  static T sparse_dot(T alpha, SGSparseVectorEntry<T>* avec, int32_t alen, SGSparseVectorEntry<T>* bvec, int32_t blen);
209 
219  T dense_dot(T alpha, T* vec, int32_t dim, T b);
220 
229  virtual float64_t dense_dot(const float64_t* vec2, int32_t vec2_len);
230 
239  virtual float32_t dense_dot(const float32_t* vec2, int32_t vec2_len);
240 
250  virtual void add_to_dense_vec(float64_t alpha, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
251 
261  virtual void add_to_dense_vec(float32_t alpha, float32_t* vec2, int32_t vec2_len, bool abs_val=false);
262 
268  int64_t get_num_nonzero_entries();
269 
276 
282  void sort_features();
283 
289  virtual int32_t get_num_features();
290 
296  virtual int32_t get_nnz_features_for_vector();
297 
303  virtual EFeatureType get_feature_type() const;
304 
310  virtual EFeatureClass get_feature_class() const;
311 
317  virtual CFeatures* duplicate() const;
318 
324  virtual const char* get_name() const { return "StreamingSparseFeatures"; }
325 
331  virtual int32_t get_num_vectors() const;
332 
333 private:
338  virtual void init();
339 
347  virtual void init(CStreamingFile *file, bool is_labelled, int32_t size);
348 
349 protected:
351  CInputParser< SGSparseVectorEntry<T> > parser;
352 
355 
358 
361 
364 };
365 
366 }
367 #endif // _STREAMING_SPARSEFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation