Repository navigation
Conversation
…logcdf` `1 - p` rounds away the low-order bits of `p`. For `p < 2^-53` the function returned `-Infinity`. Below `p = 0.5`, use `log1mexp( (x+1) * log1p(-p) )`; above it `1-p` is exact and the old form is kept. The fixtures are generated from the textbook formula in extended precision.
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
|
||
| # Tiny `p`: | ||
| x = rand( 1000 ) .* 100.0; | ||
| p = exp10.( range( -300.0, stop = -1.0, length = 1000 ) ); |
There was a problem hiding this comment.
| p = exp10.( range( -300.0, stop = -1.0, length = 1000 ) ); | |
| p = exp10.( range( -323.0, stop = -1.0, length = 1000 ) ); |
Non-blocking: this also covers subnormal p, and the tests still pass. Unlike #15797 (comment), no extra branch is needed here, since x+1 >= 1 keeps (x+1)*log1p(-p) exact.
|
@0PrashantYadav0 thanks. I tried the |
Description
This pull request:
stats/base/dists/geometric/logcdffor smallp(JS, factory and C).The function computed
log1p( -pow( 1.0-p, x+1.0 ) ). Forming1 - prounds away the low-order bits ofp, and forp < 2^-53it rounds to1, so the result is-Infinity:For
p < 0.5it now useslog1mexp( (x+1) * log1p(-p) ). Forp >= 0.5,1 - pis exact, so the old form stays. There it is more accurate than going throughlog1p, because forpnear1the error in(x+1) * log1p(-p)gets multiplied by its own magnitude.Fixtures and tests:
runner.jlnow evaluates the textbook formulaln(1 - (1-p)^(floor(x)+1))in 2048-bitBigFloatinstead ofDistributions.logcdf. Distributions computes in double precision with the same loss.Distributionsis dropped fromREQUIRE.small_p.jsonandlarge_p.jsonare regenerated with the same input ranges.New
tiny_p.json:plog-spaced over[1e-300, 0.1],xin[0, 100].Max error against the new fixtures, JS and native:
developlarge_psmall_ptiny_p-Infinityforp < 2^-53The tolerances are set to those values (were 42 and 15). On
develop, 1,006 of the 3,012 assertions intest.logcdf.jsfail. With this change they all pass.Related Issues
None. Companion to #15765 (
geometric/cdf).Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. I found the bug by reading the
stats/base/distsfunctions for1 - pcancellation.@stdlib-js/reviewers