Generating a Poisson Random Variable
Hi,
I'm afraid I'm not a professional Java programmer, nor a mathematician,
but I'd like to be able to generate a set of integers with a Poisson
distribution around a starting value (lambda). The application for which
I wish to do this is deriving confidence limits for analysis of radio
meteor observations.
<http://www.radiometeor.plus.com/>
The method I'm using, derived from "Simulation and the Monte Carlo
Method", by Rubinstein and Kroese works well for small starting values.
But, as the text of this book the algorithm becomes slow for large
starting values of lambda. In my case, the algorithm becomes
impractically slow as Lambda increases above about 745. Some radio
meteor observers have hour counts which exceed this value.
Does anyone have code to implement any alternative method to derive a
Poisson random variable?
Many thanks.
/*
* TestPoissonDistribution.java
* A method to test the Poisson distribution generator.
*/
import java.util.Random;
public class TestPoissonDistribution
{
public static void main(String[] args)
{
for(int i = 0; i <= 600; i++)
{
System.out.println();
for(int j = 0; j <= 10; j++)
{
System.out.print(distribute(i) + ", ");
}
}
}
/**
* A method to randomize a value based on a Poisson distribution.
* @param lambda The starting value.
* @return The integer which forms part of the distribution
* See pp 65 of Simulation and the Monte Carlo Method by
* Rubinstein and Kroese
*/
public static int distribute(int lambda)
{
int n = 1;
double a = 1.0;
Random r = new Random();
while(true)
{
a *= r.nextDouble();
if(a < Math.exp((double)-lambda)) break;
n += 1;
}
return n - 1;
}
}
--
David Entwistle