SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
transfer
multitask
Task.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/transfer/multitask/Task.h
>
11
12
using namespace
shogun;
13
14
CTask::CTask
() :
CSGObject
()
15
{
16
init();
17
18
m_weight
= 0.0;
19
m_name
=
"task"
;
20
}
21
22
CTask::CTask
(
index_t
min_index,
index_t
max_index,
23
float64_t
weight,
const
char
* name) :
24
CSGObject
()
25
{
26
init();
27
28
REQUIRE
(min_index<max_index,
"min index should be less than max index"
)
29
m_indices
=
SGVector<index_t>
(max_index-min_index);
30
for
(int32_t i=0; i<
m_indices
.
vlen
; i++)
31
m_indices
[i] = i+min_index;
32
m_weight
= weight;
33
m_name
= name;
34
}
35
36
CTask::CTask
(
SGVector<index_t>
indices,
37
float64_t
weight,
const
char
* name) :
38
CSGObject
()
39
{
40
init();
41
42
m_indices
= indices;
43
}
44
45
void
CTask::init()
46
{
47
m_subtasks
=
new
CList
(
true
);
48
SG_REF
(
m_subtasks
);
49
50
SG_ADD
((
CSGObject
**)&
m_subtasks
,
"subtasks"
,
"subtasks of given task"
,
MS_NOT_AVAILABLE
);
51
SG_ADD
(&
m_indices
,
"indices"
,
"indices of task"
,
MS_NOT_AVAILABLE
);
52
SG_ADD
(&
m_weight
,
"weight"
,
"weight of task"
,
MS_NOT_AVAILABLE
);
53
}
54
55
CTask::~CTask
()
56
{
57
SG_UNREF
(
m_subtasks
);
58
}
59
60
bool
CTask::is_contiguous
()
61
{
62
REQUIRE
(
m_indices
.
vlen
>1,
"Task indices vector must not be empty or contain only one element"
)
63
bool
result =
true
;
64
for
(int32_t i=0; i<
m_indices
.
vlen
-1; i++)
65
{
66
if
(
m_indices
[i]!=
m_indices
[i+1]-1)
67
{
68
result =
false
;
69
break
;
70
}
71
}
72
73
return
result;
74
}
75
76
void
CTask::add_subtask
(
CTask
* subtask)
77
{
78
SGVector<index_t>
subtask_indices = subtask->
get_indices
();
79
for
(int32_t i=0; i<subtask_indices.
vlen
; i++)
80
{
81
bool
found =
false
;
82
for
(int32_t j=0; j<
m_indices
.
vlen
; j++)
83
{
84
if
(subtask_indices[i] ==
m_indices
[j])
85
{
86
found =
true
;
87
break
;
88
}
89
}
90
if
(!found)
91
SG_ERROR
(
"Subtask contains indices that are not contained in this task\n"
)
92
}
93
m_subtasks
->
append_element
(subtask);
94
}
95
96
CList
*
CTask::get_subtasks
()
97
{
98
SG_REF
(
m_subtasks
);
99
return
m_subtasks
;
100
}
101
102
int32_t
CTask::get_num_subtasks
()
103
{
104
return
m_subtasks
->
get_num_elements
();
105
}
SHOGUN
机器学习工具包 - 项目文档