Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate discrete random events with a Poisson distribution?

I'm aware of Knuth's algorithm for generating random Poisson distributed numbers (below in Java) but how do I translate that into calling a method, generateEvent(), randomly over time?

int poissonRandomNumber(int lambda) {
    double L = Math.exp(-lambda);
    int k = 0;
    double p = 1;
    do {
        k = k + 1;
        double u = Math.random();
        p = p * u;
    } while (p > L);
    return k - 1;
}
like image 404
blank Avatar asked Feb 05 '10 09:02

blank


People also ask

How do you generate a random number in a Poisson distribution?

r = poissrnd( lambda ) generates random numbers from the Poisson distribution specified by the rate parameter lambda . lambda can be a scalar, vector, matrix, or multidimensional array.

How do you generate random timings for a Poisson process?

Simply choose a random point on the y-axis between 0 and 1, distributed uniformly, and locate the corresponding time value on the x-axis. For example, if we choose the point 0.2 from the top of the graph, the time until our next earthquake would be 64.38 minutes.

Is Poisson a discrete random variable?

Revised on August 26, 2022. A Poisson distribution is a discrete probability distribution. It gives the probability of an event happening a certain number of times (k) within a given interval of time or space. The Poisson distribution has only one parameter, λ (lambda), which is the mean number of events.

Can Poisson distribution be discrete continuous?

The Poisson distribution is a discrete function, meaning that the variable can only take specific values in a (potentially infinite) list. Put differently, the variable cannot take all values in any continuous range.


1 Answers

If you are looking to simulate the inter-event arrival time, you want the exponential distribution.

Take a look at Pseudorandom Number Generator - Exponential Distribution

Your code would then look like this:

// Note L == 1 / lambda
public double poissonRandomInterarrivalDelay(double L) {
    return (Math.log(1.0-Math.random())/-L;
}

...

while (true){
    // Note -- lambda is 5 seconds, convert to milleseconds
    long interval= (long)poissonRandomInterarrivalDelay(5.0*1000.0);
    try {
        Thread.sleep(interval);
        fireEvent();
}
like image 143
Jay Elston Avatar answered Sep 28 '22 04:09

Jay Elston