Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/univariate/discrete/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
devmotion marked this conversation as resolved.

function sampler(d::Poisson)
if rate(d) < poissonsampler_threshold
Expand Down
10 changes: 10 additions & 0 deletions test/univariate/discrete/poisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading