-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplot_histograms_ROC.m
54 lines (43 loc) · 1.58 KB
/
plot_histograms_ROC.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
clear all;
%% plot the histogram of reconstruction errors
%% setting of plot (this is the only part needs to care about)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
results_path = 'results/PaviaU_10_s0.001';
names = 'rdosr-PaviaU';
view_error_histogram=1;
step = 0.1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% get log data
output_file = 'outputs.mat';
load(fullfile(results_path, output_file));
kwn = recons_error(y~=-1);
unk = recons_error(y==-1);
%% plot the histogram for known and unknown sets
close all;
figure('name', 'Histograms', 'numbertitle', 'off', ...
'units', 'normalized', 'position', [.1 .2 .6, .4])
x = (min(recons_error)-0.05):step:(max(recons_error)+0.05);
if(view_error_histogram)
histogram(unk,x,'FaceColor','r','LineStyle','--','EdgeAlpha',0.1,'Normalization','probability');
hold on;
histogram(kwn,x,'FaceColor','g','EdgeAlpha',0.1,'Normalization','probability');
legend('Unknown','Known');
xlim([0 max(unk)]);
pause(1)
end
xlabel('Reconstruction Error')
ylabel('P(Reconstruction Error)')
set(gca, 'fontsize', 10, 'fontweight', 'bold')
%% plot ROC curve
label_act = ones(1,size(recons_error,2));
label_act(1,size(kwn,2)+1:end) = -1;
label_pred = recons_error;
[X,Y,T,AUC] = perfcurve(label_act, label_pred, -1);
figure('name', 'ROC Curve', 'numbertitle', 'off', ...
'units', 'normalized')
plot(X,Y, 'linewidth', 2);
xlabel('False Positive Rate')
ylabel('True Positive Rate')
set(gca, 'fontsize', 10, 'fontweight', 'bold')
legend(names, 'location', 'northeast', 'interpreter', 'latex', ...
'fontsize', 16)