Turing.jl
Turing.jl copied to clipboard
Safety for poisson random calls
Hi everyone,
Base Julia can't convert large floats into Int
type using floor
or round
etc. This creates a problem for sampling from Poisson's with a large mean because this is used in fast polyalgo for Poisson sampling.
e.g.
using Distributions
log_μ = 48.0 #Plausible value in a log-scale random walk with a Poisson link
d = Poisson(exp(log_μ))
rand(d)
ERROR: InexactError: trunc(Int64, 7.016735912097631e20) Stacktrace: [1] trunc @ ./float.jl:905 [inlined] [2] floor @ ./float.jl:383 [inlined] [3] PoissonADSampler @ ~/.julia/packages/Distributions/oGEEM/src/samplers/poisson.jl:54 [inlined] [4] PoissonADSampler @ ~/.julia/packages/Distributions/oGEEM/src/samplers/poisson.jl:49 [inlined] [5] sampler @ ~/.julia/packages/Distributions/oGEEM/src/univariate/discrete/poisson.jl:144 [inlined] [6] rand(rng::Random.TaskLocalRNG, d::Poisson{Float64}) @ Distributions ~/.julia/packages/Distributions/oGEEM/src/univariate/discrete/poisson.jl:148 [7] rand(::Poisson{Float64}) @ Distributions ~/.julia/packages/Distributions/oGEEM/src/genericrand.jl:22 [8] top-level scope @ REPL[18]:1
Now this would not be problematic, because the logpdf
calls are not affected but for some reason a rand
call comes into using Turing
at inference time (not sure why...).
Is there any chance of a safer version of the Poisson/Negative Binomial that can detect if round(BigInt, ...
should be used?