PaC Exercise 2.1
Posted on February 18, 2021
import numpy as np
Exercise 2.1
Suppose we roll a fair k-sided die with the numbers 1 through k on the die’s faces. If X is the number that appears, what is E(X)?
Solution:
$$
E(X) = \sum_{i=1}^K i \cdot P(X=i) = \sum_{i=1}^K i \frac 1 K = \frac 1 K \frac{K(K+1)}{2} =
\frac{K+1}{2},
$$
by using the Gauss’ infamous summation formula.
This is consistent with a 6 sided die having expectation value of 7/2.
We can also approximate the expectation value of a k = 117-sided die, which should be 118/2 = 59, by sampling as follows.
= 100000
num_samples = 117
k
=1, high=k+1, size=num_samples).mean() np.random.randint(low
59.03891