SHOGUN  v3.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  set_labels(labels);
34 
35  int32_t num_labels = 0;
36  if (m_labels)
37  num_labels = m_labels->get_num_labels();
38 
39  m_latent_labels = new CDynamicObjectArray(num_labels);
41 }
42 
44 {
47 }
48 
49 void CLatentLabels::init()
50 {
51  SG_ADD((CSGObject**) &m_latent_labels, "m_latent_labels", "The latent labels", MS_NOT_AVAILABLE);
52  SG_ADD((CSGObject**) &m_labels, "m_labels", "The labels", MS_NOT_AVAILABLE);
53  m_latent_labels = NULL;
54  m_labels = NULL;
55 }
56 
58 {
60  return m_latent_labels;
61 }
62 
64 {
65  ASSERT(m_latent_labels != NULL)
66  if (idx < 0 || idx >= get_num_labels())
67  SG_ERROR("Out of index!\n")
68 
69  return (CData*) m_latent_labels->get_element(idx);
70 }
71 
73 {
74  ASSERT(m_latent_labels != NULL)
75  m_latent_labels->push_back(label);
76 }
77 
78 bool CLatentLabels::set_latent_label(int32_t idx, CData* label)
79 {
80  if (idx < get_num_labels())
81  {
82  return m_latent_labels->set_element(label, idx);
83  }
84  else
85  {
86  return false;
87  }
88 }
89 
90 void CLatentLabels::ensure_valid(const char* context)
91 {
92  if (m_latent_labels == NULL)
93  SG_ERROR("Non-valid LatentLabels in %s", context)
94 }
95 
97 {
98  if (!m_latent_labels || !m_labels)
99  return 0;
100  int32_t num_labels = m_latent_labels->get_num_elements();
101 
102  ASSERT(num_labels == m_labels->get_num_labels())
103 
104  return num_labels;
105 }
106 
108 {
109  SG_REF(labels);
111  m_labels = labels;
112 }
113 
115 {
116  SG_REF(m_labels);
117  return m_labels;
118 }
119 

SHOGUN Machine Learning Toolbox - Documentation