Skip to content

Commit 8ddf044

Browse files
committed
Add elo catch up and many
1 parent 3e9d9b2 commit 8ddf044

File tree

5 files changed

+215
-4
lines changed

5 files changed

+215
-4
lines changed

Elo-Catch-Up.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import random
2+
#https://github.com/ddm7018/Elo
3+
from elosports.elo import Elo
4+
import sys
5+
import matplotlib.pyplot as plt
6+
import statistics
7+
from matplotlib.pyplot import cm
8+
import numpy as np
9+
10+
11+
base_elo = 1000
12+
real_elo = 2000
13+
nb_match = 500
14+
player0 = "0"
15+
player1 = "1"
16+
color = iter(cm.rainbow(np.linspace(0, 1, len(range (0,7)))))
17+
18+
19+
x_data=[]
20+
y_data=[]
21+
#plot target
22+
for i in range(1,nb_match):
23+
x_data.append(i)
24+
y_data.append(real_elo)
25+
26+
plt.plot(x_data, y_data, c=next(color), label='target=%d elo' % real_elo)
27+
28+
29+
for k_factor in (2**(i/1.0) for i in range (0,6)):
30+
eloLeague = Elo(k = k_factor , homefield = 0)
31+
eloLeague.addPlayer(player0, rating = base_elo)
32+
eloLeague.addPlayer(player1, rating = base_elo)
33+
x_data=[]
34+
y_data=[]
35+
36+
37+
for i in range(1,nb_match):
38+
current_guy_elo = eloLeague.ratingDict[player0]
39+
current_proba = eloLeague.expectResult(real_elo,current_guy_elo)
40+
print("Start match %d, current_guy_elo=%.2f, current_proba=%.2f%%" % (i , current_guy_elo, 100*current_proba ))
41+
if random.uniform(0, 1) < current_proba :
42+
eloLeague.gameOver(player0, player1, winnerHome = True)
43+
else:
44+
eloLeague.gameOver(player1, player0, winnerHome = True)
45+
46+
#update oponent to current elo
47+
#print("before", eloLeague.ratingDict[player0],eloLeague.ratingDict[player1])
48+
eloLeague.ratingDict[player1]=eloLeague.ratingDict[player0]
49+
#print("after", eloLeague.ratingDict[player0],eloLeague.ratingDict[player1])
50+
x_data.append(i)
51+
y_data.append(eloLeague.ratingDict[player1])
52+
53+
plt.plot(x_data, y_data, c=next(color), label='k_factor=%.2f' % k_factor)
54+
55+
56+
plt.title("Catch up to real_elo=%d" % real_elo)
57+
plt.xlabel("matches")
58+
plt.ylabel("elo")
59+
plt.legend(loc='best')
60+
plt.show()
61+
62+
63+

elo-et-variation.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import random
2+
#https://github.com/ddm7018/Elo
3+
from elosports.elo import Elo
4+
import sys
5+
import matplotlib.pyplot as plt
6+
import statistics
7+
from matplotlib.pyplot import cm
8+
import numpy as np
9+
10+
11+
base_elo = 1000
12+
nb_round_robin = 3
13+
k_factor = 32
14+
#Number of bins in the histogram
15+
16+
17+
18+
iter_nb_players = range(200,2400,1000)
19+
color = iter(cm.rainbow(np.linspace(0, 1, len(iter_nb_players))))
20+
21+
for nb_players in iter_nb_players:
22+
print("Computing ecart_t for nb_players=%d" %(nb_players))
23+
eloLeague = Elo(k = k_factor , homefield = 0)
24+
x_data=[]
25+
y_data=[]
26+
for i in range(nb_players):
27+
eloLeague.addPlayer(str(i), rating = base_elo)
28+
29+
for r in range(nb_round_robin):
30+
print("Running round %d/%d k=%d" %(r+1,nb_round_robin,k_factor))
31+
for i in range(nb_players):
32+
for j in range(nb_players):
33+
if i != j :
34+
if random.randrange(2)==0:
35+
eloLeague.gameOver(winner = str(i), loser = str(j), winnerHome = True)
36+
else:
37+
eloLeague.gameOver(loser = str(i), winner = str(j), winnerHome = True)
38+
current_ecart_t = statistics.stdev((eloLeague.ratingDict.values()))
39+
print("\tAfter round %d/%d elo ecart_t=%f" % (r+1,nb_round_robin,current_ecart_t))
40+
x_data.append(r)
41+
y_data.append(current_ecart_t)
42+
43+
plt.plot(x_data, y_data, '--.', c=next(color), label='nb_players=%d' % nb_players)
44+
45+
46+
# Plotting the Graph
47+
plt.title("Evolution of ET per round for different nb_players")
48+
plt.xlabel("round")
49+
plt.ylabel("ecart-type")
50+
plt.legend(loc='best')
51+
plt.show()

