-
Notifications
You must be signed in to change notification settings - Fork 1
/
BFSreorder.m
executable file
·30 lines (29 loc) · 1.25 KB
/
BFSreorder.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
% =======================================================================
% author: Xueqing Liu
% =======================================================================
% Chi Wang et al., Towards Interactive Construction of Topical Hierarchy: A
% Recursive Tensor Decomposition Approach, KDD 2015.
% =======================================================================
% re-order each node's children such that nodes corresponding to larger
% alpha is put ahead
% =======================================================================
function BFSreorder(rootnode)
rootalpha = [];
if isempty(rootnode.children) == 0
for i = 1:size(rootnode.children, 2)
rootalpha = [rootalpha, rootnode.children{i}.alpha0];
end
[sortedalpha, ind] = sort(rootalpha, 'descend');
tmp_cell = cell(1, size(rootnode.children, 2));
for i = 1:size(rootnode.children, 2)
tmp_cell{i} = rootnode.children{ind(i)};
end
rootnode.children = tmp_cell;
rootnode.twmatparent = rootnode.twmatparent(ind, :);
rootnode.pz = rootnode.pz(ind);
for i = 1:size(rootnode.children, 2)
BFSreorder(rootnode.children{i});
end
end
end