SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
io
streaming
StreamingFileFromSparseFeatures.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_FILEFROMSPARSE_H__
11
#define __STREAMING_FILEFROMSPARSE_H__
12
13
#include <
shogun/io/streaming/StreamingFileFromFeatures.h
>
14
#include <
shogun/features/SparseFeatures.h
>
15
16
namespace
shogun
17
{
22
template
<
class
T>
class
CStreamingFileFromSparseFeatures
:
public
CStreamingFileFromFeatures
23
{
24
public
:
28
CStreamingFileFromSparseFeatures
();
29
35
CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat);
36
43
CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat,
float64_t
* lab);
44
48
virtual
~CStreamingFileFromSparseFeatures
();
49
58
virtual
void
get_sparse_vector
(
SGSparseVectorEntry<T>
* &vec, int32_t &len);
59
69
virtual
void
get_sparse_vector_and_label
(
SGSparseVectorEntry<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
"StreamingFileFromSparseFeatures"
;
85
86
}
87
88
private
:
92
void
init();
93
94
protected
:
96
CSparseFeatures<T>
*
features
;
97
99
int32_t
vector_num
;
100
101
};
102
103
template
<
class
T>
104
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
()
105
:
CStreamingFileFromFeatures
()
106
{
107
init();
108
}
109
110
template
<
class
T>
111
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat)
112
:
CStreamingFileFromFeatures
(feat)
113
{
114
init();
115
}
116
117
template
<
class
T>
118
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat,
float64_t
* lab)
119
:
CStreamingFileFromFeatures
(feat,lab)
120
{
121
init();
122
}
123
124
template
<
class
T>
125
CStreamingFileFromSparseFeatures<T>::~CStreamingFileFromSparseFeatures
()
126
{
127
}
128
129
template
<
class
T>
130
void
CStreamingFileFromSparseFeatures<T>::init
()
131
{
132
vector_num=0;
133
}
134
135
/* Functions to return the vector from the SparseFeatures object */
136
template
<
class
T>
137
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector
138
(
SGSparseVectorEntry<T>
*& vector, int32_t& len)
139
{
140
if
(vector_num >= features->get_num_vectors())
141
{
142
vector=NULL;
143
len=-1;
144
return
;
145
}
146
147
SGSparseVector<T>
vec=
148
((
CSparseFeatures<T>
*)
this
)->get_sparse_feature_vector(vector_num);
149
vector=vec.
features
;
150
len=vec.
num_feat_entries
;
151
152
/* TODO. check if vector needs to be freed? */
153
154
vector_num++;
155
}
156
157
/* Functions to return the vector from the SparseFeatures object */
158
template
<
class
T>
159
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector_and_label
160
(
SGSparseVectorEntry<T>
*& vector, int32_t& len,
float64_t
& label)
161
{
162
get_sparse_vector(vector, len);
163
label=labels[vector_num];
164
}
165
166
}
167
#endif //__STREAMING_FILEFROMSPARSE_H__
SHOGUN
Machine Learning Toolbox - Documentation