SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
machine
LinearStructuredOutputMachine.cpp
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) 2012 Fernando José Iglesias García
8
* Copyright (C) 2012 Fernando José Iglesias García
9
*/
10
11
#include <
shogun/machine/LinearStructuredOutputMachine.h
>
12
#include <
shogun/structure/MulticlassSOLabels.h
>
13
14
using namespace
shogun;
15
16
CLinearStructuredOutputMachine::CLinearStructuredOutputMachine
()
17
:
CStructuredOutputMachine
()
18
{
19
register_parameters();
20
}
21
22
CLinearStructuredOutputMachine::CLinearStructuredOutputMachine
(
23
CStructuredModel
* model,
24
CStructuredLabels
* labs)
25
:
CStructuredOutputMachine
(model, labs)
26
{
27
register_parameters();
28
}
29
30
CLinearStructuredOutputMachine::~CLinearStructuredOutputMachine
()
31
{
32
}
33
34
void
CLinearStructuredOutputMachine::set_w
(
SGVector< float64_t >
w)
35
{
36
m_w
= w;
37
}
38
39
SGVector< float64_t >
CLinearStructuredOutputMachine::get_w
()
const
40
{
41
return
m_w
;
42
}
43
44
CStructuredLabels
*
CLinearStructuredOutputMachine::apply_structured
(
CFeatures
* data)
45
{
46
if
(data)
47
{
48
set_features
(data);
49
}
50
51
CStructuredLabels
* out;
52
CFeatures
* model_features = this->
get_features
();
53
if
(!model_features)
54
{
55
out =
new
CStructuredLabels
();
56
}
57
else
58
{
59
out =
new
CStructuredLabels
(model_features->
get_num_vectors
());
60
for
( int32_t i = 0 ; i < model_features->
get_num_vectors
() ; ++i )
61
{
62
CResultSet
* result =
m_model
->
argmax
(
m_w
, i,
false
);
63
out->
add_label
(result->
argmax
);
64
65
SG_UNREF
(result);
66
}
67
}
68
SG_UNREF
(model_features);
69
return
out;
70
}
71
72
void
CLinearStructuredOutputMachine::register_parameters()
73
{
74
SG_ADD
(&
m_w
,
"m_w"
,
"Weight vector"
,
MS_NOT_AVAILABLE
);
75
}
76
77
void
CLinearStructuredOutputMachine::store_model_features
()
78
{
79
}
SHOGUN
Machine Learning Toolbox - Documentation