-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHANGE: Poisson distribution return type, change from float to integer #1093
Comments
See also #958. |
@dhardy I think most of the discussion is in #987. As you noted, the reason we return an
While I agree that we are leaking an implementation detail here, I'm not convinced the more intuitive API outweighs those disadvantages. (Note that in a way it is unavoidable to leak implementation details via the return type: There are many different ways to represent a number, and we either have to pick or make the code generic.) |
Thanks for the replies! We are already making the code somewhat generic through the |
In #987 the argument against a u64 impl is that we shouldn't have potentially panicking code in the lib — but it's a weak argument since it is difficult to do better. We could instead have an impl returning So maybe the best thing is to add a |
I also strongly believe that we should not have a spontaneously panicking impl. At the very least we should use something like |
That's a really interesting idea - rerunning generation, in the case of a number falling outside the |
We could limit |
@newpavlov this is now the behaviour of
Why? That affects the distribution more. And if you're really generating |
We still need to make a decision. Personally, I would go with suggesting to use |
Is there enough discussion and consensus that I should close the issue? Is there anything valuable that I could contribute or help with here? It seems like there is no obviously best solution, and leaving the Poisson as float seems reasonable to me. |
I think we should document our rationale for the return types somewhere.
Maybe in the Rand book?
|
Thanks team. I've submitted a PR for rationale documentation. |
Summary
As a discrete probability distribution, the intuitive return type for Poisson random variates would seemingly be an integer type covering the distribution's support. This output strategy is already employed by other discrete probability distributions in rand_distr, like the "Bernoulli-related" Binomial distribution, Geometric distribution, and Hypergeometric distribution.
Details
The Poisson distribution implementation would need to be revised, to return a u64 (if following the Binomial, Geometric, and Hypergeometric precedent), instead of the current Float return type - a breaking API change. In addition to the API change, the internal implementation/calculations would need some revisions.
Motivation
What is the motivation for this change?
Making this change could make the crate more intuitive and dependent programs cleaner. Fundamentally, Poisson random variates are unsigned integers, so representing them as signed floats seems unintuitive. To me, this seems like an API made to match an internal implementation, rather than an API to match real-world intuition.
Alternatives
The Poisson random variates can be either f64 or f32, but some basic type casting logic is nevertheless fairly straightforward. Any of the possible type casts require some thought around truncation, etc., but I don't see any major issues with the cast strategy.
Notes
Through some digging, I see that a u64 return type was the initial implementation #96, yet this was later modified c03e2c8. Are we calling this a "done deal" and settling on the float return type? If there's shared interest in revisiting this, I could take a stab at the PR.
The text was updated successfully, but these errors were encountered: