SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
ui
GUIPluginEstimate.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) 1999-2008 Soeren Sonnenburg
8
* Written (W) 1999-2008 Gunnar Raetsch
9
* Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
10
*/
11
12
#include <
shogun/ui/SGInterface.h
>
13
#include <
shogun/ui/GUIPluginEstimate.h
>
14
15
#include <
shogun/lib/config.h
>
16
#include <
shogun/io/SGIO.h
>
17
#include <
shogun/features/StringFeatures.h
>
18
19
using namespace
shogun;
20
21
CGUIPluginEstimate::CGUIPluginEstimate
() :
CSGObject
()
22
{
23
init();
24
}
25
26
CGUIPluginEstimate::CGUIPluginEstimate
(CSGInterface* ui_)
27
:
CSGObject
()
28
{
29
init();
30
31
ui
=ui_;
32
}
33
34
CGUIPluginEstimate::~CGUIPluginEstimate
()
35
{
36
SG_UNREF
(
estimator
);
37
}
38
39
void
CGUIPluginEstimate::init()
40
{
41
ui
=NULL;
42
estimator
=NULL;
43
pos_pseudo
=1e-10;
44
neg_pseudo
=1e-10;
45
}
46
47
bool
CGUIPluginEstimate::new_estimator
(
float64_t
pos,
float64_t
neg)
48
{
49
SG_UNREF
(
estimator
);
50
estimator
=
new
CPluginEstimate
(pos, neg);
51
SG_REF
(
estimator
);
52
53
if
(!
estimator
)
54
SG_ERROR
(
"Could not create new plugin estimator, pos_pseudo %f, neg_pseudo %f\n"
,
pos_pseudo
,
neg_pseudo
)
55
else
56
SG_INFO
(
"Created new plugin estimator (%p), pos_pseudo %f, neg_pseudo %f\n"
,
estimator
,
pos_pseudo
,
neg_pseudo
)
57
58
return
true
;
59
}
60
61
bool
CGUIPluginEstimate::train
()
62
{
63
CLabels
* trainlabels=
ui
->ui_labels->get_train_labels();
64
CStringFeatures<uint16_t>
* trainfeatures=(
CStringFeatures<uint16_t>
*)
ui
->
65
ui_features->get_train_features();
66
bool
result=
false
;
67
68
if
(!trainlabels)
69
SG_ERROR
(
"No labels available.\n"
)
70
71
if
(!trainfeatures)
72
SG_ERROR
(
"No features available.\n"
)
73
74
ASSERT
(trainfeatures->
get_feature_type
()==
F_WORD
)
75
76
estimator
->
set_features
(trainfeatures);
77
estimator
->
set_labels
(trainlabels);
78
if
(
estimator
)
79
result=
estimator
->
train
();
80
else
81
SG_ERROR
(
"No estimator available.\n"
)
82
83
return
result;
84
}
85
86
bool
CGUIPluginEstimate::load
(
char
* param)
87
{
88
bool
result=
false
;
89
return
result;
90
}
91
92
bool
CGUIPluginEstimate::save
(
char
* param)
93
{
94
bool
result=
false
;
95
return
result;
96
}
97
98
CLabels
*
CGUIPluginEstimate::apply
()
99
{
100
CFeatures
* testfeatures=
ui
->ui_features->get_test_features();
101
102
if
(!
estimator
)
103
{
104
SG_ERROR
(
"no estimator available"
)
105
return
0;
106
}
107
108
if
(!testfeatures)
109
{
110
SG_ERROR
(
"no test features available"
)
111
return
0;
112
}
113
114
estimator
->
set_features
((
CStringFeatures<uint16_t>
*) testfeatures);
115
116
return
estimator
->
apply
();
117
}
118
119
float64_t
CGUIPluginEstimate::apply_one
(int32_t idx)
120
{
121
CFeatures
* testfeatures=
ui
->ui_features->get_test_features();
122
123
if
(!
estimator
)
124
{
125
SG_ERROR
(
"no estimator available"
)
126
return
0;
127
}
128
129
if
(!testfeatures)
130
{
131
SG_ERROR
(
"no test features available"
)
132
return
0;
133
}
134
135
estimator
->
set_features
((
CStringFeatures<uint16_t>
*) testfeatures);
136
137
return
estimator
->
apply_one
(idx);
138
}
SHOGUN
机器学习工具包 - 项目文档