-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats_testing.py
More file actions
32 lines (27 loc) · 817 Bytes
/
Copy pathstats_testing.py
File metadata and controls
32 lines (27 loc) · 817 Bytes
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
import random
import matplotlib.pyplot as plt
# only used for testing
class Game(object):
def __init__(self, prob_model: dict[int, float]):
assert sum(prob_model.values()) == 1
self.prob_model = prob_model
def simulate_many(self, n):
total = 0
for i in range(n):
total += self.simulate()
plt.plot(i+1, total, 'r')
plt.show()
return total/n
def simulate(self) -> int:
r = random.random()
total = 0
for k, v in self.prob_model.items():
total += v
if r <= total:
return k
raise ValueError('how\'d you get here')
def mean(self) -> float:
expected = 0
for k, v in self.prob_model.items():
expected += k*v
return expected