-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcompute_AP.m
42 lines (36 loc) · 948 Bytes
/
compute_AP.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
function ap = compute_AP(good_image, index)
% good_image: index for correct match
% index: ranked retrival image index
ngood = length(good_image);
old_recall = 0;
old_precision = 1.0;
ap = 0;
intersect_size = 0;
j = 0;
good_now = 0;
% ngood = ngood - 1;
% tic
for n = 1:length(index)
flag = 0;
if ~isempty(find(good_image == index(n), 1))
flag = 1; % good image
good_now = good_now+1;
end
% if ~isempty(find(junk_image == index(n), 1))
% continue; % junk image
% end
if flag == 1%good
intersect_size = intersect_size + 1;
end
recall = intersect_size/ngood;
precision = intersect_size/(j + 1);
ap = ap + (recall - old_recall)*((old_precision+precision)/2);
old_recall = recall;
old_precision = precision;
j = j+1;
if good_now == ngood
% toc
return;
end
end
end