-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplotAP.m
40 lines (32 loc) · 1002 Bytes
/
plotAP.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
% Plots precision-recall curves.
%
% 'corr' is a vector indicating which predictions are correct, where
% 1=correct, and 0=incorrect. It should be sorted in the order of
% decreasing scores, with the top scoring prediction being first.
%
% 'numtrue' is the number of actual elements in the testing set.
%
% 'varargin' are plotting commands applied to the graph.
function ap = plotAP(corr, numtrue, varargin),
rec = cumsum(corr) / numtrue;
pre = cumsum(corr) ./ (1:length(corr))';
%pre = zeros(length(corr), 1);
%rec = zeros(length(corr), 1);
%for i=1:length(corr),
% rec(i) = sum(corr(1:i)) / numtrue;
% pre(i) = sum(corr(1:i)) / i;
%
% progress('compute AP', i, length(corr), 10);
%end
plot(rec, pre, varargin{:});
xlim([0,1]);
ylim([0,1]);
ap = calculateAP(rec, pre);
function ap = calculateAP(rec, prec);
mrec=[0 ; rec ; 1];
mpre=[0 ; prec ; 0];
for i=numel(mpre)-1:-1:1
mpre(i)=max(mpre(i),mpre(i+1));
end
i=find(mrec(2:end)~=mrec(1:end-1))+1;
ap=sum((mrec(i)-mrec(i-1)).*mpre(i));