SHOGUN  v2.0.0
 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  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
10 #ifndef _STREAMING_SPARSEFEATURES__H__
11 #define _STREAMING_SPARSEFEATURES__H__
12 
13 #include <shogun/lib/common.h>
16 #include <shogun/lib/DataType.h>
18 
19 namespace shogun
20 {
43 template <class T> class CStreamingSparseFeatures : public CStreamingDotFeatures
44 {
45 public:
46 
55 
65  bool is_labelled,
66  int32_t size);
67 
74 
84  virtual void set_vector_reader();
85 
95  virtual void set_vector_and_label_reader();
96 
102  virtual void start_parser();
103 
109  virtual void end_parser();
110 
119  virtual bool get_next_example();
120 
127  T get_feature(int32_t index);
128 
135 
143  virtual float64_t get_label();
144 
151  virtual void release_example();
152 
157  virtual void reset_stream();
158 
170  int32_t set_num_features(int32_t num);
171 
179  virtual int32_t get_dim_feature_space() const;
180 
189  virtual void expand_if_required(float32_t*& vec, int32_t &len);
190 
199  virtual void expand_if_required(float64_t*& vec, int32_t &len);
200 
211  virtual float32_t dot(CStreamingDotFeatures *df);
212 
223  static T sparse_dot(T alpha, SGSparseVectorEntry<T>* avec, int32_t alen, SGSparseVectorEntry<T>* bvec, int32_t blen);
224 
234  T dense_dot(T alpha, T* vec, int32_t dim, T b);
235 
244  virtual float64_t dense_dot(const float64_t* vec2, int32_t vec2_len);
245 
254  virtual float32_t dense_dot(const float32_t* vec2, int32_t vec2_len);
255 
265  virtual void add_to_dense_vec(float64_t alpha, float64_t* vec2, int32_t vec2_len, bool abs_val=false);
266 
276  virtual void add_to_dense_vec(float32_t alpha, float32_t* vec2, int32_t vec2_len, bool abs_val=false);
277 
283  int64_t get_num_nonzero_entries();
284 
291 
297  void sort_features();
298 
304  virtual int32_t get_num_features();
305 
311  virtual int32_t get_nnz_features_for_vector();
312 
318  virtual EFeatureType get_feature_type() const;
319 
325  virtual EFeatureClass get_feature_class() const;
326 
332  virtual CFeatures* duplicate() const;
333 
339  inline virtual const char* get_name() const { return "StreamingSparseFeatures"; }
340 
346  virtual int32_t get_num_vectors() const;
347 
353  virtual int32_t get_size() const;
354 
355 private:
360  virtual void init();
361 
369  virtual void init(CStreamingFile *file, bool is_labelled, int32_t size);
370 
371 protected:
374 
377 
380 
383 
386 
389 
391  int32_t current_length;
392 
395 };
396 
397 }
398 #endif // _STREAMING_SPARSEFEATURES__H__

SHOGUN Machine Learning Toolbox - Documentation