SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
StructuredModel.cpp
浏览该文件的文档.
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 }
Base class of the labels used in Structured Output (SO) problems.
void set_labels(CStructuredLabels *labs)
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
SGVector< float64_t > get_joint_feature_vector(int32_t feat_idx, int32_t lab_idx)
CStructuredLabels * get_labels()
virtual int32_t get_num_aux_con() const
#define SG_REF(x)
Definition: SGObject.h:51
virtual int32_t get_num_aux() const
void set_features(CFeatures *feats)
virtual const char * get_name() const
SGSparseVector< float64_t > get_sparse_joint_feature_vector(int32_t feat_idx, int32_t lab_idx)
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
shogun vector
virtual CStructuredLabels * structured_labels_factory(int32_t num_labels=0)
double float64_t
Definition: common.h:50
virtual void init_primal_opt(float64_t regularization, SGMatrix< float64_t > &A, SGVector< float64_t > a, SGMatrix< float64_t > B, SGVector< float64_t > &b, SGVector< float64_t > &lb, SGVector< float64_t > &ub, SGMatrix< float64_t > &C)
float64_t delta_loss(int32_t ytrue_idx, CStructuredData *ypred)
virtual bool check_training_setup() const
#define SG_UNREF(x)
Definition: SGObject.h:52
CStructuredLabels * m_labels
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
template class SGSparseVector The assumtion is that the stored SGSparseVectorEntry* vector is orde...
CStructuredData * argmax
virtual CStructuredData * get_label(int32_t idx)
#define SG_ADD(...)
Definition: SGObject.h:81
virtual const char * get_name() const
#define delta
Definition: sfa.cpp:23
Base class of the components of StructuredLabels.

SHOGUN 机器学习工具包 - 项目文档