= 10
n
= 2
lambda
= rexp(n, rate = lambda)
w
= cumsum(c(0, w))
t
plot(t, 0:n,
type = "s",
xlab = "time, t", ylab = "Number of events, N(t)",
main = paste("Sample path of Poisson process with rate", lambda))
Poisson Processes
Simulate sample path: fixed number of events
Simulate times between events as i.i.d. Exponential
Simulate sample path: fixed time
- Simulate total number of events as Poisson(\(\lambda T\))
- Given number of events, simulate times of events as i.i.d. Uniform(0, \(T\)), sorted from smallest to largest
= 10
T
= 2
lambda
= rpois(1, lambda * T)
N_T
= runif(N_T, 0, T)
u
= c(0, sort(u))
t
plot(t, 0:N_T,
type = "s",
xlab = "time, t", ylab = "Number of events, N(t)",
main = paste("Sample path of Poisson process with rate", lambda))
Many sample paths
from symbulate import *
from matplotlib import pyplot as plt
= PoissonProcessProbabilitySpace(rate = 2)
P
= RV(P) N
plt.figure()5).plot()
N.sim(; plt.show()
plt.figure()100).plot()
N.sim(; plt.show()
Distribution of process values
;
plt.figure()
5].sim(10000).plot()
N[2 * 5).plot()
Poisson(
plt.show()
;
plt.figure()
5] - N[3]).sim(10000).plot()
(N[2 * (5 - 3)).plot()
Poisson(
plt.show()
Times between events
= RV(P, interarrival_times) W
;
plt.figure()0].sim(10000).plot()
W[= 2).plot()
Exponential(rate ; plt.show()
;
plt.figure()0] & W[1]).sim(10000).plot()
(W[; plt.show()
Times of events
= RV(P, arrival_times) T
;
plt.figure()0].sim(10000).plot()
T[= 1, rate = 2).plot()
Gamma(shape ; plt.show()
;
plt.figure()1].sim(10000).plot()
T[= 2, rate = 2).plot()
Gamma(shape ; plt.show()
Short time interval
;
plt.figure()0.05].sim(10000).plot()
N[; plt.show()
Conditional distribution
;
plt.figure()2] | (N[5] == 10) ).sim(10000).plot()
(N[10, 2 / 5).plot()
Binomial(; plt.show()
Conditional distribution of arrival times
;
plt.figure()0] | (N[2] == 1) ).sim(10000).plot()
(T[0, 2).plot()
Uniform(; plt.show()
;
plt.figure()0] & T[1]) | (N[2] == 2) ).sim(1000).plot()
((T[; plt.show()
Order statistics of Uniform
;
plt.figure()= Uniform(0, 2) ** 2
P = RV(P, min)
U1 = RV(P, max)
U2 & U2).sim(1000).plot()
(U1 ; plt.show()
Waiting time paradox
= 10000
Tmax = 5 #mean time between buses
T = 2
lambda
= rpois(1, lambda * Tmax)
N_commuters = sort(runif(N_commuters, 0 , Tmax))
W_commuters = rpois(1, Tmax / T)
N_buses = sort(runif(N_buses, 0 , Tmax))
W_buses
= rep(NA, N_commuters)
waiting_time for (i in 1:N_commuters){
if (W_commuters[i] < max(W_buses)){
= min(W_buses[W_buses > W_commuters[i]]) - W_commuters[i]
waiting_time[i]
}
}mean(waiting_time, na.rm = TRUE)
[1] 5.15143
hist(waiting_time, freq = FALSE)
curve(dexp(x, 1 / T), add = TRUE)