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
MAINT: Use expm1(x) instead of exp(x) - 1 #15346
Conversation
gaurav1086
commented
Jan 18, 2020
@bashtage, can you comment on stream compatibility here? |
Good idea in distributions but legacy should not change unless something isn't compiling. Doesn't really affect the stream except that in very rare cases one might see a different number. I'm not sure that standard exponential would ever produce a value where the precision difference would appear since there are only 2**53 ish distinct values possible. |
Are there numerical difference in reasonable sample sizes? As in any different values generated? |
I do not fully understand what this means, but in double precision, almost 50% of the samples drawn by |
I didn't have any idea for which values of expm1(x) and exp(x)-1 differ. The example at the top (1e-99)doesn't seem useful for random pareto, although It could matter for large values of |
@gaurav1086 would it be possible to add a test that would notice the loss of numerical precision if we changed things back? |
@seberg , sure, I think that would be a good idea. |
@gaurav1086 could you add the small test? Would be nice to finish this up, since it is an obvious improvement. Let me know if you need pointers for doing that. |
@seberg , sorry for the delay. Will add it today. Thank you. |
@seberg , added the test in numpy/numpy/random/tests/test_random.py def test_pareto_expm1(self): Currently,
After the change, it should be non-zero of very small magnitude. Please correct me if I am wrong. Thank you. |
@gaurav1086 thanks, the test actually fails on master. On the up-side, it is supposed to fail, since |
@seberg , I changed random_pareto() in distribution.c . The legacy was another change which I reverted back. |
@gaurav1086 yes, but your test tests the legacy one, so it fails. Can you fix the test? |
You should try running tests locally before pushing. Your fix does not work:
|