feat: add stats/incr/nanmpcorrdist#9319
Conversation
- Add incrementor for computing moving sample Pearson product-moment correlation distance with NaN handling - Wraps @stdlib/stats/incr/mpcorrdist and ignores NaN values in x and y - Include comprehensive tests (2069 passing), examples, benchmarks, and TypeScript definitions - Follow stdlib conventions for package structure and code style PR: stdlib-js#2986 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
/stdlib merge |
|
/stdlib update-copyright-years |
|
/stdlib update-copyright-years |
@Planeshifter, the slash command failed to complete. Please check the workflow logs for details. |
Planeshifter
left a comment
There was a problem hiding this comment.
Thanks!
Looks like some CI checks are failing.
| x = ( randu() < 0.2 ) ? NaN : randu() * 100.0; | ||
| y = ( randu() < 0.2 ) ? NaN : randu() * 100.0; | ||
| d = accumulator( x, y ); | ||
| console.log( '%d\t%d\t%d', x.toFixed( 4 ), y.toFixed( 4 ), d.toFixed( 4 ) ); |
There was a problem hiding this comment.
This will throw a TypeError when d is null (which happens before any non-NaN values are accumulated). Since x and y each have a 20% chance of being NaN, and both need to be non-NaN for the accumulator to update, there's a real chance d is still null on early iterations.
| console.log( '%d\t%d\t%d', x.toFixed( 4 ), y.toFixed( 4 ), d.toFixed( 4 ) ); | |
| console.log( '%d\t%d\t%d', x.toFixed( 4 ), y.toFixed( 4 ), ( d === null ) ? 'null' : d.toFixed( 4 ) ); |
| acc( 3.14, [] ); // $ExpectError | ||
| acc( 3.14, {} ); // $ExpectError | ||
| acc( 3.14, ( x: number ): number => x ); // $ExpectError | ||
| } |
There was a problem hiding this comment.
The reference package @stdlib/stats/incr/mpcorrdist has an additional test section for testing invalid arguments with the known means accumulator (lines 104-123 in the reference). This section is missing here.
You should add:
// The compiler throws an error if the returned accumulator function is provided invalid arguments (known means)...
{
const acc = incrnanmpcorrdist( 3, 2, -3 );
acc( '5', 1.0 ); // $ExpectError
acc( true, 1.0 ); // $ExpectError
acc( false, 1.0 ); // $ExpectError
acc( null, 1.0 ); // $ExpectError
acc( [], 1.0 ); // $ExpectError
acc( {}, 1.0 ); // $ExpectError
acc( ( x: number ): number => x, 1.0 ); // $ExpectError
acc( 3.14, '5' ); // $ExpectError
acc( 3.14, true ); // $ExpectError
acc( 3.14, false ); // $ExpectError
acc( 3.14, null ); // $ExpectError
acc( 3.14, [] ); // $ExpectError
acc( 3.14, {} ); // $ExpectError
acc( 3.14, ( x: number ): number => x ); // $ExpectError
}@stdlib/stats/incr/nanmpcorrdiststats/incr/nanmpcorrdist
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves #5602.
Description
This pull request:
@stdlib/stats/incr/nanmpcorrdist, an accumulator function for incrementally computing a moving sample Pearson product-moment correlation distance while ignoringNaNvalues@stdlib/stats/incr/mpcorrdistand adds robust NaN handling by checking input values before updating the accumulatorRelated Issues
This pull request has the following related issues:
stats/incr/nanmpcorrdist#5602 ([RFC]: add stats/incr/nanmpcorrdist)Questions
No.
Other
Implementation Details
The accumulator checks if either input value (
xory) isNaNusing@stdlib/math/base/assert/is-nan:NaNis detected, returns the current correlation distance without updatingmpcorrdistaccumulatorValidation Results
Tests: All 2069 tests pass, including:
Examples: Execute successfully, demonstrating ~20% NaN injection rate with proper handling
Benchmarks: All benchmarks pass:
Linting: All static analysis checks pass (see pre-commit report above)
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored with GitHub Copilot assistance. The implementation was created by analyzing existing stdlib packages (
@stdlib/stats/incr/mpcorrdist,@stdlib/stats/incr/nansum,@stdlib/stats/incr/sum) to understand patterns and conventions, then generating all required files (implementation, tests, examples, benchmarks, documentation, TypeScript definitions) following stdlib's established structure. All code has been validated with comprehensive tests (2069 passing), examples, and benchmarks, and follows stdlib linting rules and conventions.@stdlib-js/reviewers