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
structure
StructuredModel.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/structure/StructuredModel.h
>
13
14
using namespace
shogun;
15
16
CResultSet::CResultSet
() :
CSGObject
(), argmax(NULL)
17
{
18
}
19
20
CResultSet::~CResultSet
()
21
{
22
SG_UNREF
(
argmax
)
23
}
24
25
CStructuredLabels
*
CStructuredModel::structured_labels_factory
(int32_t num_labels)
26
{
27
return
new
CStructuredLabels
(num_labels);
28
}
29
30
const
char
*
CResultSet::get_name
()
const
31
{
32
return
"ResultSet"
;
33
}
34
35
CStructuredModel::CStructuredModel
() :
CSGObject
()
36
{
37
init();
38
}
39
40
CStructuredModel::CStructuredModel
(
41
CFeatures
* features,
42
CStructuredLabels
* labels)
43
:
CSGObject
()
44
{
45
init();
46
47
set_labels
(labels);
48
set_features
(features);
49
}
50
51
CStructuredModel::~CStructuredModel
()
52
{
53
SG_UNREF
(
m_labels
);
54
SG_UNREF
(
m_features
);
55
}
56
57
void
CStructuredModel::init_primal_opt
(
58
float64_t
regularization,
59
SGMatrix< float64_t >
& A,
60
SGVector< float64_t >
a,
61
SGMatrix< float64_t >
B,
62
SGVector< float64_t >
& b,
63
SGVector< float64_t >
lb,
64
SGVector< float64_t >
ub,
65
SGMatrix< float64_t >
& C)
66
{
67
SG_ERROR
(
"init_primal_opt is not implemented for %s!\n"
,
get_name
())
68
}
69
70
void
CStructuredModel::set_labels
(
CStructuredLabels
* labels)
71
{
72
SG_REF
(labels);
73
SG_UNREF
(
m_labels
);
74
m_labels
= labels;
75
}
76
77
CStructuredLabels
*
CStructuredModel::get_labels
()
78
{
79
SG_REF
(
m_labels
);
80
return
m_labels
;
81
}
82
83
void
CStructuredModel::set_features
(
CFeatures
* features)
84
{
85
SG_REF
(features);
86
SG_UNREF
(
m_features
);
87
m_features
= features;
88
}
89
90
CFeatures
*
CStructuredModel::get_features
()
91
{
92
SG_REF
(
m_features
);
93
return
m_features
;
94
}
95
96
SGVector< float64_t >
CStructuredModel::get_joint_feature_vector
(
97
int32_t feat_idx,
98
int32_t lab_idx)
99
{
100
CStructuredData
* label =
m_labels
->
get_label
(lab_idx);
101
SGVector< float64_t >
ret =
get_joint_feature_vector
(feat_idx, label);
102
SG_UNREF
(label);
103
104
return
ret;
105
}
106
107
SGVector< float64_t >
CStructuredModel::get_joint_feature_vector
(
108
int32_t feat_idx,
109
CStructuredData
* y)
110
{
111
SG_ERROR
(
"compute_joint_feature(int32_t, CStructuredData*) is not "
112
"implemented for %s!\n"
,
get_name
());
113
114
return
SGVector< float64_t >
();
115
}
116
117
float64_t
CStructuredModel::delta_loss
(int32_t ytrue_idx,
CStructuredData
* ypred)
118
{
119
REQUIRE
(ytrue_idx >= 0 || ytrue_idx < m_labels->get_num_labels(),
120
"The label index must be inside [0, num_labels-1]\n"
);
121
122
CStructuredData
* ytrue =
m_labels
->
get_label
(ytrue_idx);
123
float64_t
ret =
delta_loss
(ytrue, ypred);
124
SG_UNREF
(ytrue);
125
126
return
ret;
127
}
128
129
float64_t
CStructuredModel::delta_loss
(
CStructuredData
* y1,
CStructuredData
* y2)
130
{
131
SG_ERROR
(
"delta_loss(CStructuredData*, CStructuredData*) is not "
132
"implemented for %s!\n"
,
get_name
());
133
134
return
0.0;
135
}
136
137
void
CStructuredModel::init()
138
{
139
SG_ADD
((
CSGObject
**) &
m_labels
,
"m_labels"
,
"Structured labels"
,
140
MS_NOT_AVAILABLE
);
141
SG_ADD
((
CSGObject
**) &
m_features
,
"m_features"
,
"Feature vectors"
,
142
MS_NOT_AVAILABLE
);
143
144
m_features
= NULL;
145
m_labels
= NULL;
146
}
147
148
void
CStructuredModel::init_training
()
149
{
150
// Nothing to do here
151
}
152
153
bool
CStructuredModel::check_training_setup
()
const
154
{
155
// Nothing to do here
156
return
true
;
157
}
158
159
int32_t
CStructuredModel::get_num_aux
()
const
160
{
161
return
0;
162
}
163
164
int32_t
CStructuredModel::get_num_aux_con
()
const
165
{
166
return
0;
167
}
SHOGUN
Machine Learning Toolbox - Documentation