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