-
Notifications
You must be signed in to change notification settings - Fork 0
/
FillTree.m
executable file
·76 lines (56 loc) · 1.68 KB
/
FillTree.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function tree = FillTree(cur_idx, L_weights, tree)
global Features;
global Labels;
to_open_que = zeros(1,length(tree));
to_open_que(1) = 1;
node_idx = false(length(tree), sum(cur_idx));
node_idx(1,:) = true;
leafs = false(1, length(tree));
L_table = zeros(33, sum(cur_idx));
for l = 1 : 33
L_table(l,:) = (Labels(cur_idx) == l)' * L_weights(l);
end
que_cur = 1;
que_end = 1;
while que_cur <= que_end
cur_node = to_open_que(que_cur);
if ~tree{cur_node}.isleaf
left_idx = (Features(tree{cur_node}.dim,cur_idx) <= tree{cur_node}.thr);
right_idx = ~left_idx;
left_idx = node_idx(cur_node,:) & left_idx;
node_idx(tree{cur_node}.left_ch,:) = left_idx;
right_idx = node_idx(cur_node,:) & right_idx;
node_idx(tree{cur_node}.right_ch,:) = right_idx;
if( sum(left_idx) > 0)
to_open_que(que_end+1) = tree{cur_node}.left_ch;
que_end = que_end + 1;
end
if( sum(right_idx) > 0)
to_open_que(que_end+1) = tree{cur_node}.right_ch;
que_end = que_end + 1;
end
%to_open_que = [to_open_que tree{cur_node}.left_ch tree{cur_node}.right_ch];
else
leafs(cur_node) = true;
end
que_cur = que_cur + 1;
end
%%
for i = 1:length(tree)
if tree{i}.isleaf
leafs(i) = true;
end
end
tot_labels = 33;%max(Labels);
L_table = L_table';
%node_idx = real(node_idx);
BigProbs = node_idx(leafs,:) * L_table;
k = 1;
for i = find(leafs)
if(sum(BigProbs(k,:) > 0))
tree{i}.probs = BigProbs(k,:) / sum(BigProbs(k,:));
else
tree{i}.probs = zeros(1,33);
end
k = k + 1;
end