Use Stirling's approximation to expand range of Poisson pmf #1
+144
−12
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.
The Poisson distribution is well behaved for large input values,
but the factorial form is not numerically stable and has a hard-coded
limit for its input values. Using Stirling's Approximation for the
logarithm of the factorial, we can rewrite the probability as a
sum of the logarithm of its terms, which is numerically stable.
This commit includes two new Poisson distribution functions as well
as modifications to the current distribution function. The factorial
form is called pmf_poisson_factorial and is a slight variant on the
original code that sets all probabilities for large input x to zero.
Perhaps a value of -1 would be better. The Stirling form is called
pmf_poisson_stirling and uses Stirling's approximation for all
values of x. This leads to numerically inaccurate results for very
small values of the input argument (though the inaccuracy is minor).
The Combined form is called pmf_poisson and uses the factorial form
for small values of x (roughly < 85) and the Stirling form for large
values of x.
Results from the Stirling and factorial forms differ, but that
difference falls within numerical bit noise for x roughly at
50.
This commit does not include tests. It is intended to demonstrate
the different forms. If accepted, tests should be fairly easy and
should follow shortly.