SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
machine
LinearMulticlassMachine.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) 2012 Sergey Lisitsyn
8
* Copyright (C) 2012 Sergey Lisitsyn
9
*/
10
11
#ifndef _LINEARMULTICLASSMACHINE_H___
12
#define _LINEARMULTICLASSMACHINE_H___
13
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/features/DotFeatures.h
>
16
#include <
shogun/machine/LinearMachine.h
>
17
#include <
shogun/machine/MulticlassMachine.h
>
18
19
namespace
shogun
20
{
21
22
class
CDotFeatures;
23
class
CLinearMachine;
24
class
CMulticlassStrategy;
25
27
class
CLinearMulticlassMachine
:
public
CMulticlassMachine
28
{
29
public
:
31
CLinearMulticlassMachine
() :
CMulticlassMachine
(),
m_features
(NULL)
32
{
33
SG_ADD
((
CSGObject
**)&
m_features
,
"m_features"
,
"Feature object."
,
34
MS_NOT_AVAILABLE
);
35
}
36
43
CLinearMulticlassMachine
(
CMulticlassStrategy
*strategy,
CDotFeatures
* features,
CLinearMachine
* machine,
CLabels
* labs) :
44
CMulticlassMachine
(strategy,(
CMachine
*)machine,labs),
m_features
(NULL)
45
{
46
set_features
(features);
47
SG_ADD
((
CSGObject
**)&
m_features
,
"m_features"
,
"Feature object."
,
48
MS_NOT_AVAILABLE
);
49
}
50
52
virtual
~CLinearMulticlassMachine
()
53
{
54
SG_UNREF
(
m_features
);
55
}
56
58
virtual
const
char
*
get_name
()
const
59
{
60
return
"LinearMulticlassMachine"
;
61
}
62
67
void
set_features
(
CDotFeatures
* f)
68
{
69
SG_REF
(f);
70
SG_UNREF
(
m_features
);
71
m_features
= f;
72
73
for
(
index_t
i=0; i<
m_machines
->
get_num_elements
(); i++)
74
{
75
CLinearMachine
* machine = (
CLinearMachine
* )
m_machines
->
get_element
(i);
76
machine->
set_features
(f);
77
SG_UNREF
(machine);
78
}
79
}
80
85
CDotFeatures
*
get_features
()
const
86
{
87
SG_REF
(
m_features
);
88
return
m_features
;
89
}
90
91
protected
:
92
94
virtual
bool
init_machine_for_train
(
CFeatures
* data)
95
{
96
if
(!
m_machine
)
97
SG_ERROR
(
"No machine given in Multiclass constructor\n"
)
98
99
if
(data)
100
set_features
((
CDotFeatures
*)data);
101
102
((
CLinearMachine
*)
m_machine
)->set_features(
m_features
);
103
104
return
true
;
105
}
106
108
virtual
bool
init_machines_for_apply
(
CFeatures
* data)
109
{
110
if
(data)
111
set_features
((
CDotFeatures
*)data);
112
113
for
(int32_t i=0; i<
m_machines
->
get_num_elements
(); i++)
114
{
115
CLinearMachine
* machine = (
CLinearMachine
*)
m_machines
->
get_element
(i);
116
ASSERT
(
m_features
)
117
ASSERT
(machine)
118
machine->
set_features
(
m_features
);
119
SG_UNREF
(machine);
120
}
121
122
return
true
;
123
}
124
126
virtual
bool
is_ready
()
127
{
128
if
(
m_features
)
129
return
true
;
130
131
return
false
;
132
}
133
135
virtual
CMachine
*
get_machine_from_trained
(
CMachine
* machine)
136
{
137
return
new
CLinearMachine
((
CLinearMachine
*)machine);
138
}
139
141
virtual
int32_t
get_num_rhs_vectors
()
142
{
143
return
m_features
->
get_num_vectors
();
144
}
145
150
virtual
void
add_machine_subset
(
SGVector<index_t>
subset)
151
{
152
/* changing the subset structure to use subset stacks. This might
153
* have to be revised. Heiko Strathmann */
154
m_features
->
add_subset
(subset);
155
}
156
158
virtual
void
remove_machine_subset
()
159
{
160
/* changing the subset structure to use subset stacks. This might
161
* have to be revised. Heiko Strathmann */
162
m_features
->
remove_subset
();
163
}
164
169
virtual
void
store_model_features
() {}
170
171
protected
:
172
174
CDotFeatures
*
m_features
;
175
};
176
}
177
#endif
SHOGUN
机器学习工具包 - 项目文档