test: migrate stats/base/dists/hypergeometric/pmf to ULP-based assertions - #14091
Conversation
…rtions Migrates the tests from computed relative tolerance assertions to ULP difference testing using `@stdlib/assert/is-almost-same-value`. The ULP bound was tightened to the measured minimum (1967) over the full fixture set for both the JavaScript and C implementations. Ref: #11352 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Hello! 👋 We've noticed that you've been opening a number of PRs addressing good first issues. Thank you for your interest and enthusiasm! Now that you've made a few contributions, we suggest no longer working on good first issues. Instead, we encourage you to prioritize cleaning up any PRs which have yet to be merged and then proceed to work on more involved tasks. Not only does this ensure that other new contributors can work on things and get ramped up on all things stdlib, it also ensures that you can spend your time on more challenging problems. 🚀 For ideas for future PRs, feel free to search the codebase for TODOs and FIXMEs and be sure to check out other open issues on the issue tracker. Cheers! |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Resolves a part of #11352.
Description
This pull request:
stats/base/dists/hypergeometric/pmffrom computed relative tolerance testing (delta = abs( y - expected[i] ),tol = 1040.0 * EPS * abs( expected[i] ),t.ok( delta <= tol, ... )) to ULP difference testing using@stdlib/assert/is-almost-same-value.test/test.pmf.js,test/test.factory.js, andtest/test.native.js, each of which contains one fixture loop overtest/fixtures/julia/data.json.test/test.jscontains no tolerance math and is unchanged.@stdlib/math/base/special/absand@stdlib/constants/float64/epsrequires from all three files (neither is used elsewhere in these files).ULP bounds (tightened to the measured minimum over the full fixture set):
fixtures/julia/data.jsonx(test.pmf.js)1967fixtures/julia/data.jsonx(test.factory.js)1967fixtures/julia/data.jsonx(test.native.js)1967Notes on how the bound was determined:
Nfor whichisAlmostSameValue( y, expected[i], N )istrue, and taking the maximum over the fixture set. Starting from a bound of64and adjusting, the suite passes at1967and fails at1966(a single failing assertion, atx: 81, N: 100, K: 87, n: 86), confirming that1967is tight rather than merely sufficient.pmf( 81, 100, 87, 86 ), which returns1.4708214585445427e-5against a Julia reference value of1.4708214585448759e-5.1040.0 * EPScorresponds to a relative tolerance of ~2.31e-13, while the observed worst-case relative error is ~2.27e-13. The prior tolerance was therefore already close to the observed error, and the ULP bound is of a comparable magnitude. The relatively large bound reflects the implementation, which evaluates the pmf via a sum of log-factorial terms (gammaln-based binomial coefficients) followed by exponentiation, so the argument reduction amplifies the error of the underlying kernels for largeNandK.node-gyp rebuild), sotest/test.native.jswas exercised against the actual C implementation rather than skipped. The JavaScript and C implementations agree exactly on every fixture value.test.pmf.js, 1031 fortest.factory.js, 3 fortest.js, and 1013 fortest.native.js, all passing, per run), so the bound is not sensitive to FMA/contraction differences on this machine.Related Issues
This pull request has the following related issues:
math/base/specialpackages from relative tolerance testing to ULP difference testing (tracking issue) #11352Questions
One point:
1967is a much larger bound than most converted packages have needed. It is the measured minimum over the existing fixture set and is consistent with the relative tolerance it replaces, but reviewers may wish to consider whether the underlying accuracy of the implementation is itself worth a follow-up, since the ULP bound now makes the error magnitude explicit rather than hiding it behind anEPSmultiplier.Other
make test TESTS_FILTER=".*/stats/base/dists/hypergeometric/pmf/.*". Linting is clean viamake lint-javascript-tests TESTS_FILTER=".*/stats/base/dists/hypergeometric/pmf/.*", which usesetc/eslint/.eslintrc.tests.js.editorconfigpre-commit hook could not run in this environment, as it downloads its binary from a host this session cannot reach. The three files were instead checked against.editorconfig(LF endings, tab indentation, final newline, UTF-8, no trailing whitespace); the diff introduces no new violations.stats/base/dists/chi/quantile(test: migratestats/base/dists/chi/quantileto ULP-based assertions #14086) andstats/base/dists/lognormal/variance(test: migratestats/base/dists/lognormal/varianceto ULP-based assertions #14069), which use an inline integer ULP argument per fixture loop and the'returns expected value'assertion message.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored by Claude Code, running as an unattended scheduled task. The test migration follows the idiom established by previously merged conversions, and the ULP bound was measured empirically against both the JavaScript and compiled C implementations rather than guessed.
@stdlib-js/reviewers
Generated by Claude Code