Yes. I know what you’re thinking. “Chess is the most important sport on the planet. Perhaps the most important activity there is. If you claim that Poland played better than what their fourth place indicates, you’d better have proof. You’d. Better. Get. This. Right.”

This will be a long post, wherein I

Explain “Why Pyro” Describe chess and the Olympiad in excruciating detail Finally get to the code part, where we model the result of a chess tournament Solve the model in various ways Download Chess Olympiad data and calculate the strongest teams Draw conclusions!

Pyro

To get this right, I’d like to use probabilistic programming and Pyro.

At Tenfifty, we like Pytorch. Compared to Tensorflow, the eager execution feels much more like Python programming. When I have done probabilistic programming in the past, I have generally used PyMC3, which is nice enough. However, being built on top of Theano, it does suffer from the same problem as Tensorflow. The compiling and lazy execution can lead to strange error messages and a suboptimal REPL experience. Also Theano is not developed anymore.

Enter Pyro. Pyro is a new probabilistic programming library, built on top of Pytorch. It is still in alpha, but seems to work well. Pytorch was recently released in a 1.0 preview, which led me to do this experiment in Pytorch 1.0 (preview) and the branch of Pyro that supports Pytorch 1.0.

I learned Pyro as I worked on this, so I may have gotten some details wrong. Probably not, though.

Chess background

So, what will we use Pyro for? Recently, the 2018 Chess Olympiad was concluded. It was generally exciting, as chess tends to be, but lead to the type of discussions that seems to be the point of sports – “Did the right team win?”, “Is the system fair?”, “Could this perhaps be ruined with enough math and programming?”.

You see, the Chess Olympiad is played as a team sport. Four players from one country play four players from another country. Four games in total and you sum up the results (draw counts as 0.5). 184 teams entered the Open Section (there is also a Women’s Section, but since everyone is eligible to play in the Open, I will focus on that one), almost all of them from separate countries. They play 11 rounds. Each round, countries get paired in matches against other countries with the same score so far. This system is used in many sports and is called a Swiss pairing. The devil is in the details, however, and this year the pairing was sort of odd.

After the tournament had concluded, there were three teams with the same number of wins. Who was the tournament winner? This is decided via a complex calculation of tiebreaks, using the results of the teams that each of the three teams have played, to see who had the toughest opposition. My first question, then, is Was this procedure fair?

The second question regards Poland. Poland was the tournament surprise. For nine rounds they played the best chess and were the tournament leaders. They met all the best teams and didn’t lose a single match, until round 10. After the full eleven rounds, they placed fourth. No medal for Poland. Strong grandmasters and people in general on Twitter seemed to regard this as a scandal. Had Poland not shown that they were worthy of a medal? They had played the strongest opposition by far and faltered just at the finish line. The system was unfair! Should Poland have gotten a medal?

Being a curmudgeonly and generally unpleasant sort of fellow, I though to myself “Bah. Humbug. They just favor the underdog with their filthy emotions. I bet fourth place was even too good for that uppity Polish team. Let’s spend several hours proving that someone on the Internet is wrong.” Also I thought it would serve humanity to show that Sweden is better than Norway at chess.