You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The follow programs appear to hang indefinitely in the call poisson.sample(&mut rng):
f32
use rand_distr::{Distribution, Poisson};
fn main() {
let lambda = 1.0e37f32;
let poisson = Poisson::<f32>::new(lambda).unwrap();
let mut rng = rand::thread_rng();
let k = poisson.sample(&mut rng);
println!("{}", k);
}
f64
use rand_distr::{Distribution, Poisson};
fn main() {
let lambda = 1.0e306f64;
let poisson = Poisson::<f64>::new(lambda).unwrap();
let mut rng = rand::thread_rng();
let k = poisson.sample(&mut rng);
println!("{}", k);
}
can also overflow, because result will be $\lambda + c\sqrt{\lambda}$, where $c$ is not large. ($\sqrt{\lambda}$ is the standard deviation of the Poisson distribution.)
There is another problem with large $\lambda$, even if it isn't large enough to cause overflow: the terms being subtracted in the expressions shown above will be very close, resulting in significant loss of precision.
I've looked into modifying the calculation when $\lambda$ is large to use an asymptotic version of the check expression, but I don't have anything useful yet.
A different approach to avoiding the problem would be switch to a normal distribution when $\lambda$ is sufficiently large. Convential wisdom is that the normal distribution is a good approximation to the Poisson distribution when $\lambda$ is large, but it would be nice to have a more quantitative result on the quality of the approximation. (John D. Cook has a short blog post about it.)
The follow programs appear to hang indefinitely in the call
poisson.sample(&mut rng)
:f32
f64
I ran into this issue while testing gh-1296.
The text was updated successfully, but these errors were encountered: