Instead of three total friends, now suppose there are four total friends (yourself included). As before, you all arrive at random times during the hour and each stay for 15 minutes. On average, what would you expect the maximum number of friends meeting up to be?
OK, well now your other friend Wenceslas, whose arrival time is modeled by $W \sim U(0,1),$ joins in on the "plan" to randomly meet up at the mall. In this case, we can still calculate the maximum number of friends based on $W, X, Y, Z$ to be $$\tilde{N} = \tilde{N}(W,X,Y,Z) = \max_{t \in [0,3/4]} \# \left\{ s \in \{W,X,Y,Z\} \mid t \leq s \leq t + \frac{1}{4} \right\}.$$
Here I will resort to just coding up the function $\tilde{N}$ and throwing a Monte Carlo simulator at the problem. In particular, let's define the following two functions, since we might as well also code up and confirm our earlier function $N$, while we're at it.
import numpy as np def max_num_friends3(x,y,z): sort = np.sort(np.array([x,y,z])) d1 = sort[1]-sort[0] d2 = sort[2]-sort[1] if d1+d2 <= 0.25: return 3 elif min(d1,d2) <= 0.25: return 2 else: return 1 def max_num_friends4(w,x,y,z): sort = np.sort(np.array([w,x,y,z])) d1 = sort[1]-sort[0] d2 = sort[2]-sort[1] d3 = sort[3]-sort[2] if d1+d2+d3 <= 0.25: return 4 elif (d1+d2 <=0.25) or (d2+d3 <= 0.25): return 3 elif min(d1,d2,d3) <= 0.25: return 2 else: return 1
The following Monte Carlo setup was run, generating $S=100000$ simulations for $\tilde{N}$ and $4S$ simulations for $N$ (since we can take 4 selections of three from among $W, X, Y,$ and $Z$).
sims = 100000 t = [] f = [] x = np.random.uniform(size=(sims,)) y = np.random.uniform(size=(sims,)) z = np.random.uniform(size=(sims,)) u = np.random.uniform(size=(sims,)) for i in range(sims): mn4 = max_num_friends4(x[i], y[i], z[i], u[i]) f.append(mn4) mn3 = max_num_friends3(x[i], y[i], z[i]) t.append(mn3) mn3 = max_num_friends3(u[i], y[i], z[i]) t.append(mn3) mn3 = max_num_friends3(x[i], u[i], z[i]) t.append(mn3) mn3 = max_num_friends3(x[i], y[i], u[i]) t.append(mn3)
The sample average of $f$ was $m_f = 2.4752$ with sample standard deviation of $s_f = 0.59770,$ meaning that the SEM is $0.00189.$ Therefore, when there are a total of four friends randomly showing up at the mall, the 95% confidence interval on the expected maximum number of friends meeting up at one time is $2.4752 \pm 1.96 \cdot 0.00189 = [2.4715, 2.4789].$
For comparison, when there are three friends randomly showing up at the mall, the 95% confidence interval on the expected maximum number of friends meeting up at one time is $[2.029059, 2.032336],$ which contains the theoretical answer of $\mathbb{E}[N] = 65/32 = 2.03125.$
No comments:
Post a Comment