diff --git a/src/univariate/discrete/poisson.jl b/src/univariate/discrete/poisson.jl index 11205238ba..f098edd7b6 100644 --- a/src/univariate/discrete/poisson.jl +++ b/src/univariate/discrete/poisson.jl @@ -135,7 +135,8 @@ fit_mle(::Type{<:Poisson}, ss::PoissonStats) = Poisson(ss.sx / ss.tw) ## samplers -const poissonsampler_threshold = 6 +# PoissonADSampler is biased for μ < 10 +const poissonsampler_threshold = 10 function sampler(d::Poisson) if rate(d) < poissonsampler_threshold diff --git a/test/univariate/discrete/poisson.jl b/test/univariate/discrete/poisson.jl index 0861de4a7f..d3384446c1 100644 --- a/test/univariate/discrete/poisson.jl +++ b/test/univariate/discrete/poisson.jl @@ -4,6 +4,16 @@ test_cgf(Poisson(1 ), (1f0,2f0,10.0,50.0)) test_cgf(Poisson(10 ), (1f0,2f0,10.0,50.0)) test_cgf(Poisson(1e-3), (1f0,2f0,10.0,50.0)) +# Regression: PoissonADSampler is biased for low values of μ +# because the Ahrens-Dieter algorithm is only designed for μ ≥ 10; +# Threshold now requires μ ≥ 10 for AD; μ < 10 uses PoissonCountSampler. +@testset "Poisson sampler bias for μ < 10" begin + n = 100_000_000 + μ = 6.0 + tol = 5 * sqrt(μ / n) + @test sum(rand(Poisson(μ)) for _ in 1:n) / n ≈ μ atol = tol +end + @testset "Poisson suffstats and OffsetArrays" begin a = rand(Poisson(), 11) wa = 1.0:11.0