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
Labels.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) 1999-2009 Soeren Sonnenburg
8
* Written (W) 1999-2008 Gunnar Raetsch
9
* Written (W) 2011-2012 Heiko Strathmann
10
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
11
*/
12
13
#include <
shogun/labels/Labels.h
>
14
#include <
shogun/lib/common.h
>
15
#include <
shogun/io/SGIO.h
>
16
#include <
shogun/base/Parameter.h
>
17
18
using namespace
shogun;
19
20
CLabels::CLabels
()
21
:
CSGObject
()
22
{
23
init();
24
}
25
26
CLabels::~CLabels
()
27
{
28
SG_UNREF
(
m_subset_stack
);
29
}
30
31
void
CLabels::init()
32
{
33
SG_ADD
((
CSGObject
**)&
m_subset_stack
,
"subset_stack"
,
34
"Current subset stack"
,
MS_NOT_AVAILABLE
);
35
36
m_subset_stack
=
new
CSubsetStack
();
37
SG_REF
(
m_subset_stack
);
38
}
39
40
void
CLabels::add_subset
(
SGVector<index_t>
subset)
41
{
42
m_subset_stack
->
add_subset
(subset);
43
}
44
45
void
CLabels::remove_subset
()
46
{
47
m_subset_stack
->
remove_subset
();
48
}
49
50
void
CLabels::remove_all_subsets
()
51
{
52
m_subset_stack
->
remove_all_subsets
();
53
}
54
55
float64_t
CLabels::get_value
(int32_t idx)
56
{
57
ASSERT
(
m_current_values
.
vector
&& idx<
get_num_labels
())
58
int32_t real_num=
m_subset_stack
->
subset_idx_conversion
(idx);
59
return
m_current_values
.
vector
[real_num];
60
}
61
62
void
CLabels::set_value
(
float64_t
value, int32_t idx)
63
{
64
65
REQUIRE
(
m_current_values
.
vector
,
"%s::set_value(%f, %d): No values vector"
66
" set!\n"
,
get_name
(), value, idx);
67
REQUIRE
(
get_num_labels
(),
"%s::set_value(%f, %d): Number of values is "
68
"zero!\n"
,
get_name
(), value, idx);
69
70
int32_t real_num=
m_subset_stack
->
subset_idx_conversion
(idx);
71
m_current_values
.
vector
[real_num]=value;
72
}
73
74
void
CLabels::set_values
(
SGVector<float64_t>
values)
75
{
76
if
(
m_current_values
.
vlen
!=0 &&
m_current_values
.
vlen
!=
get_num_labels
())
77
{
78
SG_ERROR
(
"length of value values should match number of labels or"
79
" have zero length (len(labels)=%d, len(values)=%d)\n"
,
80
get_num_labels
(), values.
vlen
);
81
}
82
83
m_current_values
=values;
84
}
85
86
SGVector<float64_t>
CLabels::get_values
()
87
{
88
return
m_current_values
;
89
}
SHOGUN
Machine Learning Toolbox - Documentation