SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LatentLabels.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 Viktor Gal
8  * Copyright (C) 2012 Viktor Gal
9  */
10 
12 
13 using namespace shogun;
14 
16  : CLabels()
17 {
18  init();
19 }
20 
21 CLatentLabels::CLatentLabels(int32_t num_samples)
22  : CLabels()
23 {
24  init();
25  m_latent_labels = new CDynamicObjectArray(num_samples);
27 }
28 
30  : CLabels()
31 {
32  init();
33  m_labels = labels;
37 }
38 
40 {
43 }
44 
45 void CLatentLabels::init()
46 {
47  SG_ADD((CSGObject**) &m_latent_labels, "m_latent_labels", "The latent labels", MS_NOT_AVAILABLE);
48  SG_ADD((CSGObject**) &m_labels, "m_labels", "The labels", MS_NOT_AVAILABLE);
49  m_latent_labels = NULL;
50  m_labels = NULL;
51 }
52 
54 {
56  return m_latent_labels;
57 }
58 
60 {
61  ASSERT(m_latent_labels != NULL);
62  if (idx < 0 || idx >= get_num_labels())
63  SG_ERROR("Out of index!\n");
64 
65  return (CData*) m_latent_labels->get_element(idx);
66 }
67 
69 {
70  ASSERT(m_latent_labels != NULL);
71  m_latent_labels->push_back(label);
72 }
73 
74 bool CLatentLabels::set_latent_label(int32_t idx, CData* label)
75 {
76  if (idx < get_num_labels())
77  {
78  return m_latent_labels->set_element(label, idx);
79  }
80  else
81  {
82  return false;
83  }
84 }
85 
86 void CLatentLabels::ensure_valid(const char* context)
87 {
88  if (m_latent_labels == NULL)
89  SG_ERROR("Non-valid LatentLabels in %s", context);
90 }
91 
93 {
94  ASSERT(base_labels != NULL);
95  if (base_labels->get_label_type() == LT_LATENT)
96  return (CLatentLabels*) base_labels;
97  else
98  SG_SERROR("base_labels must be of dynamic type CLatentLabels\n");
99 
100  return NULL;
101 }
102 
104 {
105  if (!m_latent_labels || !m_labels)
106  return 0;
107  int32_t num_labels = m_latent_labels->get_num_elements();
108 
109  ASSERT(num_labels == m_labels->get_num_labels());
110 
111  return num_labels;
112 }
113 
115 {
117  SG_REF(labels);
118  m_labels = labels;
119 }
120 
122 {
123  SG_REF(m_labels);
124  return m_labels;
125 }
126 

SHOGUN Machine Learning Toolbox - Documentation