SHOGUN  3.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
13 
14 using namespace shogun;
15 
17 : CSGObject(), argmax(NULL),
18  psi_computed_sparse(false),
19  psi_computed(false),
20  psi_truth(SGVector<float64_t>(0)),
21  psi_pred(SGVector<float64_t>(0)),
22  psi_truth_sparse(SGSparseVector<float64_t>(0)),
23  psi_pred_sparse(SGSparseVector<float64_t>(0)),
24  score(0),
25  delta(0)
26 {
27 }
28 
30 {
32 }
33 
35 {
36  return new CStructuredLabels(num_labels);
37 }
38 
39 const char* CResultSet::get_name() const
40 {
41  return "ResultSet";
42 }
43 
45 {
46  init();
47 }
48 
50  CFeatures* features,
51  CStructuredLabels* labels)
52 : CSGObject()
53 {
54  init();
55 
56  set_labels(labels);
57  set_features(features);
58 }
59 
61 {
64 }
65 
67  float64_t regularization,
75 {
76  SG_ERROR("init_primal_opt is not implemented for %s!\n", get_name())
77 }
78 
80 {
81  SG_REF(labels);
83  m_labels = labels;
84 }
85 
87 {
89  return m_labels;
90 }
91 
93 {
94  SG_REF(features);
96  m_features = features;
97 }
98 
100 {
102  return m_features;
103 }
104 
106  int32_t feat_idx,
107  int32_t lab_idx)
108 {
109  CStructuredData* label = m_labels->get_label(lab_idx);
110  SGVector< float64_t > ret = get_joint_feature_vector(feat_idx, label);
111  SG_UNREF(label);
112 
113  return ret;
114 }
115 
117  int32_t feat_idx,
118  CStructuredData* y)
119 {
120  SG_ERROR("compute_joint_feature(int32_t, CStructuredData*) is not "
121  "implemented for %s!\n", get_name());
122 
123  return SGVector< float64_t >();
124 }
125 
127  int32_t feat_idx,
128  int32_t lab_idx)
129 {
130  CStructuredData* label = m_labels->get_label(lab_idx);
132  SG_UNREF(label);
133 
134  return ret;
135 }
136 
138  int32_t feat_idx,
139  CStructuredData* y)
140 {
141  SG_ERROR("compute_sparse_joint_feature(int32_t, CStructuredData*) is not "
142  "implemented for %s!\n", get_name());
143 
145 }
146 
148 {
149  REQUIRE(ytrue_idx >= 0 || ytrue_idx < m_labels->get_num_labels(),
150  "The label index must be inside [0, num_labels-1]\n");
151 
152  CStructuredData* ytrue = m_labels->get_label(ytrue_idx);
153  float64_t ret = delta_loss(ytrue, ypred);
154  SG_UNREF(ytrue);
155 
156  return ret;
157 }
158 
160 {
161  SG_ERROR("delta_loss(CStructuredData*, CStructuredData*) is not "
162  "implemented for %s!\n", get_name());
163 
164  return 0.0;
165 }
166 
167 void CStructuredModel::init()
168 {
169  SG_ADD((CSGObject**) &m_labels, "m_labels", "Structured labels",
171  SG_ADD((CSGObject**) &m_features, "m_features", "Feature vectors",
173 
174  m_features = NULL;
175  m_labels = NULL;
176 }
177 
179 {
180  // Nothing to do here
181 }
182 
184 {
185  // Nothing to do here
186  return true;
187 }
188 
190 {
191  return 0;
192 }
193 
195 {
196  return 0;
197 }

SHOGUN Machine Learning Toolbox - Documentation