# Glicko rating

## Recommended Posts

Hi,  I adapted http://www.glicko.net/glicko/glicko.pdf to apply to raitings bot.

import math

# Rating deviation extrema
RDmax = 140
RDmin = 40

# Linear mapping
GPthr = 100		# games played threshold
m = float(GPthr) / (RDmin - RDmax)		# slope

# Simple Glicko without rating deviation aging
def get_rating_adjustment2(rating, opponent_rating, games_played, opponent_games_played, result):
r = rating
rj = opponent_rating
sj = (result + 1) / 2	# outcome

# Linear mapping of games played to rating deviation
# instead of RD = min(math.sqrt(RD_{old}^2 + c^2), 350)
RD = RDmin if games_played > GPthr else m * games_played + RDmax
RDj = RDmin if opponent_games_played > GPthr else m * opponent_games_played + RDmax

# Rating delta
q = math.log(10) / 400
gj = 1 / math.sqrt(1 + 3 * math.pow(q * RDj / math.pi, 2))
Ej = 1 / (1 + math.pow(10, gj * (rj - r) / 400))
d2 = 1 / (math.pow(q * gj, 2) * Ej * (1 - Ej))
value = 1 / RD / RD + 1 / d2
# RDnew = math.sqrt(1 / value)	# not used for now
return round(q * gj * (sj - Ej) / value)

It has 3 parameters that control how much a player gains or loses depending on its experience.
The rating deviation (RD) is like the standard deviation and states the certainty of a player's rating and determines how much a result influences rating.
To fit current code, I modified the algorithm to linearly assign RD \in [RDmax, RDmin] according to games played \in [0, GPthr]
and RDmin if games played > GPthr
With RDmax = 140 so inexperienced players dont jump too much, RDmin = 40 so experienced players can still slowly increase rating, and arbitrarily setting maximum experience with GPthr = 100 games played, we can test with

from random import choice, seed, randint
r1,r2 = 2100, 1200
seed()
for x in range(GPthr+10):
print(r1, r2)
res = choice([-1, 1])
#r1 += get_rating_adjustment(r1, randint(1100, 2100), GPthr+x, randint(0, GPthr), 1)
r1 += get_rating_adjustment2(r1, r2, GPthr+x, 0+x, res)
r2 += get_rating_adjustment2(r2, r1, 0+x, GPthr+x, -res)
print(r1, r2)

Test 1: expert player like borg vs new player, 110 games with 50-50% wins

You can see how with Glicko the expert is not greatly affected but possible smurfs.

Test 2: Average fully experienced player always winning vs all kinds of players

The original rating was pretty certain but RDmin gives chance for improvement, quite slowly.

Fics uses a variation of the algorithm: http://www.freechess.org/Help/HelpFiles/glicko.html

Edited by mapkoc
• 1

##### Share on other sites

Edited by Lion.Kanzen