SHOGUN  v3.0.0
 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 
16 CResultSet::CResultSet() : CSGObject(), argmax(NULL)
17 {
18 }
19 
21 {
23 }
24 
25 const char* CResultSet::get_name() const
26 {
27  return "ResultSet";
28 }
29 
31 {
32  init();
33 }
34 
36  CFeatures* features,
37  CStructuredLabels* labels)
38 : CSGObject()
39 {
40  init();
41 
42  set_labels(labels);
43  set_features(features);
44 }
45 
47 {
50 }
51 
53  float64_t regularization,
61 {
62  SG_ERROR("init_primal_opt is not implemented for %s!\n", get_name())
63 }
64 
66 {
67  SG_REF(labels);
69  m_labels = labels;
70 }
71 
73 {
75  return m_labels;
76 }
77 
79 {
80  SG_REF(features);
82  m_features = features;
83 }
84 
86 {
88  return m_features;
89 }
90 
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 
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 
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 
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",
136  SG_ADD((CSGObject**) &m_features, "m_features", "Feature vectors",
138 
139  m_features = NULL;
140  m_labels = NULL;
141 }
142 
144 {
145  // Nothing to do here
146 }
147 
149 {
150  // Nothing to do here
151  return true;
152 }
153 
155 {
156  return 0;
157 }
158 
160 {
161  return 0;
162 }
163 

SHOGUN Machine Learning Toolbox - Documentation