forked from naiq/Duke_evaluation
-
Notifications
You must be signed in to change notification settings - Fork 6
/
compute_AP.m
41 lines (35 loc) · 901 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
function [ap, cmc] = compute_AP(good_image, junk_image, index)
cmc = zeros(length(index), 1);
ngood = length(good_image);
old_recall = 0;
old_precision = 1.0;
ap = 0;
intersect_size = 0;
j = 0;
good_now = 0;
njunk = 0;
for n = 1:length(index)
flag = 0;
if ~isempty(find(good_image == index(n), 1))
cmc(n-njunk:end) = 1;
flag = 1; % good image
good_now = good_now+1;
end
if ~isempty(find(junk_image == index(n), 1))
njunk = njunk + 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
return;
end
end
end