Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

java - Simulating Poisson Waiting Times

I need to simulate Poisson wait times. I've found many examples of simulating the number of arrivals, but I need to simulate the wait time for one arrival, given an average wait time.

I keep finding code like this:

public int getPoisson(double lambda) 
{   
    double L = Math.exp(-lambda);   
    double p = 1.0;   
    int k = 0;   

    do 
    {    
        k++;     
        p *= rand.nextDouble(); 
        p *= Math.random(); 
    } while (p > L);   

    return k - 1; 
} 

but that is for number of arrivals, not arrival times.

Efficieny is preferred to accuracy, more because of power consumption than time. The language I am working in is Java, and it would be best if the algorithm only used methods available in the Random class, but this is not required.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Time between arrivals is an exponential distribution, and you can generate a random variable X~exp(lambda) with the formula:

-ln(U)/lambda` (where U~Uniform[0,1]). 

More info on generating exponential variable.

Note that time between arrival also matches time until first arrival, because exponential distribution is memoryless.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...