Conversation
…dists/cosine/pdf` `1 + cos(pi*z)` cancels as `z` approaches -1 or 1, and the density was `0` there although it is positive. Use `1 + cos(pi*z) = 2*cos(pi*z/2)^2`. The fixtures are now generated from the textbook formula in extended precision, with `x` inside the support: `positive_mean.json` held only out-of-support points, so its test checked nothing.
5 of 7 tasks
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/cosine/pdfascospi(z/2)^2 / sinstead of( 1 + cospi(z) ) / (2s)(JS, factory and C),1 + cos(pi*z)cancels asz = (x-mu)/sapproaches-1or1. Close to the edges of the support the density is0, although it is positive there:1 + cos(pi*z) = 2*cos(pi*z/2)^2holds exactly, so this form has no subtraction.Fixtures and tests (the same changes as #15874 for
logpdf):runner.jlevaluates(1 + cos(pi*z)) / (2s)in 2048-bitBigFloatinstead ofDistributions.pdf.xis now drawn inside the support.positive_mean.jsonhad all 1,000 points outside the support, so its test checked nothing, andnegative_mean.jsonhad 968 of 1,000.There's a new
edges.jsonwith1 - |z|log-spaced over[1e-15, 0.1](mu = 0,sa power of two).Max error in JS and native, against the exact values:
developpositive_meannegative_meanlarge_varianceedges0The tolerances are set to those values. The remaining error comes from rounding
z = (x-mu)/sclose to an edge, where the density is very sensitive toz. Ondevelop, 1,016 of the 4,022 assertions intest.pdf.jsfail. With this change they all pass.Related Issues
None. Companion to #15874 (
cosine/logpdf).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 scanning
stats/base/distsfor1.0 + cos....@stdlib-js/reviewers