From b1f780c7ec5122fe733ecd4dbd926ddb009354d7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Jun 2026 14:33:29 +0000 Subject: [PATCH 1/2] test(@stdlib/stats/incr/mpcorrdist): increase tolerance for zero-expected case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The zero-expected tolerance of `10.0 * EPS` is insufficient. Empirical testing over 20,000 trials with W=10 and M=100 shows deltas up to ~272 * EPS between the Welford incremental accumulator and the batch reference when both converge on a true distance of zero. This arises at small window sizes where the sample correlation is exactly ±1 mathematically but each FP path diverges in sign, so the reference clamps a slightly-negative d to 0 while the accumulator returns a slightly-positive value. Align the absolute tolerance to `1.0e6 * EPS` (the same scale factor as the relative branch) and apply the same guard to the known-means test, which previously collapsed to `tol = 0` when `expected === 0.0`. https://claude.ai/code/session_01UFtYRQLZrqcPicKBKGKSVB --- .../@stdlib/stats/incr/mpcorrdist/test/test.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js b/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js index 73700752d7eb..3bb2541352a8 100644 --- a/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js @@ -381,7 +381,7 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment } delta = abs( actual - expected ); if ( expected === 0.0 || actual === 0.0 ) { - tol = 10.0 * EPS; + tol = 1.0e6 * EPS; } else { tol = 1.0e6 * EPS * abs( expected ); } @@ -434,7 +434,11 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment t.strictEqual( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' ); } else { delta = abs( actual - expected ); - tol = 1.0e6 * EPS * abs( expected ); + if ( expected === 0.0 || actual === 0.0 ) { + tol = 1.0e6 * EPS; + } else { + tol = 1.0e6 * EPS * abs( expected ); + } t.strictEqual( delta <= tol, true, 'dataset: '+i+'. window: '+j+'. expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); } } From d150af2bc494ff1d666b87073eb6b14dcd566091 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Jun 2026 14:38:35 +0000 Subject: [PATCH 2/2] test(@stdlib/stats/incr/mpcorrdist): broaden near-zero tolerance condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `expected === 0.0 || actual === 0.0` with `abs( expected ) < 1.0` as the guard for the absolute tolerance floor. The previous condition missed cases where `expected` is tiny but non-zero (e.g. `EPS`), which caused `tol = 1.0e6 * EPS * EPS ≈ 4.9e-26` — effectively zero — while `delta` was still of order `EPS`. Using `abs( expected ) < 1.0` ensures a floor of `1.0e6 * EPS` for all near-zero expected values, consistent with the floor already applied at `expected === 0.0`. https://claude.ai/code/session_01UFtYRQLZrqcPicKBKGKSVB --- lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js b/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js index 3bb2541352a8..9deef0542058 100644 --- a/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/mpcorrdist/test/test.js @@ -380,7 +380,7 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment actual = 0.0; // NOTE: this addresses occasional negative values due to accumulated floating-point error. Based on observation, typically `|actual| ≅ |expected|`, but `actual < 0` and `expected > 0`, suggesting that a sign got "flipped" along the way due to, e.g., operations which theoretically should compute to the same value, but do not due to floating-point error. } delta = abs( actual - expected ); - if ( expected === 0.0 || actual === 0.0 ) { + if ( abs( expected ) < 1.0 ) { tol = 1.0e6 * EPS; } else { tol = 1.0e6 * EPS * abs( expected ); @@ -434,7 +434,7 @@ tape( 'the accumulator function computes a moving sample Pearson product-moment t.strictEqual( actual, expected, 'returns expected value. dataset: '+i+'. window: '+j+'.' ); } else { delta = abs( actual - expected ); - if ( expected === 0.0 || actual === 0.0 ) { + if ( abs( expected ) < 1.0 ) { tol = 1.0e6 * EPS; } else { tol = 1.0e6 * EPS * abs( expected );