Skip to content

Instantly share code, notes, and snippets.

@metdinov
Created January 22, 2019 14:35
Show Gist options
  • Save metdinov/bb9cfddf5aeeaf82c93a9a507c5992ef to your computer and use it in GitHub Desktop.
Save metdinov/bb9cfddf5aeeaf82c93a9a507c5992ef to your computer and use it in GitHub Desktop.
Elo system
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Elo Rating System"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def expectation(rank_a, rank_b):\n",
" return 1 / (1 + 10 ** ((rank_b - rank_a) / 400))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Jugadores con el mismo ranking tienen igual probabilidad de ganar"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.5"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"expectation(1000, 1000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Update rule"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> The maximum possible adjustment per game, called the K-factor, was set at K = 16 for masters and K = 32 for weaker players."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def new_rank(rank_a, rank_b, result=1):\n",
" \"\"\"result: 1 => win | 0 => loss\"\"\"\n",
" K = 32\n",
" return rank_a + K * (result - expectation(rank_a, rank_b))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Ejemplo\n",
"Un jugador fuerte `rank = 2000` vs un paquete `rank = 1500`"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9467597847979775"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rank_a = 2000\n",
"rank_b = 1500\n",
"expectation(rank_a, rank_b)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2001.7036868864648"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_rank_a = new_rank(rank_a, rank_b, result = 1)\n",
"new_rank_a"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1484.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_rank_b = new_rank(rank_b, rank_b, result = 0)\n",
"new_rank_b"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment