-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOMPUTE_AUC.m
115 lines (71 loc) · 2.16 KB
/
COMPUTE_AUC.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
function [AUC] = COMPUTE_AUC(Run,TRUE,burn_in)
% Compute edge scores:
[SCORES] = DIR(Run, burn_in);
% Compute AUC (are under the precision recall curve)
[AUC] = AUPRC(TRUE, SCORES);
return
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [SCORES] = DIR(Run, burn_in)
DAGS = Run.dag;
n_samples = length(DAGS);
n_nodes = size(DAGS{1},1);
DIRECTED = zeros(n_nodes,n_nodes);
for i = (burn_in+1):n_samples
DIRECTED = DIRECTED + DAGS{i};
end
SCORES = DIRECTED/(n_samples-burn_in);
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [auprc_com] = AUPRC(True_Matrix, Aposteriori_Matrix)
n_nodes = length(True_Matrix);
for i=1:n_nodes
True_Matrix(i,i)=-1;
end
n_edges = length(find(True_Matrix==1));
Aposterioris = [];
for i = 1:n_nodes
for j = 1:n_nodes
if(i~=j)
Aposterioris = [Aposterioris, Aposteriori_Matrix(i,j)];
end
end
end
Aposterioris = sort(Aposterioris,'descend');
APO_values(1) = Aposterioris(1);
for i = 2:length(Aposterioris)
if Aposterioris(i)==APO_values(end)
% do nothing
else
APO_values(end+1) = Aposterioris(i);
end
end
MATRIX = zeros(n_nodes,n_nodes);
TPS = [];
FPS = [];
for i = 1:length(APO_values)
indicis = find(Aposteriori_Matrix>=APO_values(i));
MATRIX(indicis) = 1;
TP = length(find(MATRIX==1 & True_Matrix==1));
FP = length(find(MATRIX==1 & True_Matrix==0));
TPS = [TPS,TP];
FPS = [FPS,FP];
end
for i=2:length(TPS)
if (TPS(i)-TPS(i-1))>1
NEW_TPS = [];
NEW_FPS = [];
for x = 1:(TPS(i)-TPS(i-1)-1)
skew = (FPS(i)-FPS(i-1))/(TPS(i)-TPS(i-1));
NEW_TPS = [NEW_TPS,TPS(i-1)+x];
NEW_FPS = [NEW_FPS,FPS(i-1)+ skew*x];
end
TPS = [TPS(1:i-1),NEW_TPS,TPS(i:end)];
FPS = [FPS(1:i-1),NEW_FPS,FPS(i:end)];
end
end
PRECISION = TPS(2:end)./(TPS(2:end)+FPS(2:end));
RECALL = TPS(2:end)/n_edges;
PRECISION = [1,PRECISION];
RECALL = [0,RECALL];
auprc_com = trapz(RECALL,PRECISION);
return;