SHOGUN
4.1.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
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/lib/config.h
>
14
15
#include <
shogun/io/streaming/StreamingFileFromFeatures.h
>
16
#include <
shogun/features/SparseFeatures.h
>
17
18
namespace
shogun
19
{
24
template
<
class
T>
class
CStreamingFileFromSparseFeatures
:
public
CStreamingFileFromFeatures
25
{
26
public
:
30
CStreamingFileFromSparseFeatures
();
31
37
CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat);
38
45
CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat,
float64_t
* lab);
46
50
virtual
~CStreamingFileFromSparseFeatures
();
51
60
virtual
void
get_sparse_vector
(
SGSparseVectorEntry<T>
* &vec, int32_t &len);
61
71
virtual
void
get_sparse_vector_and_label
(
SGSparseVectorEntry<T>
* &vec, int32_t &len,
float64_t
&label);
72
78
void
reset_stream
()
79
{
80
vector_num
= 0;
81
}
82
84
virtual
const
char
*
get_name
()
const
85
{
86
return
"StreamingFileFromSparseFeatures"
;
87
88
}
89
90
private
:
94
void
init(
CSparseFeatures<T>
* feat);
95
96
protected
:
98
CSparseFeatures<T>
*
features
;
99
101
int32_t
vector_num
;
102
103
};
104
105
template
<
class
T>
106
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
()
107
:
CStreamingFileFromFeatures
()
108
{
109
init(NULL);
110
}
111
112
template
<
class
T>
113
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat)
114
:
CStreamingFileFromFeatures
(feat)
115
{
116
init(feat);
117
}
118
119
template
<
class
T>
120
CStreamingFileFromSparseFeatures<T>::CStreamingFileFromSparseFeatures
(
CSparseFeatures<T>
* feat,
float64_t
* lab)
121
:
CStreamingFileFromFeatures
(feat,lab)
122
{
123
init(feat);
124
}
125
126
template
<
class
T>
127
CStreamingFileFromSparseFeatures<T>::~CStreamingFileFromSparseFeatures
()
128
{
129
SG_UNREF
(features);
130
}
131
132
template
<
class
T>
133
void
CStreamingFileFromSparseFeatures<T>::init
(
CSparseFeatures<T>
* feat)
134
{
135
features = feat;
136
SG_REF
(features);
137
vector_num=0;
138
139
set_generic<T>();
140
}
141
142
/* Functions to return the vector from the SparseFeatures object */
143
template
<
class
T>
144
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector
145
(
SGSparseVectorEntry<T>
*& vector, int32_t& len)
146
{
147
if
(vector_num >= features->get_num_vectors())
148
{
149
vector=NULL;
150
len=-1;
151
return
;
152
}
153
154
SGSparseVector<T>
vec=
155
features->get_sparse_feature_vector(vector_num);
156
vector=vec.
features
;
157
len=vec.
num_feat_entries
;
158
159
/* TODO. check if vector needs to be freed? */
160
161
vector_num++;
162
}
163
164
/* Functions to return the vector from the SparseFeatures object */
165
template
<
class
T>
166
void
CStreamingFileFromSparseFeatures<T>::get_sparse_vector_and_label
167
(
SGSparseVectorEntry<T>
*& vector, int32_t& len,
float64_t
& label)
168
{
169
get_sparse_vector(vector, len);
170
label=labels[vector_num];
171
}
172
173
}
174
#endif //__STREAMING_FILEFROMSPARSE_H__
shogun::CStreamingFileFromSparseFeatures::CStreamingFileFromSparseFeatures
CStreamingFileFromSparseFeatures()
Definition:
StreamingFileFromSparseFeatures.h:106
shogun::CStreamingFileFromSparseFeatures::reset_stream
void reset_stream()
Definition:
StreamingFileFromSparseFeatures.h:78
shogun::CStreamingFileFromSparseFeatures::~CStreamingFileFromSparseFeatures
virtual ~CStreamingFileFromSparseFeatures()
Definition:
StreamingFileFromSparseFeatures.h:127
shogun::CStreamingFileFromSparseFeatures::get_name
virtual const char * get_name() const
Definition:
StreamingFileFromSparseFeatures.h:84
StreamingFileFromFeatures.h
shogun::CSparseFeatures< T >
config.h
SG_REF
#define SG_REF(x)
Definition:
SGObject.h:51
shogun::SGSparseVector::num_feat_entries
index_t num_feat_entries
Definition:
SGSparseVector.h:212
shogun::CStreamingFileFromFeatures
Class StreamingFileFromFeatures to read vector-by-vector from a CFeatures object. ...
Definition:
StreamingFileFromFeatures.h:38
shogun::CStreamingFileFromSparseFeatures::features
CSparseFeatures< T > * features
SparseFeatures object.
Definition:
StreamingFileFromSparseFeatures.h:98
float64_t
double float64_t
Definition:
common.h:50
SparseFeatures.h
shogun::SGSparseVector::features
SGSparseVectorEntry< T > * features
Definition:
SGSparseVector.h:215
shogun::CStreamingFileFromSparseFeatures::get_sparse_vector
virtual void get_sparse_vector(SGSparseVectorEntry< T > *&vec, int32_t &len)
Definition:
StreamingFileFromSparseFeatures.h:145
SG_UNREF
#define SG_UNREF(x)
Definition:
SGObject.h:52
shogun
all of classes and functions are contained in the shogun namespace
Definition:
class_list.h:18
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:167
shogun::SGSparseVectorEntry
template class SGSparseVectorEntry
Definition:
File.h:23
shogun::SGSparseVector
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry
* vector is orde...
Definition:
base/Parameter.h:29
shogun::CStreamingFileFromSparseFeatures::vector_num
int32_t vector_num
Index of vector to be returned from the feature matrix.
Definition:
StreamingFileFromSparseFeatures.h:101
shogun::CStreamingFileFromSparseFeatures
Class CStreamingFileFromSparseFeatures is derived from CStreamingFile and provides an input source fo...
Definition:
StreamingFileFromSparseFeatures.h:24
SHOGUN
Machine Learning Toolbox - Documentation