SHOGUN
v3.2.0
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
virtual
const
char
*
get_name
()
const
83
{
84
return
"StreamingFileFromSparseFeatures"
;
85
86
}
87
88
private
:
92
void
init(
CSparseFeatures<T>
* feat);
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(NULL);
108
}
109
110
template
<
class
T>
111
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat)
112
:
CStreamingFileFromFeatures
(feat)
113
{
114
init(feat);
115
}
116
117
template
<
class
T>
118
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat,
float64_t
* lab)
119
:
CStreamingFileFromFeatures
(feat,lab)
120
{
121
init(feat);
122
}
123
124
template
<
class
T>
125
CStreamingFileFromSparseFeatures<T>::~CStreamingFileFromSparseFeatures
()
126
{
127
SG_UNREF
(
features
);
128
}
129
130
template
<
class
T>
131
void
CStreamingFileFromSparseFeatures<T>::init
(
CSparseFeatures<T>
* feat)
132
{
133
features
= feat;
134
SG_REF
(
features
);
135
vector_num
=0;
136
137
set_generic<T>();
138
}
139
140
/* Functions to return the vector from the SparseFeatures object */
141
template
<
class
T>
142
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector
143
(
SGSparseVectorEntry<T>
*& vector, int32_t& len)
144
{
145
if
(
vector_num
>=
features
->
get_num_vectors
())
146
{
147
vector=NULL;
148
len=-1;
149
return
;
150
}
151
152
SGSparseVector<T>
vec=
153
features
->
get_sparse_feature_vector
(
vector_num
);
154
vector=vec.
features
;
155
len=vec.
num_feat_entries
;
156
157
/* TODO. check if vector needs to be freed? */
158
159
vector_num
++;
160
}
161
162
/* Functions to return the vector from the SparseFeatures object */
163
template
<
class
T>
164
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector_and_label
165
(
SGSparseVectorEntry<T>
*& vector, int32_t& len,
float64_t
& label)
166
{
167
get_sparse_vector
(vector, len);
168
label=
labels
[
vector_num
];
169
}
170
171
}
172
#endif //__STREAMING_FILEFROMSPARSE_H__
shogun::CStreamingFileFromSparseFeatures::CStreamingFileFromSparseFeatures
CStreamingFileFromSparseFeatures()
Definition:
StreamingFileFromSparseFeatures.h:104
shogun::CStreamingFileFromSparseFeatures::reset_stream
void reset_stream()
Definition:
StreamingFileFromSparseFeatures.h:76
shogun::CStreamingFileFromSparseFeatures::~CStreamingFileFromSparseFeatures
virtual ~CStreamingFileFromSparseFeatures()
Definition:
StreamingFileFromSparseFeatures.h:125
shogun::CStreamingFileFromSparseFeatures::get_name
virtual const char * get_name() const
Definition:
StreamingFileFromSparseFeatures.h:82
SG_UNREF
#define SG_UNREF(x)
Definition:
SGRefObject.h:35
StreamingFileFromFeatures.h
shogun::CSparseFeatures< T >
shogun::CStreamingFileFromFeatures::labels
float64_t * labels
Labels (if applicable)
Definition:
StreamingFileFromFeatures.h:98
shogun::CStreamingFileFromFeatures
Class StreamingFileFromFeatures to read vector-by-vector from a CFeatures object. ...
Definition:
StreamingFileFromFeatures.h:34
shogun::SGSparseVector
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry<T>* vector is orde...
Definition:
HashedSparseFeatures.h:21
shogun::CStreamingFileFromSparseFeatures::features
CSparseFeatures< T > * features
SparseFeatures object.
Definition:
StreamingFileFromSparseFeatures.h:96
float64_t
double float64_t
Definition:
common.h:48
SG_REF
#define SG_REF(x)
Definition:
SGRefObject.h:34
SparseFeatures.h
shogun::CStreamingFileFromSparseFeatures::get_sparse_vector
virtual void get_sparse_vector(SGSparseVectorEntry< T > *&vec, int32_t &len)
Definition:
StreamingFileFromSparseFeatures.h:143
shogun::CSparseFeatures::get_num_vectors
virtual int32_t get_num_vectors() const
Definition:
SparseFeatures.cpp:324
shogun
all of classes and functions are contained in the shogun namespace
Definition:
class_list.h:16
shogun::CStreamingFileFromSparseFeatures::get_sparse_vector_and_label
virtual void get_sparse_vector_and_label(SGSparseVectorEntry< T > *&vec, int32_t &len, float64_t &label)
Definition:
StreamingFileFromSparseFeatures.h:165
shogun::SGSparseVector::num_feat_entries
index_t num_feat_entries
Definition:
SGSparseVector.h:220
shogun::SGSparseVectorEntry
template class SGSparseVectorEntry
Definition:
File.h:23
shogun::CSparseFeatures::get_sparse_feature_vector
SGSparseVector< ST > get_sparse_feature_vector(int32_t num)
Definition:
SparseFeatures.cpp:93
shogun::CStreamingFileFromSparseFeatures::vector_num
int32_t vector_num
Index of vector to be returned from the feature matrix.
Definition:
StreamingFileFromSparseFeatures.h:99
shogun::CStreamingFileFromSparseFeatures
Class CStreamingFileFromSparseFeatures is derived from CStreamingFile and provides an input source fo...
Definition:
StreamingFileFromSparseFeatures.h:22
shogun::SGSparseVector::features
SGSparseVectorEntry< T > * features
Definition:
SGSparseVector.h:223
SHOGUN
Machine Learning Toolbox - Documentation