Repository navigation
Change PoissonADSampler threshold to 10 - #2060
Merged
Merged
Conversation
Ahrens-Dieter PD (`PoissonADSampler`) is designed for μ ≥ 10; the hat function bounds the residual between the discretized normal and the poisson pmf correctly for that threshold, below it the rejection step is no longer exact. Threshold now requires μ ≥ 10 for AD; μ < 10 uses PoissonCountSampler.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2060 +/- ##
==========================================
- Coverage 86.65% 86.63% -0.02%
==========================================
Files 148 149 +1
Lines 8919 8921 +2
==========================================
Hits 7729 7729
- Misses 1190 1192 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
devmotion
reviewed
Apr 26, 2026
Comment on lines
+10
to
+12
| let n = 100_000_000, μ = 6.0, tol = 5 * sqrt(μ / n) | ||
| @test abs(sum(rand(Poisson(μ)) for _ in 1:n) / n - μ) < tol | ||
| end |
Member
There was a problem hiding this comment.
Minor nitpick: Could you change this to a @testset? It would also be a bit more natural to use @test ... ≈ ... atol = ....
1 task done
devmotion
reviewed
Jun 19, 2026
Co-authored-by: David Müller-Widmann <devmotion@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Another one that came up when I was going through some of the older papers for sampling algorithms:
In the Poisson sampler, the threshold at which
PoissonADSamplerkicks in is currentlyμ >= 6, but the Ahrens-Dieter PD algorithm says it is designed forμ >= 10. I am not sure why 6 was chosen (it looks like it was originally from PoissonRandom.jl, see #1021 but I don't see anything beyond that). To verify that this is actually a problem: if you plot the hat function (equation 24) against the residual between the discretized normal and the poisson PMF, you will see that at 6 it definitely goes outside the bounds. With the following:In terms of demonstrating the bias, right now the sampler tests only check down to
10.0, not6.0:Distributions.jl/test/samplers.jl
Line 63 in a7ed7b6
You can detect it at 6, but I found that you need to use
n=10^8(I included a regression test in the PR which fails on master). At μ=7 it requiresn=10^9, I didn't go further than that.Note: I think you would expect performance regressions for this change for values of μ from 6 to 9, since
PoissonADSamplershould be faster down to 6.