SHOGUN  v3.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  virtual const char* get_name() const
83  {
84  return "StreamingFileFromStringFeatures";
85 
86  }
87 
88 private:
92  void init(CStringFeatures<T>* feat=NULL);
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(feat);
116 }
117 
118 template <class T>
120  : CStreamingFileFromFeatures(feat,lab)
121 {
122  init(feat);
123 }
124 
125 template <class T>
127 {
128 }
129 
130 template <class T>
132 {
133  vector_num=0;
134  features = feat;
135 
136  set_generic<T>();
137 }
138 
139 /* Functions to return the vector from the StringFeatures object */
140 template <class T>
141 void CStreamingFileFromStringFeatures<T>::get_string(T*& vector, int32_t& num_feat)
142 {
143  if (vector_num >= features->get_num_vectors())
144  {
145  vector=NULL;
146  num_feat=-1;
147  return;
148  }
149 
150  SGVector<T> sg_vector=
151  features->get_feature_vector(vector_num);
152 
153  vector = sg_vector.vector;
154  num_feat = sg_vector.vlen;
155  sg_vector.vector = NULL;
156  sg_vector.vlen = -1;
157  vector_num++;
158 }
159 
160 /* Functions to return the vector from the StringFeatures object with label */
161 template <class T>
163 (T*& vector, int32_t& num_feat, float64_t& label)
164 {
165  if (vector_num >= features->get_num_vectors())
166  {
167  vector=NULL;
168  num_feat=-1;
169  return;
170  }
171 
172  SGVector<T> sg_vector
173  =features->get_feature_vector(vector_num);
174 
175  vector = sg_vector.vector;
176  num_feat = sg_vector.vlen;
177  label = labels[vector_num];
178 
179  vector_num++;
180 }
181 
182 
183 }
184 #endif //__STREAMING_FILEFROMSTRING_H__

SHOGUN Machine Learning Toolbox - Documentation