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