SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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__
index_t current_vec_index
The current vector index.
int32_t current_num_features
Number of features in current vector (as seen so far upto the current vector)
int32_t index_t
Definition: common.h:62
virtual void add_to_dense_vec(float64_t alpha, float64_t *vec2, int32_t vec2_len, bool abs_val=false)
virtual EFeatureType get_feature_type() const
static T sparse_dot(T alpha, SGSparseVectorEntry< T > *avec, int32_t alen, SGSparseVectorEntry< T > *bvec, int32_t blen)
EFeatureClass
shogun feature class
Definition: FeatureTypes.h:38
A Streaming File access class.
Definition: StreamingFile.h:34
virtual float32_t dot(CStreamingDotFeatures *df)
virtual int32_t get_dim_feature_space() const
double float64_t
Definition: common.h:50
virtual CFeatures * duplicate() const
Streaming features that support dot products among other operations.
float64_t current_label
The current example's label.
float float32_t
Definition: common.h:49
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
SGSparseVector< T > current_sgvector
The current example's feature vector as an SGVector
virtual EFeatureClass get_feature_class() const
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CInputParser< SGSparseVectorEntry< T > > parser
The parser object, which reads from input and returns parsed example objects.
template class SGSparseVectorEntry
Definition: File.h:23
The class Features is the base class of all feature objects.
Definition: Features.h:68
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
T dense_dot(T alpha, T *vec, int32_t dim, T b)
This class implements streaming features with sparse feature vectors. The vector is represented as an...
virtual const char * get_name() const

SHOGUN Machine Learning Toolbox - Documentation