SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
15 
16 namespace shogun
17 {
27 template<class T> class CStreamingFileFromDenseFeatures:
29 {
30 public:
35 
43  float64_t* lab=NULL);
44 
49 
58  virtual void get_vector(T* &vec, int32_t &len);
59 
69  virtual void get_vector_and_label(T* &vec, int32_t &len, float64_t &label);
70 
76  void reset_stream()
77  {
78  vector_num=0;
79  }
80 
82  virtual const char* get_name() const
83  {
84  return "StreamingFileFromDenseFeatures";
85 
86  }
87 
88 private:
92  void init();
93 
94 protected:
95 
98 
100  int32_t vector_num;
101 
102 };
103 
104 template<class T>
107 {
108  init();
109 }
110 
111 template<class T>
113  CDenseFeatures<T>* feat, float64_t* lab) :
115 {
116  init();
117 
118  REQUIRE(feat,"%s::CStreamingFileFromDenseFeatures() features required!\n",
119  get_name());
120  features=feat;
121  SG_REF(feat);
122 
123  labels=lab;
124 
125 }
126 
127 template<class T>
129 {
130  SG_UNREF(features);
131 }
132 
133 template<class T>
135 {
136  vector_num=0;
137  features=NULL;
138 
139  set_generic<T>();
140 }
141 
142 /* Functions to return the vector from the DenseFeatures object
143  * If the class is of type T, specialize this function to work for
144  * vectors of that type. */
145 template<class T>
147  int32_t& num_feat)
148 {
149  if (vector_num>=features->get_num_vectors())
150  {
151  vector=NULL;
152  num_feat=-1;
153  return;
154  }
155 
156  SGVector<T> sg_vector=features->get_feature_vector(vector_num);
157 
158  vector=sg_vector.vector;
159  num_feat=sg_vector.vlen;
160  vector_num++;
161 
162 }
163 
164 /* Functions to return the vector from the DenseFeatures object with label */
165 template<class T>
167  int32_t& num_feat, float64_t& label)
168 {
169  if (vector_num>=features->get_num_vectors())
170  {
171  vector=NULL;
172  num_feat=-1;
173  return;
174  }
175 
176  SGVector<T> sg_vector=features->get_feature_vector(vector_num);
177 
178  vector=sg_vector.vector;
179  num_feat=sg_vector.vlen;
180  label=labels[vector_num];
181 
182  vector_num++;
183 }
184 
185 
186 }
187 #endif //__STREAMING_FILEFROMDENSE_H__

SHOGUN Machine Learning Toolbox - Documentation