SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
labels
MulticlassMultipleOutputLabels.cpp
浏览该文件的文档.
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
* Copyright (C) 2012 Sergey Lisitsyn
8
*/
9
10
#include <
shogun/labels/MulticlassMultipleOutputLabels.h
>
11
12
using namespace
shogun;
13
14
CMulticlassMultipleOutputLabels::CMulticlassMultipleOutputLabels
()
15
:
CLabels
()
16
{
17
init();
18
}
19
20
CMulticlassMultipleOutputLabels::CMulticlassMultipleOutputLabels
(int32_t num_labels)
21
:
CLabels
()
22
{
23
init();
24
m_labels
= SG_MALLOC(
SGVector<index_t>
, num_labels);
25
m_n_labels
= num_labels;
26
}
27
28
CMulticlassMultipleOutputLabels::~CMulticlassMultipleOutputLabels
()
29
{
30
SG_FREE(
m_labels
);
31
}
32
33
void
CMulticlassMultipleOutputLabels::ensure_valid
(
const
char
* context)
34
{
35
if
(
m_labels
== NULL )
36
SG_ERROR
(
"Non-valid MulticlassMultipleOutputLabels in %s"
, context)
37
}
38
39
SGMatrix<index_t>
CMulticlassMultipleOutputLabels::get_labels
()
const
40
{
41
if
(
m_n_labels
==0)
42
return
SGMatrix<index_t>
();
43
int
n_outputs =
m_labels
[0].
vlen
;
44
SGMatrix<index_t>
labels(
m_n_labels
,n_outputs);
45
for
(int32_t i=0; i<
m_n_labels
; i++)
46
{
47
for
(int32_t j=0; j<n_outputs; j++)
48
labels(i,j) =
m_labels
[i][j];
49
}
50
return
labels;
51
}
52
53
SGVector<index_t>
CMulticlassMultipleOutputLabels::get_label
(int32_t idx)
54
{
55
ensure_valid
(
"CMulticlassMultipleOutputLabels::get_label(int32_t)"
);
56
if
( idx < 0 || idx >=
get_num_labels
() )
57
SG_ERROR
(
"Index must be inside [0, num_labels-1]\n"
)
58
59
return
m_labels
[
m_subset_stack
->
subset_idx_conversion
(idx)];
60
}
61
62
bool
CMulticlassMultipleOutputLabels::set_label
(int32_t idx,
SGVector<index_t>
label)
63
{
64
int32_t real_idx =
m_subset_stack
->
subset_idx_conversion
(idx);
65
66
if
(real_idx <
get_num_labels
())
67
{
68
m_labels
[real_idx] = label;
69
return
true
;
70
}
71
else
72
return
false
;
73
}
74
75
int32_t
CMulticlassMultipleOutputLabels::get_num_labels
()
const
76
{
77
return
m_n_labels
;
78
}
79
80
void
CMulticlassMultipleOutputLabels::init()
81
{
82
m_labels
= NULL;
83
m_n_labels
= 0;
84
}
SHOGUN
机器学习工具包 - 项目文档