Last active
July 9, 2019 23:58
-
-
Save usptact/231bc57f8a0a7154f8577182d431e0f8 to your computer and use it in GitHub Desktop.
SoftRank: from scores to rank distributions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Demo script to compute rank distributions given pairwise preference probabilities. | |
Data: | |
- pairwise preference probabilities (not including self) | |
Output: | |
- distribution over ranks | |
Michael Taylor, John Guiver, Stephen Robertson and Tom Minka, "SoftRank: Optimising Non-Smooth Rank Metrics", WSDM 2008. | |
""" | |
pi_j = list() | |
def main(): | |
global pi_j | |
P = [ | |
[0.01, 0.4], # pi_1j | |
[0.1, 0.6], # pi_2j | |
[0.9, 0.99], # pi_3j | |
] | |
num_documents = len(P) | |
num_ranks = num_documents | |
for j in range(num_documents): | |
pi_j = P[j] | |
pdist = [0] * num_ranks | |
for r in range(num_ranks): | |
pdist[r] = p_func(r, num_documents-2) | |
pdist.reverse() # why??? | |
print(pdist) | |
def p_func(r, i): | |
if r < 0: | |
return 0.0 | |
if i == -1: | |
if r == 0: | |
return 1.0 | |
else: | |
return 0.0 | |
else: | |
return p_func(r - 1, i - 1) * pi_j[i] + p_func(r, i - 1) * (1.0 - pi_j[i]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment