SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
virtual void ensure_valid(const char *context=NULL)
virtual int32_t get_num_labels() const
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual int32_t get_num_labels() const =0
#define SG_ERROR(...)
Definition: SGIO.h:129
#define SG_REF(x)
Definition: SGObject.h:51
bool set_element(CSGObject *e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
CData * get_latent_label(int32_t idx)
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
CLabels * get_labels() const
dummy data holder
Definition: Data.h:25
void set_labels(CLabels *labels)
Dynamic array class for CSGObject pointers that creates an array that can be used like a list or an a...
CDynamicObjectArray * get_latent_labels() const
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
CSGObject * get_element(int32_t index) const
void add_latent_label(CData *label)
#define SG_ADD(...)
Definition: SGObject.h:81
CDynamicObjectArray * m_latent_labels
Definition: LatentLabels.h:114
bool set_latent_label(int32_t idx, CData *label)

SHOGUN Machine Learning Toolbox - Documentation