elo-et.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import random
2+
#https://github.com/ddm7018/Elo
3+
from elosports.elo import Elo
4+
import sys
5+
import matplotlib.pyplot as plt
6+
import statistics
7+
8+
9+
nb_players = 1000
10+
base_elo = 1000
11+
nb_round_robin = 6
12+
13+
x_data=[]
14+
y_data=[]
15+
16+
17+
for k_factor in (2**(i/2.0) for i in range (0,15)):
18+
print("Computing ecart_t for k=%.2f" %(k_factor))
19+
eloLeague = Elo(k = k_factor , homefield = 0)
20+
average_ecart_t = 0
21+
for i in range(nb_players):
22+
eloLeague.addPlayer(str(i), rating = base_elo)
23+
24+
for r in range(nb_round_robin):
25+
print("Running round %d/%d k=%.2f" %(r+1,nb_round_robin,k_factor))
26+
for i in range(nb_players):
27+
for j in range(nb_players):
28+
if i != j :
29+
if random.randrange(2)==0:
30+
eloLeague.gameOver(winner = str(i), loser = str(j), winnerHome = True)
31+
else:
32+
eloLeague.gameOver(loser = str(i), winner = str(j), winnerHome = True)
33+
current_ecart_t = statistics.stdev((eloLeague.ratingDict.values()))
34+
average_ecart_t+=current_ecart_t
35+
print("\tAfter round %d/%d elo ecart_t=%.2f" % (r+1,nb_round_robin,current_ecart_t))
36+
37+
average_ecart_t = average_ecart_t/nb_round_robin
38+
x_data.append(k_factor)
39+
y_data.append(average_ecart_t)
40+
41+
42+
# Plotting the Graph
43+
plt.plot(x_data, y_data, '--bo')
44+
plt.title("Evolution of ET versus K")
45+
plt.xlabel("K")
46+
plt.ylabel("ecart_t")
47+
plt.show()

elo.py

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
print("\tAfter round %d/%d elo ecart_t=%f" % (r+1,nb_round_robin,statistics.stdev((eloLeague.ratingDict.values()))))
3232

3333

34-
35-
#for team in eloLeague.ratingDict.keys():
36-
# print(team, eloLeague.ratingDict[team])
37-
3834
elo_list=eloLeague.ratingDict.values()
3935
hist_bins = []
4036
current = min(elo_list)

random-match.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import random
2+
#https://github.com/ddm7018/Elo
3+
from elosports.elo import Elo
4+
import sys
5+
import matplotlib.pyplot as plt
6+
import statistics
7+
from matplotlib.pyplot import cm
8+
import numpy as np
9+
10+
nb_players = 2000
11+
matches_ratio = 0.01
12+
nb_matches = nb_players * nb_players * matches_ratio
13+
base_elo = 1000
14+
plot_step = 10
15+
print_step = plot_step*100
16+
k_factor = 32
17+
number_of_curve = 4
18+
19+
#Number of bins in the histogram
20+
color = iter(cm.rainbow(np.linspace(0, 1, number_of_curve)))
21+
22+
for iteration in range(number_of_curve):
23+
print("Iteration %d "% iteration)
24+
eloLeague = Elo(k = k_factor , homefield = 0)
25+
x_data=[]
26+
y_data=[]
27+
for i in range(nb_players):
28+
eloLeague.addPlayer(str(i), rating = base_elo)
29+
30+
for m in range(int(nb_matches)):
31+
i,j = random.sample(range(nb_players), 2)
32+
if random.randrange(2)==0:
33+
eloLeague.gameOver(winner = str(i), loser = str(j), winnerHome = True)
34+
else:
35+
eloLeague.gameOver(loser = str(i), winner = str(j), winnerHome = True)
36+
37+
38+
if m % plot_step == 0 or m < nb_matches * 0.4 :
39+
current_ecart_t = statistics.stdev((eloLeague.ratingDict.values()))
40+
x_data.append(m)
41+
y_data.append(current_ecart_t)
42+
if m % print_step == 0:
43+
print("\tAfter nb_matches %d/%d=%.2f%% elo ecart_t=%.2f" % (m+1,nb_matches, 100.0*m/nb_matches, current_ecart_t))
44+
45+
46+
plt.plot(x_data, y_data, c=next(color), label='iteration=%d' % iteration)
47+
48+
49+
# Plotting the Graph
50+
plt.title("Evolution of ET per matches nb_players=%d, plot_step=%d" % (nb_players, plot_step))
51+
plt.xlabel("matches")
52+
plt.ylabel("ecart-type")
53+
plt.legend(loc='best')
54+
plt.show()

0 commit comments

Comments
 (0)