-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfind_STC.m
45 lines (35 loc) · 1.24 KB
/
find_STC.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
function [auc, mcc, f1s, olp, estTh] = find_STC(Th, TP, TN, FP, FN, disp_opt)
%=========================================================================%
PPV = TP ./ (TP + FP); % precision/overlap normalized by estimated area
TPR = TP ./ (TP + FN); % sensitivity/overlap normalized by true area
FPR = FP ./ (FP + TN); % specificity complemntary
% Matthews correlation coefficient
%=========================================================================%
MCC = (TP.*TN - FP.*FN)./sqrt((TP+FP).*(TP+FN).*(TN+FP).*(TN+FN));
MCC(isinf(MCC) | isnan(MCC)) = 0;
% F1 scores
%=========================================================================%
F1S = 2*PPV.*TPR./(PPV+TPR);
%%
[mcc, imcc] = max(MCC, [], 1);
[f1s, if1s] = max(F1S, [], 1);
estTh = Th(imcc);
for t = 1 : size(TPR, 2)
auc(t) = trapz(FPR(:, t), TPR(:, t));
olp(t, :) = [TPR(imcc(t), t) PPV(imcc(t), t)];
dFPR(t) = FPR(imcc(t), t);
end
%%
if(strcmp(disp_opt, 'Display'))
figure,
plot(FPR, TPR)
TP = length(estTh);
hold on, line([dFPR; dFPR], [zeros(1, TP); ones(1, TP)])
ylabel('True Positive Rate')
xlabel('False Positive Rate')
for i = 1 : TP
lgnd{i} = ['Th = ' num2str(estTh(i))];
end
legend(lgnd)
end
end