Repository navigation
Conversation
…e/dists/rayleigh/pdf` For `sigma` outside about [1.5e-154, 1.3e154], `sigma^2` (or `x^2`) overflows or underflows, so the PDF came out NaN or 0 where it is finite: `pdf( 1e200, 1e200 )` returned NaN instead of about 6.065e-201. Same approach as `rayleigh/logpdf` (stdlib-js#15923): the existing expression is kept wherever it is safe, bit for bit on every existing fixture point, and the ratio `x/sigma` is used otherwise.
…/pdf` Generated by a new `gen_extended` in 2048-bit BigFloat, with `sigma` on either side of the range where `sigma^2` over- or underflows and `x/sigma` in [1e-3, 1]. develop fails all 2,000 points; this branch is within 2 ULP. The existing fixtures and `gen` are unchanged.
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:
1instats/base/dists/rayleigh/pdf(JS, factory and C).For
sigmaoutside about[1.5e-154, 1.3e154],sigma^2(orx^2) overflows or underflows, so the PDF comes outNaNor0where it is finite:This is the follow-up I mentioned in #15923, using the same approach. The existing expression is kept wherever it is safe —
sigma^2normal with2*sigma^2finite (the1e154case you found on #15923),x^2finite,x/sigma^2normal — and on all 3,000 points of the existing fixtures the result is bit-for-bit identical todevelop. Otherwise it usesx/sigma:(r/sigma) * exp(-r^2/2), falling back toexp( ln(r) - ln(sigma) - r^2/2 )whenx/sigma^2overflows, i.e. for a tinysigma, where the exponential decides the result.Tests, and why the existing fixtures weren't regenerated this time. On #15923 you asked for the old fixtures to be regenerated in extended precision. I tried the same here. Against a 2048-bit reference,
develop— and this PR, being bit-identical there — is up to 691 ULP off on the existing fixtures, atx/sigma ≈ 34. That'sexp(-r^2/2)amplifying the rounding ofx^2/(2*sigma^2)by its own magnitude (~590 at that point), which any double-precision evaluation inherits. The old Float64 Julia fixtures share that rounding, so they pass at 2 ULP. Regenerating them would mean loosening those tolerances to ~700 ULP for a part of the function this PR doesn't change.So
genand the three existing fixtures are untouched. A separategen_extended(2048-bitBigFloat, textbook formula) writes two new fixtures:tiny_scale.json:sigmain[1e-200, 1e-155], wheresigma^2underflows.huge_scale.json:sigmain[1e155, 1e200], where it overflows.Both use
x/sigmain[1e-3, 1], so they test the new branch rather than that conditioning. On them this PR is within 2 ULP, the existing tolerance;developfails all 2,000 points in bothtest.pdf.jsandtest.factory.js.test.pdf.js/test.factory.js/test.native.jspass 5,014 each. If you'd still prefer the old fixtures regenerated, I'll do that and set those three blocks' tolerances from the measured errors instead.Related Issues
None. Follow-up to #15923 (
rayleigh/logpdf), as mentioned there.Questions