Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random draw from Poisson fails for large lambda #1633

Closed
jsbryan4 opened this issue Nov 2, 2022 · 1 comment
Closed

Random draw from Poisson fails for large lambda #1633

jsbryan4 opened this issue Nov 2, 2022 · 1 comment

Comments

@jsbryan4
Copy link

jsbryan4 commented Nov 2, 2022

When using "e" notation for large numbers, I notice that the Poisson distribution fails for orders of magnitude greater than 18.

For example look at the following code and output

using Distributions

println(rand(Poisson(1.0e10)))
println(rand(Poisson(1.0e11)))
println(rand(Poisson(1.0e12)))
println(rand(Poisson(1.0e13)))
println(rand(Poisson(1.0e14)))
println(rand(Poisson(1.0e15)))
println(rand(Poisson(1.0e16)))
println(rand(Poisson(1.0e17)))
println(rand(Poisson(1.0e18)))
println(rand(Poisson(1.0e19)))   # <---- Fails
println(rand(Poisson(1.0e20)))
9999837095
99999767161
1000000268447
10000002717295
100000005394573
1000000029583672
9999999992683622
99999999934764640
1000000000632877824
ERROR: InexactError: trunc(Int64, 1.0e19)
Stacktrace:
 [1] trunc
   @ ./float.jl:805 [inlined]
 [2] floor
   @ ./float.jl:367 [inlined]
 [3] PoissonADSampler
   @ ~/.julia/packages/Distributions/DiPwc/src/samplers/poisson.jl:54 [inlined]
 [4] PoissonADSampler
   @ ~/.julia/packages/Distributions/DiPwc/src/samplers/poisson.jl:49 [inlined]
 [5] sampler
   @ ~/.julia/packages/Distributions/DiPwc/src/univariate/discrete/poisson.jl:143 [inlined]
 [6] rand(rng::Random._GLOBAL_RNG, d::Poisson{Float64})
   @ Distributions ~/.julia/packages/Distributions/DiPwc/src/univariate/discrete/poisson.jl:147
 [7] rand(::Poisson{Float64})
   @ Distributions ~/.julia/packages/Distributions/DiPwc/src/genericrand.jl:22
 [8] top-level scope
   @ ~/Desktop/Projects/StructuredIlluminationInference/examples/scratch.jl:14
@devmotion
Copy link
Member

I'll close the issue since it is a duplicate of #821.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants