-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.m
85 lines (70 loc) · 2.25 KB
/
tree.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
77
78
79
80
81
82
83
84
classdef tree
properties
ParentList;
end
methods
function obj = tree()
load ParentList2.mat
obj.ParentList = ParentList2;
end
function children = getChildren(obj,node)
children = find(obj.ParentList==node);
end
function parents = getParents(obj,node)
parents = node;
while obj.ParentList(node) ~=0
node = obj.ParentList(node);
parents = [node,parents];
end
end
function commonParent = getCommonParent(obj,node1,node2)
parents1 = obj.getParents(node1);
parents2 = obj.getParents(node2);
N = min(length(parents1),length(parents2));
commonParent = 0;
for i = 1:N
if parents1(i)==parents2(i)
commonParent = parents1(i);
else
return;
end
end
end
function depth = getDepth(obj,node)
parents = obj.getParents(node);
depth = length(parents);
end
function hight = getHight(obj,node)
children = obj.getChildren(node);
if isempty(children)
hight = 0;
else
hight = 0;
for i = 1:length(children)
hight_i = obj.getHight(children(i));
if hight_i > hight
hight = hight_i;
end
end
hight = hight + 1;
end
end
function Specificity = getSpecificity(obj,node)
depth = obj.getDepth(node);
hight = obj.getHight(node);
Specificity = depth/(depth+hight);
end
function flag = isParent(obj,node1,node2)
parents = obj.getParents(node2);
flag = ismember(node1,parents);
end
function flag = isLeafNode(obj, node)
children = obj.getChildren(node);
if isempty(children)
flag = true;
else
flag = false;
end
end
end
end