-
Notifications
You must be signed in to change notification settings - Fork 6
/
plotting.py
59 lines (48 loc) · 2.07 KB
/
plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pickle
import matplotlib.pyplot as plt
import seaborn as sns
from collections import Counter
from statistics import median
def combine_guesses():
all_guesses = []
for i in range(5):
FileStore = open(f"stored_objects/guesses_{i}.pickle", "rb")
guesses = pickle.load(FileStore)
FileStore.close()
all_guesses.extend(guesses)
FileStore = open(f"stored_objects/ht_min_parity_guesses_final.pickle", "wb")
pickle.dump(all_guesses, FileStore)
FileStore.close()
def plot_games(num_guesses, display_name=None):
games_by_score = Counter(num_guesses)
for i in range(101):
if i not in games_by_score.keys():
games_by_score[i] = 0
games_by_score = dict(sorted(games_by_score.items(), key=lambda item: item[0]))
if display_name:
plt.plot(games_by_score.keys(), games_by_score.values(), label=display_name)
else:
plt.plot(games_by_score.keys(), games_by_score.values())
def plot_all_games(file_names, display_names):
for file_name, display_name in zip(file_names, display_names):
FileStore = open(f"stored_objects/{file_name}.pickle", "rb")
guesses = pickle.load(FileStore)
FileStore.close()
plot_games(guesses, display_name)
plt.xlabel("Number of Guesses")
plt.ylabel("Number of Games")
plt.legend(loc="upper left")
def plot_all_cdfs(file_names, display_names):
for filename, display_name in zip(file_names, display_names):
FileStore = open(f"stored_objects/{filename}.pickle", "rb")
guesses = pickle.load(FileStore)
FileStore.close()
sns.kdeplot(data=[0] + guesses + [100], cumulative=True, clip=(0, 101), label=display_name)
plt.xlabel("Number of Guesses")
plt.legend(loc="upper left")
file_names = ["random_guesses_final", "ht_guesses_final", "ht_min_parity_guesses_final", "prob_guesses_final"]
display_names = ["Random", "Hunt / Target", "Hunt / Target Minimum", "Probabilistic"]
num = 4
plot_all_games(file_names[:num], display_names[:num])
# plot_all_cdfs(file_names[:num], display_names[:num])
plt.show()