-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstation.py
More file actions
85 lines (73 loc) · 2.67 KB
/
station.py
File metadata and controls
85 lines (73 loc) · 2.67 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
72
73
74
75
76
77
78
79
80
81
82
83
from engine import Engine
from coach import Player
import csv
import argparse
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from hopper import clear
'''
This script is used via the terminal to run simulations and
write the results to file.
'''
def define_optimal_sample_size(start=500, stop=7000, step=500):
# Generates samples of sizes defined by args
# To help computers with less memory, this function can be run
# in stages. , after running the first set of tests, change the
# 'w+' in the next line to 'a', and comment out the following
# line (f.write(f'mean_score\n')). Then run fuction with smaller
# batch sizes (like: start=2500, stop=5000)
f = open('../data/batchtests.csv', 'w+')
f.write(f'size,mean_score\n')
engine = Engine('perfect')
# First loop: Ranges of sample sizes to test
for n in range(start, stop, step):
# Second loop: tests each sample size 25 times.
# This results in 25 light blue dots on the graph
for sample in range(25):
results = list()
# Third loop runs simulation n times and stores
# the mean of those simulations.
for _ in range(n):
engine.play_round()
results.append(engine.round_points)
f.write(f'{n},{int(np.mean(results))}\n')
clear()
print(f'Generating samples... test #{int(n/stop*100)}.{int(sample/250*100)}% done')
f.close()
def run_test(vp_name='perfect', n=4000, t=200, file_name=None):
file_name = file_name or vp_name
engine = Engine(vp_name)
f = open(f'../data/{file_name}.csv', 'w+')
f.write('mean_score\n')
for _ in range(t):
score_sum = 0
for _ in range(n):
engine.play_round()
score_sum += engine.round_points
f.write(f'{score_sum/n}\n')
def take_sample(vp_name='perfect', n=100, file_name='sample'):
# Writes n number of scores + outcomes to file using
# the specified VP.
engine = Engine(vp_name)
f = open(f'../data/{file_name}.csv', 'w+')
f.write('score\n')
for _ in range(n):
engine.play_round()
f.write(f'{engine.round_points}\n')
if __name__ == '__main__':
clear()
num =input('''Menu:\n
1) Generate sample of scores from the Perfect VP. (ch.2)
2) Define the optimal number of samples. (ch.2)
3) Run tests on each VP.
Please input a number
''')
if num == '1':
take_sample()
if num == '2':
define_optimal_sample_size()
if num == '3':
for vp in Player()._funcs.keys():
if vp not in ['custom', 'terminal']:
run_test(vp)