SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StreamingFileFromStringFeatures.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_FILEFROMSTRING_H__
11 #define __STREAMING_FILEFROMSTRING_H__
12 
15 
16 namespace shogun
17 {
23 {
24 public:
29 
36 
44 
49 
58  virtual void get_string(T* &vec, int32_t &len);
59 
69  virtual void get_string_and_label(T* &vec, int32_t &len, float64_t &label);
70 
76  void reset_stream()
77  {
78  vector_num = 0;
79  }
80 
82  inline virtual const char* get_name() const
83  {
84  return "StreamingFileFromStringFeatures";
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>
114 {
115  init();
116 }
117 
118 template <class T>
120  : CStreamingFileFromFeatures(feat,lab)
121 {
122  init();
123 }
124 
125 template <class T>
127 {
128 }
129 
130 template <class T>
132 {
133  vector_num=0;
134 }
135 
136 /* Functions to return the vector from the StringFeatures object */
137 template <class T>
138 void CStreamingFileFromStringFeatures<T>::get_string(T*& vector, int32_t& num_feat)
139 {
140  if (vector_num >= features->get_num_vectors())
141  {
142  vector=NULL;
143  num_feat=-1;
144  return;
145  }
146 
147  SGVector<T> sg_vector=
148  features->get_feature_vector(vector_num);
149 
150  vector = sg_vector.vector;
151  num_feat = sg_vector.vlen;;
152  vector_num++;
153 
154 }
155 
156 /* Functions to return the vector from the StringFeatures object with label */
157 template <class T>
159 (T*& vector, int32_t& num_feat, float64_t& label)
160 {
161  if (vector_num >= features->get_num_vectors())
162  {
163  vector=NULL;
164  num_feat=-1;
165  return;
166  }
167 
168  SGVector<T> sg_vector
169  =features->get_feature_vector(vector_num);
170 
171  vector = sg_vector.vector;
172  num_feat = sg_vector.vlen;
173  label = labels[vector_num];
174 
175  vector_num++;
176 }
177 
178 
179 }
180 #endif //__STREAMING_FILEFROMSTRING_H__

SHOGUN Machine Learning Toolbox - Documentation