Skip to content

test: migrate stats/base/dists/invgamma/entropy to ULP-based assertions - #15478

Merged
kgryte merged 1 commit into
developfrom
kgryte/ulp-invgamma-entropy
Sep 24, 2026
Merged

kgryte merged 1 commit into
developfrom
kgryte/ulp-invgamma-entropy

Conversation

@kgryte

@kgryte kgryte commented Sep 23, 2026

Copy link
Copy Markdown
Member

Resolves a part of #11352.

Description

What is the purpose of this pull request?

This pull request:

  • migrates the tests for stats/base/dists/invgamma/entropy from relative tolerance assertions to ULP difference assertions using @stdlib/assert/is-almost-same-value.
  • updates test/test.js and test/test.native.js, replacing the delta/tol comparison against 1e-10 * abs( expected[i] ) with t.strictEqual( isAlmostSameValue( y, expected[ i ], 90112 ), true, 'returns expected value' ); and dropping the now-unused abs require.

ULP bound

The ULP constant for both test files is 90112, which is the measured minimum over the full Julia fixture set (200 cases):

Implementation N = 90111 N = 90112
JavaScript 1 failure 0 failures
C (native) 1 failure 0 failures

The 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.0005097193624408192 differs from the expected -0.0005097193624310492 by 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 is 1.9e-11, which is about 5x tighter than the previous 1e-10 relative 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.js executed against the C implementation rather than being skipped. The suite was run twice at N = 90112 for both files to confirm determinism (214 passing assertions per file on each run, no failures).

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

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

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Only the two test files are changed. Both files lint cleanly under etc/eslint/.eslintrc.tests.js.

Note on environment: make install-node-modules could not complete in this environment because a transitive dependency resolves to es-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 to 1.1.1. As a result, the tests were run directly via node rather than through make 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

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

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

…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
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Good First PR A pull request resolving a Good First Issue. labels Sep 23, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/invgamma/entropy $\\color{green}201/201$
$\\color{green}+100.00\\%$
$\\color{green}10/10$
$\\color{green}+100.00\\%$
$\\color{green}2/2$
$\\color{green}+100.00\\%$
$\\color{green}201/201$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte added the Tests Pull requests specifically adding tests. label Sep 24, 2026
@kgryte
kgryte marked this pull request as ready for review September 24, 2026 06:04
@kgryte
kgryte requested a review from a team September 24, 2026 06:04
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 24, 2026
@kgryte
kgryte merged commit 01bd47a into develop Sep 24, 2026
82 checks passed
@kgryte
kgryte deleted the kgryte/ulp-invgamma-entropy branch September 24, 2026 06:06
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. Tests Pull requests specifically adding tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants