Skip to content

Commit

Permalink
adding some extra comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Cartucho committed May 3, 2018
1 parent fc35357 commit 17d1ffc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,31 @@ def voc_ap(rec, prec):
prec.insert(0, 0.0) # insert 0.0 at begining of list
prec.append(0.0) # insert 0.0 at end of list
mpre = prec[:]
"""
This part makes the precision monotonically decreasing
(goes from the end to the beginning)
"""
# matlab indexes start in 1 but python in 0, so I have to do:
# range(start=(len(mpre) - 2), end=0, step=-1)
# also the python function range excludes the end, resulting in:
# range(start=(len(mpre) - 2), end=-1, step=-1)
for i in range(len(mpre)-2, -1, -1):
mpre[i] = max(mpre[i], mpre[i+1])
"""
This part creates a list of indexes where the recall changes
"""
# matlab: i=find(mrec(2:end)~=mrec(1:end-1))+1;
ind = []
for ind_1 in range(1, len(mrec)):
if mrec[ind_1] != mrec[ind_1-1]:
ind.append(ind_1) # if it was matlab would be ind_1 + 1
i_list = []
for i in range(1, len(mrec)):
if mrec[i] != mrec[i-1]:
i_list.append(i) # if it was matlab would be i + 1
"""
The Average Precision (AP) is the area under the curve
(numerical integration)
"""
# matlab: ap=sum((mrec(i)-mrec(i-1)).*mpre(i));
ap = 0.0
for i in ind:
for i in i_list:
ap += ((mrec[i]-mrec[i-1])*mpre[i])
return ap, mrec, mpre

Expand Down

0 comments on commit 17d1ffc

Please sign in to comment.