SHOGUN  v2.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 {
28 {
29 public:
34 
41 
49 
54 
63  virtual void get_vector(T* &vec, int32_t &len);
64 
74  virtual void get_vector_and_label(T* &vec, int32_t &len, float64_t &label);
75 
81  void reset_stream()
82  {
83  vector_num = 0;
84  }
85 
87  inline virtual const char* get_name() const
88  {
89  return "StreamingFileFromDenseFeatures";
90 
91  }
92 
93 private:
97  void init();
98 
99 protected:
100 
103 
105  int32_t vector_num;
106 
107 };
108 
109 template <class T>
112 {
113  init();
114 }
115 
116 template <class T>
119 {
120  ASSERT(feat);
121  features=feat;
122 
123  init();
124 }
125 
126 template <class T>
129 {
130  ASSERT(feat);
131  ASSERT(lab);
132  features=feat;
133  labels=lab;
134 
135  init();
136 }
137 
138 template <class T>
140 {
141 }
142 
143 template <class T>
145 {
146  vector_num=0;
147 }
148 
149 /* Functions to return the vector from the DenseFeatures object
150  * If the class is of type T, specialize this function to work for
151  * vectors of that type. */
152 template <class T>
153 void CStreamingFileFromDenseFeatures<T>::get_vector(T*& vector, int32_t& num_feat)
154 {
155  if (vector_num >= features->get_num_vectors())
156  {
157  vector=NULL;
158  num_feat=-1;
159  return;
160  }
161 
162  SGVector<T> sg_vector=
163  features->get_feature_vector(vector_num);
164 
165  vector = sg_vector.vector;
166  num_feat = sg_vector.vlen;;
167  vector_num++;
168 
169 }
170 
171 /* Functions to return the vector from the DenseFeatures object with label */
172 template <class T>
174 (T*& vector, int32_t& num_feat, float64_t& label)
175 {
176  if (vector_num >= features->get_num_vectors())
177  {
178  vector=NULL;
179  num_feat=-1;
180  return;
181  }
182 
183  SGVector<T> sg_vector
184  =features->get_feature_vector(vector_num);
185 
186  vector = sg_vector.vector;
187  num_feat = sg_vector.vlen;
188  label = labels[vector_num];
189 
190  vector_num++;
191 }
192 
193 }
194 #endif //__STREAMING_FILEFROMDENSE_H__

SHOGUN Machine Learning Toolbox - Documentation