SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultilabelSOLabels.cpp
Go to the documentation of this file.
1 /*
2  * This software is distributed under BSD 3-clause license (see LICENSE file).
3  *
4  * Written (W) 2013 Thoralf Klein
5  * Written (W) 2014 Abinash Panda
6  * Copyright (C) 2013 Thoralf Klein and Zuse-Institute-Berlin (ZIB)
7  * Copyright (C) 2014 Abinash Panda
8  */
9 
11 
12 using namespace shogun;
13 
15 {
16  init();
17  m_multilabel_labels = NULL;
18 }
19 
22 {
23  init();
24  m_multilabel_labels = new CMultilabelLabels(num_classes);
25 }
26 
27 CMultilabelSOLabels::CMultilabelSOLabels(int32_t num_labels, int32_t num_classes)
29 {
30  init();
31  m_multilabel_labels = new CMultilabelLabels(num_labels, num_classes);
32 }
33 
36 {
37  init();
38  SG_REF(multilabel_labels);
39  m_multilabel_labels = multilabel_labels;
40 }
41 
42 void CMultilabelSOLabels::init()
43 {
44  SG_ADD((CSGObject **)&m_multilabel_labels, "multilabel_labels", "multilabel labels object",
46  SG_ADD(&m_last_set_label, "last_set_label", "index of the last label added using add_label() method",
48 
49  m_last_set_label = 0;
50 }
51 
53 {
54  SG_UNREF(m_multilabel_labels);
55 }
56 
58 {
59  if (m_sdt == SDT_UNKNOWN)
60  {
62  }
63 
64  m_multilabel_labels->set_label(j, label);
65 }
66 
68 {
69  if (m_sdt == SDT_UNKNOWN)
70  {
72  }
73 
74  m_multilabel_labels->set_labels(labels);
75 }
76 
78 {
79  if (m_multilabel_labels == NULL)
80  {
81  return 0;
82  }
83 
84  return m_multilabel_labels->get_num_labels();
85 }
86 
88 {
89  if (m_multilabel_labels == NULL)
90  {
91  return 0;
92  }
93 
94  return m_multilabel_labels->get_num_classes();
95 }
96 
98 {
99  return m_multilabel_labels;
100 }
101 
103 {
104  if (m_sdt == SDT_UNKNOWN)
105  {
106  m_sdt = label->get_structured_data_type();
107  }
108 
110  m_multilabel_labels->set_label(j, slabel->get_data());
111  return true;
112 }
113 
115 {
116  CSparseMultilabel * slabel = new CSparseMultilabel(m_multilabel_labels->get_label(j));
117  SG_REF(slabel);
118  return (CStructuredData *)slabel;
119 }
120 
122 {
123  return m_multilabel_labels->get_label(j);
124 }
125 
126 void CMultilabelSOLabels::ensure_valid(const char * context)
127 {
128  m_multilabel_labels->ensure_valid(context);
129 }
130 
132  int32_t dense_dim, float64_t d_true, float64_t d_false)
133 {
135  SGVector<int32_t> slabel_data = slabel->get_data();
136  return CMultilabelLabels::to_dense<int32_t, float64_t>(&slabel_data,
137  dense_dim, d_true, d_false);
138 }
139 
141 {
142  REQUIRE(m_last_set_label >= 0 && m_last_set_label < get_num_labels(),
143  "Only %d number of labels can be added.\n", get_num_labels());
144 
145  set_label(m_last_set_label, label);
146  m_last_set_label++;
147 }
Base class of the labels used in Structured Output (SO) problems.
virtual void set_sparse_label(int32_t j, SGVector< int32_t > label)
virtual int32_t get_num_labels() const
#define REQUIRE(x,...)
Definition: SGIO.h:206
void set_labels(SGVector< int32_t > *labels)
#define SG_REF(x)
Definition: SGObject.h:54
virtual bool set_label(int32_t j, CStructuredData *label)
virtual EStructuredDataType get_structured_data_type() const
virtual int32_t get_num_classes() const
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
double float64_t
Definition: common.h:50
EStructuredDataType m_sdt
SGVector< int32_t > get_label(int32_t j)
Class CSparseMultilabel to be used in the application of Structured Output (SO) learning to Multilabe...
virtual void set_sparse_labels(SGVector< int32_t > *labels)
virtual void add_label(CStructuredData *label)
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
void set_label(int32_t j, SGVector< int32_t > label)
static SGVector< float64_t > to_dense(CStructuredData *label, int32_t dense_dim, float64_t d_true, float64_t d_false)
virtual int32_t get_num_labels() const
void ensure_valid(const char *context=NULL)
virtual SGVector< int32_t > get_sparse_label(int32_t j)
virtual CStructuredData * get_label(int32_t j)
#define SG_ADD(...)
Definition: SGObject.h:84
virtual int32_t get_num_classes() const
Multilabel Labels for multi-label classification.
Base class of the components of StructuredLabels.
static CSparseMultilabel * obtain_from_generic(CStructuredData *base_data)
SGVector< int32_t > get_data() const
virtual void ensure_valid(const char *context=NULL)
virtual CMultilabelLabels * get_multilabel_labels()

SHOGUN Machine Learning Toolbox - Documentation