SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
multiclass
tree
TreeMachineNode.h
浏览该文件的文档.
1
/*
2
* Copyright (c) The Shogun Machine Learning Toolbox
3
* Written (w) 2012 Chiyuan Zhang
4
* Written (w) 2014 Parijat Mazumdar
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
*
10
* 1. Redistributions of source code must retain the above copyright notice, this
11
* list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright notice,
13
* this list of conditions and the following disclaimer in the documentation
14
* and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*
27
* The views and conclusions contained in the software and documentation are those
28
* of the authors and should not be interpreted as representing official policies,
29
* either expressed or implied, of the Shogun Development Team.
30
*/
31
32
#ifndef TREEMACHINENODE_H__
33
#define TREEMACHINENODE_H__
34
35
#include <
shogun/base/SGObject.h
>
36
#include <
shogun/base/Parameter.h
>
37
#include <
shogun/lib/DynamicObjectArray.h
>
38
39
namespace
shogun
40
{
41
49
template
<
typename
T>
50
class
CTreeMachineNode
51
:
public
CSGObject
52
{
53
public
:
55
CTreeMachineNode
() :
CSGObject
()
56
{
57
init();
58
}
59
61
virtual
~CTreeMachineNode
()
62
{
63
for
(int32_t i=0;i<
m_children
->
get_num_elements
();i++)
64
{
65
CTreeMachineNode
* child=(
CTreeMachineNode
*)
m_children
->
get_element
(i);
66
child->
parent
(NULL);
67
SG_UNREF
(child);
68
}
69
SG_UNREF
(
m_children
);
70
}
71
75
virtual
const
char
*
get_name
()
const
{
return
"TreeMachineNode"
; }
76
80
void
machine
(int32_t idx)
81
{
82
m_machine
=idx;
83
}
84
88
int32_t
machine
()
89
{
90
return
m_machine
;
91
}
92
96
void
parent
(
CTreeMachineNode
* par)
97
{
98
m_parent
=par;
99
}
100
104
CTreeMachineNode
*
parent
()
105
{
106
return
m_parent
;
107
}
108
112
virtual
void
set_children
(
CDynamicObjectArray
* children)
113
{
114
m_children
->
reset_array
();
115
for
(int32_t i=0; i<children->
get_num_elements
(); i++)
116
{
117
CTreeMachineNode
* child=(
CTreeMachineNode
*) children->
get_element
(i);
118
add_child
(child);
119
SG_UNREF
(child);
120
}
121
}
122
126
virtual
void
add_child
(
CTreeMachineNode
* child)
127
{
128
m_children
->
push_back
(child);
129
child->
parent
(
this
);
130
}
131
135
virtual
CDynamicObjectArray
*
get_children
()
136
{
137
SG_REF
(
m_children
);
138
return
m_children
;
139
}
140
142
typedef
void (*
data_print_func_t
) (
const
T&);
143
147
void
debug_print
(
data_print_func_t
data_print_func)
148
{
149
debug_print_impl
(data_print_func,
this
, 0);
150
}
151
152
protected
:
158
static
void
debug_print_impl
(
data_print_func_t
data_print_func,
159
CTreeMachineNode<T>
*
node
, int32_t depth)
160
{
161
for
(int32_t i=0;i<depth;++i)
162
SG_SPRINT
(
" "
);
163
164
data_print_func(node->
data
);
165
166
CDynamicObjectArray
* children_vector=node->
get_children
();
167
for
(int32_t j=0;j<children_vector->
get_num_elements
();j++)
168
{
169
CTreeMachineNode<T>
* child=(
CTreeMachineNode<T>
*)
170
children_vector->
get_element
(j);
171
debug_print_impl
(data_print_func,child,depth+1);
172
SG_UNREF
(child);
173
}
174
175
SG_UNREF
(children_vector);
176
}
177
178
private
:
179
/* initialize parameters in constructor */
180
void
init()
181
{
182
m_parent
=NULL;
183
m_machine
=-1;
184
m_children
=
new
CDynamicObjectArray
();
185
SG_REF
(
m_children
);
186
SG_ADD
((
CSGObject
**)&
m_parent
,
"m_parent"
,
"Parent node"
,
MS_NOT_AVAILABLE
);
187
SG_ADD
(&
m_machine
,
"m_machine"
,
"Index of associated machine"
,
MS_NOT_AVAILABLE
);
188
}
189
190
public
:
192
T
data
;
193
194
protected
:
195
/* parent node */
196
CTreeMachineNode
*
m_parent
;
197
198
/* machine index */
199
int32_t
m_machine
;
200
201
/* Dynamic array of pointers to children */
202
CDynamicObjectArray
*
m_children
;
203
204
};
205
206
}
/* namespace shogun */
207
208
#endif
/* end of include guard: TREEMACHINENODE_H__ */
209
SHOGUN
机器学习工具包 - 项目文档