Figure 5.6:

A sample path of the unit Poisson process.

Code for Figure 5.6

Text of the GNU GPL.

main.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import matplotlib.pyplot as plt

nsam = 11

np.random.seed(10)

p = np.random.rand(nsam, 1)
tau = -np.log(p)
time = np.cumsum(tau, axis=0)
time = np.insert(time, 0, 0, axis=0)

Y = np.arange(nsam + 1)

xx, yy = np.repeat(time, 2)[1:-1], np.repeat(Y, 2)[:-2]  # Equivalent to stairs without the last element

plt.figure()
plt.plot(xx, yy)
plt.show(block=False)

plt.figure()
plt.hist(tau, bins=20)
plt.show(block=False)

table = np.column_stack((xx, yy))
with open("unitpoisson.dat", "w") as f:
    np.savetxt(f, table, fmt='%f', header="time Y")