Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
update ranking 2
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Jul 22, 2019
1 parent 382d663 commit e0a86a0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions deeprank/learn/rankingMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ def hitrate(rs):
rs (array): binary relevance array
Returns:
hirate (array): [recall@1,recall@2,...]
Rets:
hirtate (array): [recall@1,recall@2,...]
"""
rs =np.array(rs)
nr = np.max((1,np.sum(rs)))
rs = np.array(rs)
nr = np.max((1, np.sum(rs)))
return np.cumsum(rs) / nr


def success(hitrate):
'''
Input: hitrate = [0, 0, 0.3, 0.4]
Output: success = [0, 0, 1, 1]
'''

success = np.ones(len(hitrate))
idx = (hitrate ==0)
idx = (hitrate == 0)
success[idx] = 0

return success


def avprec(rs):
return [average_precision(rs[:i]) for i in range(1,len(rs))]
return [average_precision(rs[:i]) for i in range(1, len(rs))]

def recall(rs,nr):

def recall(rs, nr):
"""recall rate
First element is rank 1, Relevance is binray
Expand All @@ -68,6 +70,7 @@ def recall(rs,nr):

return np.sum(rs)/nr


def mean_reciprocal_rank(rs):
"""Score is reciprocal of the rank of the first relevant item
Expand Down

0 comments on commit e0a86a0

Please sign in to comment.