SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
io
streaming
StreamingVwFile.cpp
浏览该文件的文档.
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
11
#include <
shogun/io/streaming/StreamingVwFile.h
>
12
13
using namespace
shogun;
14
15
CStreamingVwFile::CStreamingVwFile
()
16
:
CStreamingFile
()
17
{
18
init();
19
}
20
21
CStreamingVwFile::CStreamingVwFile
(
const
char
* fname,
char
rw)
22
:
CStreamingFile
(fname, rw)
23
{
24
init();
25
}
26
27
CStreamingVwFile::~CStreamingVwFile
()
28
{
29
SG_UNREF
(
env
);
30
SG_UNREF
(
parser
);
31
}
32
33
void
CStreamingVwFile::set_parser_type
(
E_VW_PARSER_TYPE
type)
34
{
35
switch
(type)
36
{
37
case
T_VW
:
38
parse_example
= &
CVwParser::read_features
;
39
parser_type
=
T_VW
;
40
return
;
41
case
T_SVMLIGHT
:
42
parse_example
= &
CVwParser::read_svmlight_features
;
43
parser_type
=
T_SVMLIGHT
;
44
return
;
45
case
T_DENSE
:
46
parse_example
= &
CVwParser::read_dense_features
;
47
parser_type
=
T_DENSE
;
48
return
;
49
}
50
51
SG_SERROR
(
"Unrecognized parser type!\n"
)
52
}
53
54
void
CStreamingVwFile::get_vector
(
VwExample
* &ex, int32_t &len)
55
{
56
len = (
parser
->*
parse_example
)(
buf
, ex);
57
if
(len == 0)
58
len = -1;
// indicates failure
59
}
60
61
void
CStreamingVwFile::get_vector_and_label
(
VwExample
* &ex, int32_t &len,
float64_t
&label)
62
{
63
len = (
parser
->*
parse_example
)(
buf
, ex);
64
if
(len == 0)
65
len = -1;
// indicates failure
66
}
67
68
void
CStreamingVwFile::init()
69
{
70
parser
=
new
CVwParser
();
71
env
=
parser
->
get_env
();
72
73
set_parser_type
(
T_VW
);
74
write_to_cache
=
false
;
75
SG_REF
(
env
);
76
}
SHOGUN
机器学习工具包 - 项目文档