Repository navigation
Conversation
…s/laplace/logcdf` Above the mean, `ln(1/2) + log1p( 1 - exp(-z) )` cancels and rounds to 0: `logcdf( 50, 0, 1 )` returned 0 instead of about -9.64e-23. Use the equivalent `log1p( -exp(-z)/2 )`. The fixtures came from Distributions.jl's Float64 logcdf, which has the same cancellation, and were asserted at 0 ULP; they are now evaluated in 2048-bit BigFloat, with tolerances set from measured error.
Contributor
|
Hello! Thank you for your contribution to stdlib. We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
This acknowledgment confirms that you've read the guidelines, which include:
We can't review or accept contributions without this acknowledgment. Thank you for your understanding and cooperation. We look forward to reviewing your contribution! |
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This pull request:
stats/base/dists/laplace/logcdfwithout cancellation (JS, factory and C).Above the mean the function computed
ln(1/2) + log1p( 1 - exp(-z) ). That'sln(1/2) + ln(2 - exp(-z)), which cancels and rounds to0onceexp(-z)is below an ULP of2:It now uses the equivalent
log1p( -exp(-z)/2 ), which has no subtraction. The lower branch andx = muare unchanged.Fixtures and tolerances. The fixtures came from Distributions.jl's
logcdf, which evaluates the same expression inFloat64, and the tests asserted them at 0 ULP. Sodevelopwas being checked for bit-equality with a reference that has the same cancellation.gennow evaluates the log CDF in 2048-bitBigFloat, and all three fixtures were regenerated. Measured against them:develop: p99 / max ULPpositive_meannegative_meanlarge_variance0)The tolerances are set from those numbers: 1, 1 and 160 ULP. The 160 is not slack in the formula. Far above the mean the result is about
-exp(-z)/2, so the rounding ofz = (x-mu)/bgets amplified byz, andlarge_variancereachesz ≈ 120. Any double-precision evaluation hits that; there's a comment on the assertion saying so.test.logcdf.js/test.factory.js/test.native.jspass 3,013 / 3,018 / 3,013.Related Issues
None.
Questions