Skip to content
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

Remove u64 support for Poisson #1517

Merged
merged 4 commits into from
Oct 24, 2024
Merged

Remove u64 support for Poisson #1517

merged 4 commits into from
Oct 24, 2024

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Oct 24, 2024

  • Added a CHANGELOG.md entry

Summary

Counter-proposal to #1516.
Reverts part of #1498.
Closes #1323 (doc change only).

Motivation

Where only Distribution<F> for F: Float is supported, Rust is reasonably good at inferring the intended sampling type. When Distribution<u64> is supported too, much more type annotation is needed which is annoying.

Also as noted in #1516, saturating to u64::MAX may not be appropriate in all use-cases.

@benjamin-lieser
Copy link
Collaborator

For Possion we have the garantie that it will not exceed u64::MAX, we should document that and encourage people to cast it to an integer.

For Zipf we should have the same garantie, because it takes n : u64 and the samples should be <=n. It is probably worth checking and potentially documenting if this can be violated due to rounding errors.

@dhardy
Copy link
Member Author

dhardy commented Oct 24, 2024

garantie

Is it a guarantee for Poisson or "just" P(event) <= 1e-1000? Though by some definitions I can see that being sufficient.

What would the equivalent limit be for u32::MAX?

@benjamin-lieser
Copy link
Collaborator

benjamin-lieser commented Oct 24, 2024

garantie

Is it a guarantee for Poisson or "just" P(event) <= 1e-1000? Though by some definitions I can see that being sufficient.

What would the equivalent limit be for u32::MAX?

It is more than 1e6 standard deviations away, so it is actually more like at least 1e-1000000. My guess is that you can prove it is actually impossible with f64 but I have not tried it. In any case there is no way that a saturation could effect any real application. It is dramatically more likely that any computer running it will be hit by a meteor during the calculation than actually saturating on u64

If you take 4.2e9 as limit, you get 4.2e9 + 1465 * sqrt(4.2e9) < 2**32
Even though there are just 1465 standard deviations it is still less likely than the meteor.

I found a way to calculate the probabilities:
For the first it is 10 ^(-5e11)
For the second it is 10 ^(-1e6)

@dhardy dhardy merged commit 0c36c6c into rust-random:master Oct 24, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It is not reasonable for rand_distr::Zipf to return floating-point values
2 participants