5

I read somewhere that the python library function random.expovariate produces intervals equivalent to Poisson Process events.
Is that really the case or should I impose some other function on the results?

PaulMcG
  • 62,419
  • 16
  • 94
  • 130
hizki
  • 709
  • 1
  • 8
  • 19

2 Answers2

8

On a strict reading of your question, yes, that is what random.expovariate does.

expovariate gives you random floating point numbers, exponentially distributed. In a Poisson process the size of the interval between consecutive events is exponential.

However, there are two other ways I could imagine modelling poisson processes

  1. Just generate random numbers, uniformly distributed and sort them.
  2. Generate integers which have a Poisson distribution (i.e. they are distributed like the number of events within a fixed interval in a Poisson process). Use numpy.random.poisson to do this.

Of course all three things are quite different. The right choice depends on your application.

Tarik
  • 10,810
  • 2
  • 26
  • 40
Adrian Ratnapala
  • 5,485
  • 2
  • 29
  • 39
  • About 1., @AdrianRatnapala, does a sequence of uniformly distributed random numbers on [0, 100], *sorted*, model a Poisson process? Why? – Basj Feb 10 '16 at 17:44
  • 1
    @Basj The need to sort also depends on the application. The Poission process is a _set_ (i.e. unordered) of uniformly distributed events. A list or array of generated data would also contain "unwanted" information about what order they were generated in. Sorting destroys that information. – Adrian Ratnapala Feb 11 '16 at 12:11
4

https://stackoverflow.com/a/10250877/1587329 gives a nice explanation of why this works (not only in python), and some code. In short

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)
Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188