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), score(0), delta(0)
18 {
19 }
20 
22 {
24 }
25 
27 {
28  return new CStructuredLabels(num_labels);
29 }
30 
31 const char* CResultSet::get_name() const
32 {
33  return "ResultSet";
34 }
35 
37 {
38  init();
39 }
40 
42  CFeatures* features,
43  CStructuredLabels* labels)
44 : CSGObject()
45 {
46  init();
47 
48  set_labels(labels);
49  set_features(features);
50 }
51 
53 {
56 }
57 
59  float64_t regularization,
67 {
68  SG_ERROR("init_primal_opt is not implemented for %s!\n", get_name())
69 }
70 
72 {
73  SG_REF(labels);
75  m_labels = labels;
76 }
77 
79 {
81  return m_labels;
82 }
83 
85 {
86  SG_REF(features);
88  m_features = features;
89 }
90 
92 {
94  return m_features;
95 }
96 
98  int32_t feat_idx,
99  int32_t lab_idx)
100 {
101  CStructuredData* label = m_labels->get_label(lab_idx);
102  SGVector< float64_t > ret = get_joint_feature_vector(feat_idx, label);
103  SG_UNREF(label);
104 
105  return ret;
106 }
107 
109  int32_t feat_idx,
110  CStructuredData* y)
111 {
112  SG_ERROR("compute_joint_feature(int32_t, CStructuredData*) is not "
113  "implemented for %s!\n", get_name());
114 
115  return SGVector< float64_t >();
116 }
117 
119 {
120  REQUIRE(ytrue_idx >= 0 || ytrue_idx < m_labels->get_num_labels(),
121  "The label index must be inside [0, num_labels-1]\n");
122 
123  CStructuredData* ytrue = m_labels->get_label(ytrue_idx);
124  float64_t ret = delta_loss(ytrue, ypred);
125  SG_UNREF(ytrue);
126 
127  return ret;
128 }
129 
131 {
132  SG_ERROR("delta_loss(CStructuredData*, CStructuredData*) is not "
133  "implemented for %s!\n", get_name());
134 
135  return 0.0;
136 }
137 
138 void CStructuredModel::init()
139 {
140  SG_ADD((CSGObject**) &m_labels, "m_labels", "Structured labels",
142  SG_ADD((CSGObject**) &m_features, "m_features", "Feature vectors",
144 
145  m_features = NULL;
146  m_labels = NULL;
147 }
148 
150 {
151  // Nothing to do here
152 }
153 
155 {
156  // Nothing to do here
157  return true;
158 }
159 
161 {
162  return 0;
163 }
164 
166 {
167  return 0;
168 }

SHOGUN Machine Learning Toolbox - Documentation