Skip to content

feat: add stats/base/dists/wald/cdf - #9709

Merged
Planeshifter merged 18 commits into
stdlib-js:developfrom
Neerajpathak07:wald/cdf
Jul 23, 2026
Merged

Planeshifter merged 18 commits into
stdlib-js:developfrom
Neerajpathak07:wald/cdf

Conversation

@Neerajpathak07

Copy link
Copy Markdown
Member

Progresses #209.

Description

What is the purpose of this pull request?

This pull request:

  • Adds stats/base/dists/wald/cdf

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?

No.

Other

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

No.

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

{{TODO: add disclosure if applicable}}


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Jan 12, 2026
@Neerajpathak07 Neerajpathak07 added the Feature Issue or pull request for adding a new feature. label Jan 12, 2026
@stdlib-bot

stdlib-bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/wald/cdf $\\color{green}361/361$
$\\color{green}+1.15\\%$
$\\color{green}35/35$
$\\color{green}+6.45\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}361/361$
$\\color{green}+1.15\\%$

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

@Neerajpathak07

Copy link
Copy Markdown
Member Author

Given that the CI error is not due to changes in this PR will go ahead and open it for review!!

z = sqrt( lambda / x );

// Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) )
t1 = 0.5 * erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Representing phi in this format ref:-
image

@Neerajpathak07 Neerajpathak07 Jan 13, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could have used stats/base/dists/normal/cdf but while writing the C implementation using normal_cdf into the equation causes discrepancy in the return values.

Comment on lines +115 to +116
y = mycdf( 8.0 );
// returns ~0.999

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Throws an error if 0.998 is rounded of to 1.000 so used this instead!!

@Neerajpathak07
Neerajpathak07 marked this pull request as ready for review January 13, 2026 04:39
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 13, 2026

@Planeshifter Planeshifter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left a bunch of comments. Thanks!

Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md
@Planeshifter Planeshifter added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jan 13, 2026
@Neerajpathak07

Copy link
Copy Markdown
Member Author

@Planeshifter Updated the changes. But, benchmarks do seem to fail but runs clean locally.
Is it a bug in this PR??

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 16, 2026
@Neerajpathak07
Neerajpathak07 marked this pull request as draft January 25, 2026 10:33
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jan 25, 2026
kgryte and others added 4 commits May 26, 2026 10:32
---
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_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - 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: na
  - task: lint_license_headers
    status: passed
---
---
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_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - 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: missing_dependencies
  - 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
---
@Neerajpathak07
Neerajpathak07 requested a review from a team July 15, 2026 15:27
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jul 15, 2026
@kgryte

kgryte commented Jul 16, 2026

Copy link
Copy Markdown
Member

@batpigandme Do we need to update our R versions again?

@kgryte

kgryte commented Jul 16, 2026

Copy link
Copy Markdown
Member

Looks like CI failures stem from R to varying degree. @Neerajpathak07 Was there a reason why you decided to include R benchmarks in this PR?

@kgryte

kgryte commented Jul 16, 2026

Copy link
Copy Markdown
Member

Also, @Neerajpathak07 you should address the R lint warnings, as they are simple fixes.

@batpigandme

Copy link
Copy Markdown
Member

Something weird is going on because R 4.7 is still devel, and (much to my surprise) MASS depends on R >= 4.4.

The R lint fixes should be addressable. We could update R (again, really surprised about the versioning of MASS…must be a good reason, I’ll check the change log), but no released version of a package depends on 4.7.

Warning message:
package ‘MASS’ is not available for this version of R
‘MASS’ version 7.3-65 is in the repositories but depends on R (>= 4.4.0)
‘MASS’ version 7.3-65 is in the repositories but depends on R (>= 4.7)

@batpigandme

Copy link
Copy Markdown
Member

We can definitely update to >= 4.4.0 if we need to. It looks like MASS just published a new version today (2026-07-15), so I wonder if there was a transient something that led to the 4.7 error.

@kgryte

kgryte commented Jul 16, 2026

Copy link
Copy Markdown
Member

I am thinking we can just remove the R benchmarks altogether. They are not essential to getting this package in.

@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label Jul 16, 2026
@Neerajpathak07

Copy link
Copy Markdown
Member Author

@kgryte sure I'll go ahead and remove the R benchmarks. Initially I implemented R benchmarks since R supports the wald/cdf distribution I tried checking out how the API would respond towards R benchmarks. Something which I tried for the first time.

