SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
labels
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
11
#include <
shogun/labels/LatentLabels.h
>
12
13
using namespace
shogun;
14
15
CLatentLabels::CLatentLabels
()
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);
26
SG_REF
(
m_latent_labels
);
27
}
28
29
CLatentLabels::CLatentLabels
(
CLabels
* labels)
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);
40
SG_REF
(
m_latent_labels
);
41
}
42
43
CLatentLabels::~CLatentLabels
()
44
{
45
SG_UNREF
(
m_latent_labels
);
46
SG_UNREF
(
m_labels
);
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
57
CDynamicObjectArray
*
CLatentLabels::get_latent_labels
()
const
58
{
59
SG_REF
(
m_latent_labels
);
60
return
m_latent_labels
;
61
}
62
63
CData
*
CLatentLabels::get_latent_label
(int32_t idx)
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
72
void
CLatentLabels::add_latent_label
(
CData
* label)
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
96
int32_t
CLatentLabels::get_num_labels
()
const
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
107
void
CLatentLabels::set_labels
(
CLabels
* labels)
108
{
109
SG_REF
(labels);
110
SG_UNREF
(
m_labels
);
111
m_labels
= labels;
112
}
113
114
CLabels
*
CLatentLabels::get_labels
()
const
115
{
116
SG_REF
(
m_labels
);
117
return
m_labels
;
118
}
119
SHOGUN
Machine Learning Toolbox - Documentation