Repository navigation
test: migrate stats/base/dists/invgamma/entropy to ULP-based assertions - #15478
Merged
Merged
Conversation
…ions Replaces the relative tolerance comparison (`1e-10 * abs( expected[i] )`) in `test/test.js` and `test/test.native.js` with ULP difference assertions using `@stdlib/assert/is-almost-same-value`. The ULP bound is `90112`, which is the measured minimum over the full fixture set (200 cases) for both the JavaScript and C implementations; `90111` fails one case. Ref: #11352 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BX6G1VLr8YZ78tW8PGEvhn
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
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.
Resolves a part of #11352.
Description
This pull request:
stats/base/dists/invgamma/entropyfrom relative tolerance assertions to ULP difference assertions using@stdlib/assert/is-almost-same-value.test/test.jsandtest/test.native.js, replacing thedelta/tolcomparison against1e-10 * abs( expected[i] )witht.strictEqual( isAlmostSameValue( y, expected[ i ], 90112 ), true, 'returns expected value' );and dropping the now-unusedabsrequire.ULP bound
The ULP constant for both test files is
90112, which is the measured minimum over the full Julia fixture set (200 cases):N = 90111N = 90112The JavaScript and C implementations return bit-identical results for all 200 fixture cases, so a single bound applies to both test files.
The worst case is
alpha = 13.021259169040828,beta = 10.791321613286392, where the returned value-0.0005097193624408192differs from the expected-0.0005097193624310492by 90112 ULP. The differential entropy of the inverse gamma distribution is a sum of terms of order 1 (alpha + ln( beta*gamma(alpha) ) - (1+alpha)*digamma(alpha)), and for these parameters those terms very nearly cancel, leaving a result of magnitude~5e-4. The absolute error is~9.8e-15, i.e., roughly 44 ULP relative to the magnitude of the intermediate terms, but cancellation inflates it to ~90k ULP relative to the result. The bound is therefore a consequence of cancellation in the fixture, not of a loose implementation; in relative terms it is1.9e-11, which is about 5x tighter than the previous1e-10relative tolerance. The remaining 199 cases are all within 12288 ULP, and 11 are bit-exact.The native addon was compiled locally so that
test/test.native.jsexecuted against the C implementation rather than being skipped. The suite was run twice atN = 90112for both files to confirm determinism (214 passing assertions per file on each run, no failures).Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
The measured minimum bound is large in ULP terms because the fixture includes parameter combinations where the entropy is the result of near-total cancellation. Bounds of this magnitude have precedent in the repository, but if a tighter bound is preferred for this package, the alternative would be to regenerate the fixtures to avoid the cancellation region, which is out of scope here. Happy to adjust.
Other
Only the two test files are changed. Both files lint cleanly under
etc/eslint/.eslintrc.tests.js.Note on environment:
make install-node-modulescould not complete in this environment because a transitive dependency resolves toes-object-atoms@^1.1.2, which is not available from the registry reachable here; the required test tooling (tape,node-gyp, ESLint and its plugins) was therefore installed separately with that dependency pinned to1.1.1. As a result, the tests were run directly vianoderather than throughmake test TESTS_FILTER=".*/stats/base/dists/invgamma/entropy/.*", and the EditorConfig linter could not be run. EditorConfig compliance (LF line endings, UTF-8, tab indentation, no trailing whitespace, final newline) was verified manually instead.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code, which also measured the minimum ULP bound empirically against the fixture set and ran the test suite.
@stdlib-js/reviewers
🤖 Generated with Claude Code
https://claude.ai/code/session_01BX6G1VLr8YZ78tW8PGEvhn
Generated by Claude Code