SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StreamingFileFromSparseFeatures.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_FILEFROMSPARSE_H__
11 #define __STREAMING_FILEFROMSPARSE_H__
12 
13 #include <shogun/lib/config.h>
14 
17 
18 namespace shogun
19 {
25 {
26 public:
31 
38 
46 
51 
60  virtual void get_sparse_vector(SGSparseVectorEntry<T>* &vec, int32_t &len);
61 
71  virtual void get_sparse_vector_and_label(SGSparseVectorEntry<T>* &vec, int32_t &len, float64_t &label);
72 
78  void reset_stream()
79  {
80  vector_num = 0;
81  }
82 
84  virtual const char* get_name() const
85  {
86  return "StreamingFileFromSparseFeatures";
87 
88  }
89 
90 private:
94  void init(CSparseFeatures<T>* feat);
95 
96 protected:
99 
101  int32_t vector_num;
102 
103 };
104 
105 template <class T>
108 {
109  init(NULL);
110 }
111 
112 template <class T>
115 {
116  init(feat);
117 }
118 
119 template <class T>
121  : CStreamingFileFromFeatures(feat,lab)
122 {
123  init(feat);
124 }
125 
126 template <class T>
128 {
129  SG_UNREF(features);
130 }
131 
132 template <class T>
134 {
135  features = feat;
136  SG_REF(features);
137  vector_num=0;
138 
139  set_generic<T>();
140 }
141 
142 /* Functions to return the vector from the SparseFeatures object */
143 template <class T>
145 (SGSparseVectorEntry<T>*& vector, int32_t& len)
146 {
147  if (vector_num >= features->get_num_vectors())
148  {
149  vector=NULL;
150  len=-1;
151  return;
152  }
153 
154  SGSparseVector<T> vec=
155  features->get_sparse_feature_vector(vector_num);
156  vector=vec.features;
157  len=vec.num_feat_entries;
158 
159  /* TODO. check if vector needs to be freed? */
160 
161  vector_num++;
162 }
163 
164 /* Functions to return the vector from the SparseFeatures object */
165 template <class T>
167 (SGSparseVectorEntry<T>*& vector, int32_t& len, float64_t& label)
168 {
169  get_sparse_vector(vector, len);
170  label=labels[vector_num];
171 }
172 
173 }
174 #endif //__STREAMING_FILEFROMSPARSE_H__
#define SG_REF(x)
Definition: SGObject.h:51
Class StreamingFileFromFeatures to read vector-by-vector from a CFeatures object. ...
CSparseFeatures< T > * features
SparseFeatures object.
double float64_t
Definition: common.h:50
SGSparseVectorEntry< T > * features
virtual void get_sparse_vector(SGSparseVectorEntry< T > *&vec, int32_t &len)
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual void get_sparse_vector_and_label(SGSparseVectorEntry< T > *&vec, int32_t &len, float64_t &label)
template class SGSparseVectorEntry
Definition: File.h:23
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
int32_t vector_num
Index of vector to be returned from the feature matrix.
Class CStreamingFileFromSparseFeatures is derived from CStreamingFile and provides an input source fo...

SHOGUN Machine Learning Toolbox - Documentation