SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StructuredLabels.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) 2012 Fernando José Iglesias García
8  * Copyright (C) 2012 Fernando José Iglesias García
9  */
10 
12 
13 using namespace shogun;
14 
16 : CLabels()
17 {
18  init();
19 }
20 
22 : CLabels()
23 {
24  init();
25  m_labels = new CDynamicObjectArray(num_labels);
27 }
28 
30 {
32 }
33 
34 void CStructuredLabels::ensure_valid(const char* context)
35 {
36  if ( m_labels == NULL )
37  SG_ERROR("Non-valid StructuredLabels in %s", context)
38 }
39 
41 {
43  return m_labels;
44 }
45 
47 {
48  ensure_valid("CStructuredLabels::get_label(int32_t)");
49  if ( idx < 0 || idx >= get_num_labels() )
50  SG_ERROR("Index must be inside [0, num_labels-1]\n")
51 
52  return (CStructuredData*) m_labels->get_element(idx);
53 }
54 
56 {
57  ensure_valid_sdt(label);
58  m_labels->push_back(label);
59 }
60 
62 {
63  ensure_valid_sdt(label);
64  int32_t real_idx = m_subset_stack->subset_idx_conversion(idx);
65 
66  if ( real_idx < get_num_labels() )
67  {
68  return m_labels->set_element(label, real_idx);
69  }
70  else
71  {
72  return false;
73  }
74 }
75 
77 {
78  if ( m_labels == NULL )
79  return 0;
80  else
81  return m_labels->get_num_elements();
82 }
83 
84 void CStructuredLabels::init()
85 {
86  SG_ADD((CSGObject**) &m_labels, "m_labels", "The labels", MS_NOT_AVAILABLE);
87 
88  m_labels = NULL;
90 }
91 
92 void CStructuredLabels::ensure_valid_sdt(CStructuredData* label)
93 {
94  if ( m_sdt == SDT_UNKNOWN )
95  {
97  }
98  else
99  {
100  REQUIRE(label->get_structured_data_type() == m_sdt, "All the labels must "
101  "belong to the same CStructuredData child class\n");
102  }
103 }

SHOGUN Machine Learning Toolbox - Documentation