---
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_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - 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: na
  - task: lint_license_headers
    status: passed
---
@Neerajpathak07

Copy link
Copy Markdown
Member Author

@kgryte also I was wondering why git hooks didn't catch the lint R files errors?

@kgryte

kgryte commented Jul 16, 2026

Copy link
Copy Markdown
Member

also I was wondering why git hooks didn't catch the lint R files errors?

Likely because, at least in CI, they are only warnings, not errors.

@batpigandme

Copy link
Copy Markdown
Member

@kgryte do you still want me to upgrade to 4.4.0?

@kgryte

kgryte commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

@batpigandme Your call. I am not sure what is an appropriate minimum version to "support" in R world. The reality is that we are only using R for tests and benchmarks, so there is no production constraint. In which case, we are free to support what minimum version we want, at the cost of forcing devs to satisfy that constraint in their local environments. In short, I'll defer to you. 😅

… feedback

- Add missing x === +infinity check to the factory-created CDF (was
  only fixed in main.js and src/main.c).
- Call the factory-created unary function with a single argument in
  tests.
- Extend +/- infinity tests to cover the non-degenerate case.
- Align repl.txt lambda constraint with the implementation (lambda < 0
  returns NaN; lambda = 0 is the degenerate case).

---
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: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter

Copy link
Copy Markdown
Member

Pushed 15b227b addressing the remaining review feedback:

  • The x === +infinity short-circuit was only added to lib/main.js and src/main.c; the factory-created CDF still returned NaN for +infinity with a non-degenerate lambda. Added the same check to lib/factory.js.
  • Updated test/test.factory.js to call the created unary function with a single argument (the degenerate-distribution test was still passing 3 arguments).
  • Extended the ±infinity tests in test/test.cdf.js, test/test.factory.js, and test/test.native.js to also cover the non-degenerate (lambda > 0) case, so the factory bug can't regress silently.
  • docs/repl.txt still said λ <= 0 returns NaN; changed to λ < 0 to match the implementation (λ = 0 is the documented degenerate case).

---
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: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md Outdated
Comment thread lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js Outdated
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
…feedback

- Compute the exponentially-scaled term via `erfcx`:
  `exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² )`, since
  `b² - a² = 2λ/μ`. Previously, `exp( 2λ/μ )` overflowed for
  `2λ/μ ≳ 709.8`, yielding `Infinity` or `NaN` for valid parameters
  (e.g., `cdf( 1.0, 1.0, 400.0 )`) and intermittently failing
  benchmarks which draw `μ` near `EPS`. Applied to JS main, factory,
  and C implementations; `erfcx` added to manifest dependencies.
- Bump fixture ULP tolerance from 4 to 5 (max observed diff with the
  reformulated expression).
- Exercise the created function's own `NaN` and `x <= 0` branches in
  factory tests (previously only degenerate/invalid-parameter paths
  were hit) and add dedicated nonpositive-`mu` tests to main, native,
  and factory suites; avoid conflating invalid `mu` with other failure
  causes in NaN tests, repl.txt, and TypeScript declaration examples.
- Annotate `mu` as `{PositiveNumber}` in JSDoc; document `mu <= 0`
  constraint and add nonpositive-mean and degenerate examples to the
  TypeScript declarations.
- Use Greek `μ` (U+03BC) instead of micro sign (U+00B5) and `F(x;μ,λ)`
  (CDF) instead of `f(x;μ,λ)` in printouts; capitalize "Wald".
- Replace standalone "inverse"/"gaussian" keywords with
  "inverse gaussian"/"inverse-gaussian" per sibling packages.
- Remove unused `LEN` define and restore standard C benchmark Makefile
  boilerplate.
- Sync Julia fixture runner docstring with actual generation code and
  fix test message spacing.

---
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: missing_dependencies
  - task: lint_c_examples
    status: missing_dependencies
  - task: lint_c_benchmarks
    status: missing_dependencies
  - 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
---

@Planeshifter Planeshifter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's get it in!

@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jul 23, 2026
@stdlib-bot

stdlib-bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Commit Message

feat: add `stats/base/dists/wald/cdf`

PR-URL: https://github.com/stdlib-js/stdlib/pull/9709
Ref: https://github.com/stdlib-js/stdlib/issues/209

Co-authored-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>

Please review the above commit message and make any necessary adjustments.

@Planeshifter
Planeshifter merged commit 01a27ec into stdlib-js:develop Jul 23, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants