Dice & German Tank Problem¶
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import seaborn as sns
import empiricaldist
from empiricaldist import Pmf, Distribution
Manual Way¶
dice = Pmf.from_seq([4,6,8,12])
dice
probs | |
---|---|
4 | 0.25 |
6 | 0.25 |
8 | 0.25 |
12 | 0.25 |
dice[4] *= 0
dice[6] *= 1/6
dice[8] *= 1/8
dice[12] *= 1/12
dice.normalize()
0.09374999999999999
dice
probs | |
---|---|
4 | 0.000000 |
6 | 0.444444 |
8 | 0.333333 |
12 | 0.222222 |
def likelihood_dice(data, hypo):
if data > hypo:
return 0
else:
return 1 /hypo
# Solution
# def likelihood_dice(data, hypo):
# """Likelihood function for the dice problem.
# data: outcome of the die roll
# hypo: number of sides
# returns: float probability
# """
# if data > hypo:
# return 0
# else:
# return 1 / hypo
dice = Pmf.from_seq([4,6,8,12])
dice.update(likelihood_dice, 6)
dice
probs | |
---|---|
4 | 0.000000 |
6 | 0.444444 |
8 | 0.333333 |
12 | 0.222222 |
for roll in [8,7,7,5, 4]:
dice.update(likelihood_dice, roll)
dice
probs | |
---|---|
4 | 0.000000 |
6 | 0.000000 |
8 | 0.919294 |
12 | 0.080706 |
dice.update??