-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_ap_from_ranks1.m
55 lines (39 loc) · 1018 Bytes
/
score_ap_from_ranks1.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
% Authors: Herve Jegou and Matthijs Douze, [email protected]
% Copyright INRIA 2008-2010. License: GPL
% This function computes the AP for a query
function ap = score_ap_from_ranks1 (ranks, nres)
% number of images ranked by the system
nimgranks = length (ranks);
if 1
ranks = ranks - 1;
% accumulate trapezoids in PR-plot
ap = 0;
recall_step = 1 / nres;
for i = 1:nimgranks
rank = ranks(i);
if rank == 0
precision_0 = 1.0;
else
precision_0 = (i - 1) / rank;
end
precision_1 = i / (rank + 1);
ap = ap + (precision_0 + precision_1) * recall_step / 2;
end
%----------------------------------------
else
% number of images ranked by the system
nimgranks = length (ranks);
% accumulate trapezoids in PR-plot
ap = 0;
recall_step = 1 / nres;
for i = 1:nimgranks
rank = ranks(i);
if rank == 1
precision_0 = 1.0;
else
precision_0 = (i - 1) / (rank - 1);
end
precision_1 = i / rank;
ap = ap + (precision_0 + precision_1) * recall_step / 2;
end
end