-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboggle_analysis.py
More file actions
71 lines (65 loc) · 2.03 KB
/
boggle_analysis.py
File metadata and controls
71 lines (65 loc) · 2.03 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import scipy.stats as stats
import seaborn as sns
import matplotlib.pyplot as plt
from word_finder import *
from time import process_time
import csv
result_file = 'boggle_trials_test_cubes.csv'
plt.rcParams['figure.dpi'] = 150
plt.rcParams['savefig.dpi'] = 150
board = Board(dim=5)
def simulate():
result = []
words_dict = {}
with open(result_file, 'w') as csvfile:
writer = csv.writer(csvfile)
for i in range(10000):
board.populate()
result.append(board.total_points)
writer.writerow([i,board.last_id, board.total_points])
for word in board.all_words:
if word in words_dict:
words_dict[word][0] += 1
else:
words_dict[word] = [1, board.last_id,i]
np_result = np.array(result)
return (np_result, words_dict)
def get_words():
words_dict = {}
board = Board(dim=5)
with open(result_file, 'r') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
board.id = float(row[0])
board.populate()
# assert board.total_points == int(row[1])
for word in board.all_words:
if word in words_dict:
words_dict[word][0] += 1
else:
words_dict[word][0] = 1
words_dict[word][1] = set(board.id)
return words_dict
t1 = process_time()
result = simulate()
t2 = process_time()
sim = result[0]
words_dict = result[1]
with open('word_occurrences_test_cubes.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
for word in words_dict:
res = words_dict.get(word)
writer.writerow([word, res[0], res[1], res[2]])
x=stats.describe(sim)
y=sns.histplot(sim)
med=np.median(sim)
z = stats.t.interval(0.99, 299999, loc = np.mean(sim), scale = np.std(sim) / np.sqrt(10000))
plt.title('Distribution of Points in Big Boggle (Old Cubes)')
plt.ylabel('Frequency')
plt.xlabel('Points')
plt.show()
print(x)
print(z)
print(med)
print(t2-t1)