How do I generate a Poisson Process?

后端 未结 8 2067
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 06:07

Original Question:

I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter

8条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 07:02

    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
    

提交回复
热议问题