-
-
Save thouis/746430e9f597c15d70b5 to your computer and use it in GitHub Desktop.
This file contains 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
import math | |
def K_factor(rating, board_weight=1.0): | |
'''maximum change possible at a given rating; lower for higher ratings. | |
called "con" in EGF rating system. | |
board_weight is 1 for 19x19, .5 for 13x13, .25 for 9x9. | |
''' | |
r100 = rating / 100 | |
return board_weight * (122 - (r100 * 6) + (r100 * r100 / 15)) | |
def A_factor(rating): | |
'''rating difference normalizer in the logistic curve: see http://senseis.xmp.net/?GoR''' | |
return 205 - (rating / 20) | |
def compute_change(winner_rating, loser_rating): | |
''' return the change in ratings for as a tuple: (change_winner, change_loser)''' | |
stronger_rating = max(winner_rating, loser_rating) | |
weaker_rating = min(winner_rating, loser_rating) | |
rating_diff = stronger_rating - weaker_rating | |
# expected probability of winning for each player | |
# S_E_xxx naming taken from EGF description at http://senseis.xmp.net/?GoR | |
S_E_weaker = 1 / (math.exp(rating_diff / A_factor(weaker_rating)) + 1) | |
S_E_stronger = 1 - S_E_weaker | |
if winner_rating == stronger_rating: | |
return (K_factor(winner_rating) * (1 - S_E_stronger), | |
K_factor(loser_rating) * (0 - S_E_weaker)) | |
else: | |
return (K_factor(winner_rating) * (1 - S_E_weaker), | |
K_factor(loser_rating) * (0 - S_E_stronger)) | |
if __name__ == '__main__': | |
changes = compute_change(1047, 1422) # http://online-go.com/game/485007 | |
assert round(1047 + changes[0]) == 1107 | |
assert round(1422 + changes[1]) == 1377 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment