SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
io
streaming
StreamingFileFromDenseFeatures.h
浏览该文件的文档.
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_FILEFROMDENSE_H__
11
#define __STREAMING_FILEFROMDENSE_H__
12
13
#include <
shogun/io/streaming/StreamingFileFromFeatures.h
>
14
#include <
shogun/features/DenseFeatures.h
>
15
16
namespace
shogun
17
{
27
template
<
class
T>
class
CStreamingFileFromDenseFeatures
:
28
public
CStreamingFileFromFeatures
29
{
30
public
:
34
CStreamingFileFromDenseFeatures
();
35
42
CStreamingFileFromDenseFeatures
(
CDenseFeatures<T>
* feat,
43
float64_t
* lab=NULL);
44
48
virtual
~CStreamingFileFromDenseFeatures
();
49
58
virtual
void
get_vector
(T* &vec, int32_t &len);
59
69
virtual
void
get_vector_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
"StreamingFileFromDenseFeatures"
;
85
86
}
87
88
private
:
92
void
init();
93
94
protected
:
95
97
CDenseFeatures<T>
*
features
;
98
100
int32_t
vector_num
;
101
102
};
103
104
template
<
class
T>
105
CStreamingFileFromDenseFeatures<T>::CStreamingFileFromDenseFeatures
() :
106
CStreamingFileFromFeatures
()
107
{
108
init();
109
}
110
111
template
<
class
T>
112
CStreamingFileFromDenseFeatures<T>::CStreamingFileFromDenseFeatures
(
113
CDenseFeatures<T>
* feat,
float64_t
* lab) :
114
CStreamingFileFromFeatures
()
115
{
116
init();
117
118
REQUIRE
(feat,
"%s::CStreamingFileFromDenseFeatures() features required!\n"
,
119
get_name
());
120
features
=feat;
121
SG_REF
(feat);
122
123
labels
=lab;
124
125
}
126
127
template
<
class
T>
128
CStreamingFileFromDenseFeatures<T>::~CStreamingFileFromDenseFeatures
()
129
{
130
SG_UNREF
(features);
131
}
132
133
template
<
class
T>
134
void
CStreamingFileFromDenseFeatures<T>::init
()
135
{
136
vector_num=0;
137
features=NULL;
138
139
set_generic<T>();
140
}
141
142
/* Functions to return the vector from the DenseFeatures object
143
* If the class is of type T, specialize this function to work for
144
* vectors of that type. */
145
template
<
class
T>
146
void
CStreamingFileFromDenseFeatures<T>::get_vector
(T*& vector,
147
int32_t& num_feat)
148
{
149
if
(vector_num>=features->get_num_vectors())
150
{
151
vector=NULL;
152
num_feat=-1;
153
return
;
154
}
155
156
SGVector<T>
sg_vector=features->get_feature_vector(vector_num);
157
158
vector=sg_vector.
vector
;
159
num_feat=sg_vector.
vlen
;
160
vector_num++;
161
162
}
163
164
/* Functions to return the vector from the DenseFeatures object with label */
165
template
<
class
T>
166
void
CStreamingFileFromDenseFeatures<T>::get_vector_and_label
(T*& vector,
167
int32_t& num_feat,
float64_t
& label)
168
{
169
if
(vector_num>=features->get_num_vectors())
170
{
171
vector=NULL;
172
num_feat=-1;
173
return
;
174
}
175
176
SGVector<T>
sg_vector=features->get_feature_vector(vector_num);
177
178
vector=sg_vector.
vector
;
179
num_feat=sg_vector.
vlen
;
180
label=labels[vector_num];
181
182
vector_num++;
183
}
184
185
186
}
187
#endif //__STREAMING_FILEFROMDENSE_H__
SHOGUN
机器学习工具包 - 项目文档