MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / compute_ap

Function compute_ap

utils.py:688–720  ·  view source on GitHub ↗

Computes average precision for given ranked indexes. Arguments --------- ranks : zerro-based ranks of positive images nres : number of positive images Returns ------- ap : average precision

(ranks, nres)

Source from the content-addressed store, hash-verified

686
687
688def compute_ap(ranks, nres):
689 """
690 Computes average precision for given ranked indexes.
691 Arguments
692 ---------
693 ranks : zerro-based ranks of positive images
694 nres : number of positive images
695 Returns
696 -------
697 ap : average precision
698 """
699
700 # number of images ranked by the system
701 nimgranks = len(ranks)
702
703 # accumulate trapezoids in PR-plot
704 ap = 0
705
706 recall_step = 1. / nres
707
708 for j in np.arange(nimgranks):
709 rank = ranks[j]
710
711 if rank == 0:
712 precision_0 = 1.
713 else:
714 precision_0 = float(j) / rank
715
716 precision_1 = float(j + 1) / (rank + 1)
717
718 ap += (precision_0 + precision_1) * recall_step / 2.
719
720 return ap
721
722
723def compute_map(ranks, gnd, kappas=[]):

Callers 1

compute_mapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected