Skip to content

Conversation

@bhargava-d16
Copy link
Contributor


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

Progresses #9416

Description

What is the purpose of this pull request?

This pull request:

  • This PR adds implementation of entropy calculation for half-normal distribution.

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

I consulted ChatGPT to verify mathematical formulation of half-normal entropy function and to confirm expected numerical values


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

stdlib-bot commented Jan 14, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/halfnormal/entropy $\color{green}164/164$
$\color{green}+0.00%$
$\color{green}8/8$
$\color{green}+0.00%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{green}164/164$
$\color{green}+0.00%$

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

Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! Left initial comment.

// returns ~2.6238370975295946
```

If provided `sigma < 0`, the function returns `NaN`.
Copy link
Member

Choose a reason for hiding this comment

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

The documentation says sigma < 0 but the implementation in lib/main.js checks sigma <= 0.0. This should be updated to sigma <= 0 to match the implementation behavior (sigma=0 also returns NaN).

Note: docs/repl.txt correctly uses σ ≤ 0.


```c
double out = stdlib_base_dists_halfnormal_entropy( 1.0 );
// returns ~0.726
Copy link
Member

Choose a reason for hiding this comment

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

The expected output value ~0.726 is incorrect. For sigma=1.0, the entropy should be ~1.0143991850954939 (as shown correctly in the JavaScript examples above).

double out = stdlib_base_dists_halfnormal_entropy( 1.0 );
// returns ~1.014

*
* ## Notes
*
* - If provided `σ < 0`, the function returns `NaN`.
Copy link
Member

Choose a reason for hiding this comment

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

The documentation says σ < 0 but the implementation checks σ <= 0. This should be updated to σ ≤ 0 to match the implementation behavior (sigma=0 also returns NaN).

Note: docs/repl.txt correctly uses σ ≤ 0.

Comment on lines 60 to 64
var y = entropy( 1.0 );
// returns ~1.0143991850954939

y = entropy( 5.0 );
// returns ~2.6238370975295946
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
var y = entropy( 1.0 );
// returns ~1.0143991850954939
y = entropy( 5.0 );
// returns ~2.6238370975295946
var y = entropy( 1.0 );
// returns ~1.014
y = entropy( 5.0 );
// returns ~2.624

@Planeshifter Planeshifter changed the title feat: add stats/base/dists/halfnormal/entropy feat: add stats/base/dists/halfnormal/entropy Jan 15, 2026
---
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: 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: passed
  - task: lint_license_headers
    status: passed
---
@@ -0,0 +1,26 @@
{{alias}}( σ )
Copy link
Member

Choose a reason for hiding this comment

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

The file should start with a leading blank line before {{alias}}.

Suggested change
{{alias}}( σ )
{{alias}}( σ )

Comment on lines 32 to 37
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
Copy link
Member

Choose a reason for hiding this comment

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

Same as the repl.txt - the example return values should use short approximations instead of full precision. Reference packages (e.g., rayleigh/entropy) use // returns ~3.139 rather than the full value.

Suggested change
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
* var v = entropy( 1.0 );
* // returns ~1.014
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.624

for ( i = 0; i < expected.length; i++ ) {
y = entropy( sigma[ i ] );
if ( y === expected[ i ] ) {
t.strictEqual(y, expected[ i ], 'sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i]);
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after t.strictEqual( - should be t.strictEqual( y, with a space after the opening parenthesis, matching stdlib's spacing convention.

Suggested change
t.strictEqual(y, expected[ i ], 'sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i]);
t.strictEqual( y, expected[ i ], 'sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i] );

} else {
delta = abs( y - expected[ i ] );
tol = 40.0 * EPS * abs( expected[ i ] );
t.ok(delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.');
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after t.ok( - should be t.ok( delta with a space after the opening parenthesis.

Suggested change
t.ok(delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.');
t.ok( delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' );

} else {
delta = abs( y - expected[ i ] );
tol = 40.0 * EPS * abs( expected[ i ] );
t.ok(delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.');
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after t.ok( - should be t.ok( delta with a space after the opening parenthesis.

Suggested change
t.ok(delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.');
t.ok( delta <= tol, 'within tolerance. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' );

Comment on lines 20 to 23
> var v = {{alias}}( 1.0 )
~1.0143991850954939
> v = {{alias}}( 5.0 )
~2.6238370975295946
Copy link
Member

Choose a reason for hiding this comment

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

The example output values should use short approximations instead of full precision. Looking at other stdlib repl.txt files (e.g., rayleigh/entropy), they use formats like ~3.34 and ~2.446 rather than ~1.0143991850954939.

Suggested change
> var v = {{alias}}( 1.0 )
~1.0143991850954939
> v = {{alias}}( 5.0 )
~2.6238370975295946
> var v = {{alias}}( 1.0 )
~1.014
> v = {{alias}}( 5.0 )
~2.624

Comment on lines 29 to 33
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* v = entropy( 5.0 );
* // returns ~2.6238370975295946
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
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* v = entropy( 5.0 );
* // returns ~2.6238370975295946
* var v = entropy( 1.0 );
* // returns ~1.014
*
* v = entropy( 5.0 );
* // returns ~2.624

Comment on lines 38 to 43
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
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
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
* var v = entropy( 1.0 );
* // returns ~1.014
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.624

Comment on lines 36 to 41
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
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
* var v = entropy( 1.0 );
* // returns ~1.0143991850954939
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.6238370975295946
* var v = entropy( 1.0 );
* // returns ~1.014
*
* @example
* var v = entropy( 5.0 );
* // returns ~2.624

Comment on lines 32 to 33
* double y = stdlib_base_dists_halfnormal_entropy( 1.0 );
* // returns ~1.0143991850954939
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
* double y = stdlib_base_dists_halfnormal_entropy( 1.0 );
* // returns ~1.0143991850954939
* double y = stdlib_base_dists_halfnormal_entropy( 1.0 );
* // returns ~1.014

---
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: 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
---
---
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: 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 Neerajpathak07 added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Jan 16, 2026
---
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: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: missing_dependencies
  - 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
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Changes Pull request which needs changes before being merged. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants