How do I generate a Poisson Process?
If you have a Poisson process with rate parameter L (meaning that, long term, there are L arrivals per second), then the inter-arrival times are exponentially distributed with mean 1/L. So the PDF is f(t) = -L*exp(-Lt), and the CDF is F(t) = Prob(T < t) = 1 - exp(-Lt). So your problem changes to: how to I generate a random number t with distribution F(t) = 1 - \exp(-Lt)?
Assuming the language you are using has a function (let's call it rand()
) to generate random numbers uniformly distributed between 0 and 1, the inverse CDF technique reduces to calculating:
-log(rand()) / L
As python provides a function to generate exponentially distributed random numbers, you could simulate the first 10 events in a poisson process with an averate rate of 15 arrivals per second like this:
import random
for i in range(1,10):
print random.expovariate(15)
Note that that would generate the *inter*arrival times. If you wanted the arrival times, you would have to keep moving a time variable forward like this:
import random
t= 0
for i in range(1,10):
t+= random.expovariate(15)
print t
Here's sample code for generating Poisson samples using C++ TR1.
If you want a Poisson process, times between arrivals are exponentially distributed, and exponential values can be generated trivially with the inverse CDF method: -k*log(u) where u is a uniform random variable and k is the mean of the exponential.