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
multiclass
tree
VwConditionalProbabilityTree.h
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 Chiyuan Zhang
8
* Copyright (C) 2012 Chiyuan Zhang
9
*/
10
11
#ifndef CONDITIONALPROBABILITYTREE_H__
12
#define CONDITIONALPROBABILITYTREE_H__
13
14
#include <map>
15
16
#include <
shogun/multiclass/tree/TreeMachine.h
>
17
#include <
shogun/classifier/vw/VowpalWabbit.h
>
18
19
namespace
shogun
20
{
21
23
struct
VwConditionalProbabilityTreeNodeData
24
{
26
int32_t
label
;
28
float64_t
p_right
;
29
31
VwConditionalProbabilityTreeNodeData
():
label
(-1),
p_right
(0) {}
32
};
33
35
class
CVwConditionalProbabilityTree
:
public
CTreeMachine
<VwConditionalProbabilityTreeNodeData>
36
{
37
public
:
38
typedef
CTreeMachineNode<VwConditionalProbabilityTreeNodeData>
node_t
;
39
41
CVwConditionalProbabilityTree
(int32_t num_passes=1)
42
:
m_num_passes
(num_passes),
m_feats
(NULL)
43
{
44
}
45
47
virtual
~CVwConditionalProbabilityTree
() {}
48
50
virtual
const
char
*
get_name
()
const
{
return
"VwConditionalProbabilityTree"
; }
51
53
void
set_num_passes
(int32_t num_passes)
54
{
55
m_num_passes
= num_passes;
56
}
57
59
int32_t
get_num_passes
()
const
60
{
61
return
m_num_passes
;
62
}
63
67
void
set_features
(
CStreamingVwFeatures
*feats)
68
{
69
SG_REF
(feats);
70
SG_UNREF
(
m_feats
);
71
m_feats
= feats;
72
}
73
75
virtual
CMulticlassLabels
*
apply_multiclass
(
CFeatures
* data=NULL);
76
78
virtual
int32_t
apply_multiclass_example
(
VwExample
* ex);
79
protected
:
81
virtual
bool
train_require_labels
()
const
{
return
false
; }
82
89
virtual
bool
train_machine
(
CFeatures
* data);
90
94
void
train_example
(
VwExample
*ex);
95
100
void
train_path
(
VwExample
*ex,
node_t
*
node
);
101
107
float64_t
train_node
(
VwExample
*ex,
node_t
*
node
);
108
112
int32_t
create_machine
(
VwExample
*ex);
113
119
virtual
bool
which_subtree
(
node_t
*
node
,
VwExample
*ex)=0;
120
122
void
compute_conditional_probabilities
(
VwExample
*ex);
123
127
float64_t
accumulate_conditional_probability
(
node_t
*leaf);
128
129
int32_t
m_num_passes
;
130
std::map<int32_t, node_t*>
m_leaves
;
131
CStreamingVwFeatures
*
m_feats
;
132
};
133
134
}
/* shogun */
135
136
#endif
/* end of include guard: CONDITIONALPROBABILITYTREE_H__ */
137
SHOGUN
Machine Learning Toolbox - Documentation