CS计算机代考程序代写 In [43]:

In [43]:
import numpy as np
import sympy
In [44]:
def lmbda(t):
return np.sin(t/60) + 10

def thinning(T):
# Maximum of sin function is 1, so maximum
# of lambda(t) is just 11.
lmbda_max = 11

t0 = -1/lmbda_max * np.log(np.random.rand())
t = t0
arrivals = []
while t < T: if np.random.rand() < lmbda(t) / lmbda_max: arrivals.append(t) t0 = -1/lmbda_max * np.log(np.random.rand()) t += t0 return np.array(arrivals) arrivals = thinning(8 * 60) inter_arrivals = np.diff(np.insert(arrivals, 0, 0)) print(np.mean(inter_arrivals)) print(len(inter_arrivals)) 0.10087679487921243 4758