For complete written solutions, please see. We will mainly be concerned with the Python code here.
import numpy as np
number=10000
inter = np.random.exponential(1/2,number) #notice it is parametrized by scale rather than rate
arr = np.cumsum(inter)
L = len(arr)
coin = np.random.binomial(1,0.5, L)
coinindex=-99
for i in range(L):
if coin[i]==0:
coinindex = np.append(coinindex, i)
coinindex = np.delete(coinindex, 0)
arrthin = np.delete(arr,coinindex)
interthin = arrthin[0]
for i in range(len(arrthin)-1):
interthin = np.append(interthin, arrthin[i+1] - arrthin[i])
import matplotlib.pyplot as plt
z=interthin
plt.hist(z, bins = 50, density=True, label='Proability Histogram')
t=np.linspace(0,5,num=2000)
plt.plot(t,1*np.exp(-1*t), label='Exact Density')
plt.legend(loc='upper left')
plt.show()
def point():
x=1
y=1
while(x**2 + y**2 >=1):
x= 2*np.random.uniform() -1
y= 2*np.random.uniform() -1
return np.array([x,y])
pois = [point() for _ in range(np.random.poisson(100*np.math.pi) ) ]
L= len(pois)
x=100
y=100
for i in range(L):
x = np.append(x, pois[i][0])
y = np.append(y, pois[i][1])
x = np.delete(x, 0)
y = np.delete(y, 0)
import matplotlib.pyplot as plt
t=np.linspace(-1,1,num=500)
plt.figure(figsize = (10,10))
plt.plot(x,y, 'r*')
plt.plot(t, np.sqrt(1-t**2))
plt.plot(t, -np.sqrt(1-t**2))
plt.title("Poisson process on a disc", fontsize=10)
plt.show()
from datetime import datetime
print(datetime.now())
2021-10-23 22:12:38.767520