
Trials¶
Faisal Qureshi
faisal.qureshi@ontariotechu.ca
http://www.vclab.ca
Copyright information¶
© Faisal Qureshi
License¶

In [1]:
import numpy as np
In [2]:
def dice_throw():
return np.random.choice([1,2,3,4,5,6])
In [3]:
def estimate_dice_probabilities(num_throws):
outcomes = np.zeros(6)
for i in range(num_throws):
outcome = dice_throw()
outcomes[outcome-1] = outcomes[outcome-1] + 1
return outcomes / num_throws
In [4]:
num_trials = 10
probabilities = estimate_dice_probabilities(num_trials)
print('probabilities:', probabilities)
print('true probabilities:', np.ones(6)/6.)
probabilities: [0.2 0.1 0.3 0.2 0. 0.2] true probabilities: [0.16666667 0.16666667 0.16666667 0.16666667 0.16666667 0.16666667]
In [5]:
n_independent_trials = 4
probabilities = []
for i in range(n_independent_trials):
num_throws = 1000000
probabilities.append(estimate_dice_probabilities(num_throws))
print(f'{i}: ', probabilities[-1])
0: [0.166501 0.166531 0.167105 0.166554 0.166607 0.166702] 1: [0.166105 0.16654 0.16658 0.167204 0.16695 0.166621] 2: [0.166382 0.16646 0.166546 0.16692 0.166458 0.167234] 3: [0.167432 0.166031 0.166604 0.167425 0.16602 0.166488]
In [6]:
sum = 0
for i in range(len(probabilities)):
sum = sum + probabilities[i]
print(sum/len(probabilities))
[0.166605 0.1663905 0.16670875 0.16702575 0.16650875 0.16676125]

In [ ]: