Skip to content

Conversation

@navyansh007
Copy link
Contributor

@navyansh007 navyansh007 commented Dec 29, 2025


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: passed
  • 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

Progresses #9416

Description

What is the purpose of this pull request?

This pull request:

  • Adds a comprehensive implementation of the cumulative distribution function (CDF) for the half-normal distribution
  • Implements @stdlib/stats/base/dists/halfnormal/cdf package with complete functionality including:
    • Main CDF function for evaluating the half-normal CDF at a given value
    • Factory function for creating partially applied CDF functions with fixed parameters
    • Full TypeScript type definitions and tests
    • Comprehensive test suite covering edge cases (NaN, infinity, degenerate distributions)
    • Performance benchmarks for both direct calls and factory-generated functions
    • Examples demonstrating usage
    • REPL documentation
    • Test fixture infrastructure using Julia scripts
  • Follows the same structure and quality standards as the normal distribution's CDF package

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • #{{TODO: add related issue number}}

Questions

Any questions for reviewers of this pull request?

No.

Other

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

Implementation Notes:

The half-normal distribution CDF is implemented using the error function (erf):

F(x;μ,σ) = erf((x-μ)/(σ√2)) for x ≥ μ
F(x;μ,σ) = 0 for x < μ

where μ is the location parameter and σ is the scale parameter.

Package Structure:

The implementation closely mirrors the structure of @stdlib/stats/base/dists/normal/cdf to ensure consistency across the stdlib codebase:

  • lib/main.js - Main CDF implementation
  • lib/factory.js - Factory function for partial application
  • lib/index.js - Package exports
  • test/test.cdf.js - Comprehensive tests for the main function
  • test/test.factory.js - Tests for the factory function
  • test/test.js - Basic module tests
  • examples/index.js - Usage examples
  • benchmark/benchmark.js - Performance benchmarks
  • docs/types/index.d.ts - TypeScript definitions
  • docs/types/test.ts - TypeScript definition tests
  • docs/repl.txt - REPL documentation
  • test/fixtures/julia/ - Test fixture generation scripts

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 me.".

The tests and documentation were primarily authored by Claude Code, but the research and understanding of the half-normal distribution were done by me, and the CDF function's code implementation was entirely authored and reviewed by me.


@stdlib-js/reviewers

---
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: passed
  - 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
---
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Dec 29, 2025
@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/halfnormal/cdf $\color{red}228/232$
$\color{green}+98.28%$
$\color{red}23/25$
$\color{green}+92.00%$
$\color{green}3/3$
$\color{green}+100.00%$
$\color{red}228/232$
$\color{green}+98.28%$

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

@kgryte kgryte changed the title feat: initial implementation of @stdlib/stats/base/dists/halfnormal/cdf feat: initial implementation of stats/base/dists/halfnormal/cdf Dec 30, 2025
Comment on lines +34 to +39
"@stdlib/math/base/assert/is-nan": "^0.2.2",
"@stdlib/math/base/special/erf": "^0.2.2",
"@stdlib/math/base/special/sqrt": "^0.2.2",
"@stdlib/stats/base/dists/degenerate/cdf": "^0.2.2",
"@stdlib/utils/constant-function": "^0.2.2",
"@stdlib/utils/define-nonenumerable-read-only-property": "^0.2.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@stdlib/math/base/assert/is-nan": "^0.2.2",
"@stdlib/math/base/special/erf": "^0.2.2",
"@stdlib/math/base/special/sqrt": "^0.2.2",
"@stdlib/stats/base/dists/degenerate/cdf": "^0.2.2",
"@stdlib/utils/constant-function": "^0.2.2",
"@stdlib/utils/define-nonenumerable-read-only-property": "^0.2.2"

t.end();
});

tape('if provided `x < mu`, the function returns `0`', function test(t) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tape('if provided `x < mu`, the function returns `0`', function test(t) {
tape( 'if provided `x < mu`, the function returns `0`', function test( t ) {

t.equal(y, expected[i], 'x: ' + x[i] + ', mu: ' + mu[i] + ', sigma: ' + sigma[i] + ', y: ' + y + ', expected: ' + expected[i]);
} else {
del = abs(y - expected[i]);
t.ok(del <= 1e-14, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + expected[i] + '. Delt: ' + del);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t.ok(del <= 1e-14, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + expected[i] + '. Delt: ' + del);
t.ok(del <= 1e-14, 'within tolerance. x: ' + x[i] + '. y: ' + y + '. E: ' + expected[i] + '. Delt: ' + del);

Use assert/is-almost-same-value with an appropriate maxULPs argument.

*
* @example
* var y = cdf( 2.0, 0.0, 1.0 );
* // returns 0.9544997361036416
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* // returns 0.9544997361036416
* // returns ~0.9545


```javascript
var y = cdf( 2.0, 0.0, 1.0 );
// returns 0.9544997361036416
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// returns 0.9544997361036416
// returns ~0.9545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants