crodgers

Untitled

Jul 11th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import math
  2.  
  3. def K_factor(rating, board_weight=1.0):
  4. '''maximum change possible at a given rating; lower for higher ratings.
  5. called "con" in EGF rating system.
  6. board_weight is 1 for 19x19, .5 for 13x13, .25 for 9x9.
  7. '''
  8. r100 = rating / 100
  9. return board_weight * (122 - (r100 * 6) + (r100 * r100 / 15))
  10.  
  11. def A_factor(rating):
  12. '''rating difference normalizer in the logistic curve: see http://senseis.xmp.net/?GoR'''
  13. return 205 - (rating / 20)
  14.  
  15. def compute_change(winner_rating, loser_rating):
  16. ''' return the change in ratings for as a tuple: (change_winner, change_loser)'''
  17. stronger_rating = max(winner_rating, loser_rating)
  18. weaker_rating = min(winner_rating, loser_rating)
  19. rating_diff = stronger_rating - weaker_rating
  20. # expected probability of winning for each player
  21. # S_E_xxx naming taken from EGF description at http://senseis.xmp.net/?GoR
  22. S_E_weaker = 1 / (math.exp(rating_diff / A_factor(weaker_rating)) + 1)
  23. S_E_stronger = 1 - S_E_weaker
  24. if winner_rating == stronger_rating:
  25. return (K_factor(winner_rating) * (1 - S_E_stronger),
  26. K_factor(loser_rating) * (0 - S_E_weaker))
  27. else:
  28. return (K_factor(winner_rating) * (1 - S_E_weaker),
  29. K_factor(loser_rating) * (0 - S_E_stronger))
  30.  
  31. if __name__ == '__main__':
  32. changes = compute_change(1047, 1422) # http://online-go.com/game/485007
  33. assert round(1047 + changes[0]) == 1107
  34. assert round(1422 + changes[1]) == 1377
Advertisement
Add Comment
Please, Sign In to add comment