SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StreamingFileFromDenseFeatures.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_FILEFROMDENSE_H__
11 #define __STREAMING_FILEFROMDENSE_H__
12 
13 #include <shogun/lib/config.h>
14 
17 
18 namespace shogun
19 {
29 template<class T> class CStreamingFileFromDenseFeatures:
31 {
32 public:
37 
45  float64_t* lab=NULL);
46 
51 
60  virtual void get_vector(T* &vec, int32_t &len);
61 
71  virtual void get_vector_and_label(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 "StreamingFileFromDenseFeatures";
87 
88  }
89 
90 private:
94  void init();
95 
96 protected:
97 
100 
102  int32_t vector_num;
103 
104 };
105 
106 template<class T>
109 {
110  init();
111 }
112 
113 template<class T>
115  CDenseFeatures<T>* feat, float64_t* lab) :
117 {
118  init();
119 
120  REQUIRE(feat,"%s::CStreamingFileFromDenseFeatures() features required!\n",
121  get_name());
122  features=feat;
123  SG_REF(feat);
124 
125  labels=lab;
126 
127 }
128 
129 template<class T>
131 {
132  SG_UNREF(features);
133 }
134 
135 template<class T>
137 {
138  vector_num=0;
139  features=NULL;
140 
141  set_generic<T>();
142 }
143 
144 /* Functions to return the vector from the DenseFeatures object
145  * If the class is of type T, specialize this function to work for
146  * vectors of that type. */
147 template<class T>
149  int32_t& num_feat)
150 {
151  if (vector_num>=features->get_num_vectors())
152  {
153  vector=NULL;
154  num_feat=-1;
155  return;
156  }
157 
158  SGVector<T> sg_vector=features->get_feature_vector(vector_num);
159 
160  vector=sg_vector.vector;
161  num_feat=sg_vector.vlen;
162  vector_num++;
163 
164 }
165 
166 /* Functions to return the vector from the DenseFeatures object with label */
167 template<class T>
169  int32_t& num_feat, float64_t& label)
170 {
171  if (vector_num>=features->get_num_vectors())
172  {
173  vector=NULL;
174  num_feat=-1;
175  return;
176  }
177 
178  SGVector<T> sg_vector=features->get_feature_vector(vector_num);
179 
180  vector=sg_vector.vector;
181  num_feat=sg_vector.vlen;
182  label=labels[vector_num];
183 
184  vector_num++;
185 }
186 
187 
188 }
189 #endif //__STREAMING_FILEFROMDENSE_H__
Class CStreamingFileFromDenseFeatures is a derived class of CStreamingFile which creates an input sou...
#define REQUIRE(x,...)
Definition: SGIO.h:206
float64_t * labels
Labels (if applicable)
virtual void get_vector(T *&vec, int32_t &len)
#define SG_REF(x)
Definition: SGObject.h:54
Class StreamingFileFromFeatures to read vector-by-vector from a CFeatures object. ...
virtual void get_vector_and_label(T *&vec, int32_t &len, float64_t &label)
index_t vlen
Definition: SGVector.h:494
shogun vector
double float64_t
Definition: common.h:50
CDenseFeatures< T > * features
DenseFeatures object.
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
int32_t vector_num
Index of vector to be returned from the feature matrix.

SHOGUN Machine Learning Toolbox - Documentation