Elo ratings are easy to calculate
Elo ratings may seem mysterious and complicated, but basic Elo ratings are super easy to calculate. The entire code is in these 2 yellow boxes. It’s perl, a particularly ugly language, but any coder should be able to read it.
First, given two ratings, here’s how you find out the probability that the player with the first rating beats the player with the second. I broke it out because it’s useful on its own. It’s literally 1 line of calculation. This is the logistic function, which has been shown empirically to be a good fit for the job. 400 is a scaling constant which is standard for Elo.
sub expected_win_rate ($, $) {
my $rating1 = shift;
my $rating2 = shift;
return 1.0 / (1.0 + 10.0 ** (($rating2 - $rating1) / 400.0));
}
Second, given two ratings and a game result, here’s how you figure out the two new ratings after the game. This time it’s 2 lines of calculation, and it calls the expected win rate function above. $actual is the game result, 0.0 if the first player lost and 1.0 if the first player won. You can use 0.5 for a draw, but I skipped over draws because I’m not sure what ‘draw’ means in the file I have (there are 1211 draws in the 141,164 games, a negligible number, so it shouldn’t make much difference). $elo_k is the K constant for the Elo formula, which is the maximum rating change per game. Setting $elo_k high means that ratings react quickly to changes, and setting $elo_k low means ratings are more accurate if changes are slow. I have a lot of games, so I set $elo_k to a low value, 16. Other common values are 24 and 32.
sub update_elo ($, $, $) {
my $rating1 = shift;
my $rating2 = shift;
my $actual = shift;
my $delta = $elo_k * ($actual - &expected_win_rate ($rating1, $rating2));
return ($rating1 + $delta, $rating2 - $delta);
}
Third and last, you need to already have an Elo rating before you can use the Elo formula. How do you set a player’s initial rating? If you don’t have any better idea, it’s standard to set it to 1500. It will take a while to become accurate. I used the calculate-backward trick to get accurate initial ratings, but that only works if you have the whole dataset ahead of time. Sometimes players are rated by a different “provisional” system for some small number of early games, before Elo kicks in.
And that’s the story! There are a bunch of fancy variations of Elo which try to do a little better. And though I think they mostly do do a little better, they’re more complicated and not very much better.
The bottom line: Calculating Elo ratings is easy and works well, so you should do it. If you care about playing strength and have the data, ratings are your answer.
Comments
Jay Scott on :
krasi0 on :
Jay Scott on :