Trials¶
Faisal Qureshi
faisal.qureshi@ontariotechu.ca
http://www.vclab.ca
Copyright information¶
© Faisal Qureshi
License¶
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.In [68]:
import numpy as np
In [69]:
def dice_throw():
return np.random.choice([1,2,3,4,5,6])
In [70]:
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 [71]:
num_trials = 10
probabilities = estimate_dice_probabilities(num_trials)
print('probabilities:', probabilities)
print('true probabilities:', np.ones(6)/6.)
probabilities: [0. 0.2 0.4 0.3 0.1 0. ] true probabilities: [0.16666667 0.16666667 0.16666667 0.16666667 0.16666667 0.16666667]
In [78]:
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.166204 0.166675 0.166508 0.166805 0.166883 0.166925] 1: [0.166346 0.166416 0.166692 0.16667 0.166575 0.167301] 2: [0.167064 0.167034 0.166341 0.166529 0.16689 0.166142] 3: [0.166911 0.166304 0.166528 0.166351 0.167288 0.166618]
In [67]:
sum = 0
for i in range(len(probabilities)):
sum = sum + probabilities[i]
print(sum/len(probabilities))
[0.275 0.15 0.15 0.15 0.1 0.175]
In [ ]: