Skip to content

Commit 108e110

Browse files
committed
fix: use correct analytic formula and update tests and documentation
--- 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: 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: passed - task: lint_r status: na - task: lint_c_src status: passed - 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 ---
1 parent 2816724 commit 108e110

12 files changed

Lines changed: 34 additions & 33 deletions

File tree

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ Returns the [differential entropy][entropy] of a [half-normal][half-normal-distr
5858

5959
```javascript
6060
var y = entropy( 1.0 );
61-
// returns ~1.014
61+
// returns ~0.7258
6262

6363
y = entropy( 5.0 );
64-
// returns ~2.624
64+
// returns ~2.3352
6565
```
6666

6767
If provided `sigma ≤ 0`, the function returns `NaN`.
@@ -140,7 +140,7 @@ Returns the differential entropy of a half-normal distribution.
140140

141141
```c
142142
double out = stdlib_base_dists_halfnormal_entropy( 1.0 );
143-
// returns ~1.014
143+
// returns ~0.7258
144144
```
145145

146146
The function accepts the following arguments:

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
Examples
2020
--------
2121
> var v = {{alias}}( 1.0 )
22-
~1.014
22+
~0.7258
2323
> v = {{alias}}( 5.0 )
24-
~2.624
24+
~2.3352
2525

2626
See Also
2727
--------

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
*
3131
* @example
3232
* var v = entropy( 1.0 );
33-
* // returns ~1.014
33+
* // returns ~0.7258
3434
*
3535
* @example
3636
* var v = entropy( 5.0 );
37-
* // returns ~2.624
37+
* // returns ~2.3352
3838
*
3939
* @example
4040
* var v = entropy( -0.2 );

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
* var entropy = require( '@stdlib/stats/base/dists/halfnormal/entropy' );
2828
*
2929
* var v = entropy( 1.0 );
30-
* // returns ~1.014
30+
* // returns ~0.7258
3131
*
3232
* v = entropy( 5.0 );
33-
* // returns ~2.624
33+
* // returns ~2.3352
3434
*/
3535

3636
// MODULES //

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/lib/main.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222

2323
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2424
var ln = require( '@stdlib/math/base/special/ln' );
25-
var GAMMA = require( '@stdlib/constants/float64/eulergamma' );
26-
var SQRT_HALF_PI = require( '@stdlib/constants/float64/sqrt-half-pi' );
2725

2826

2927
// VARIABLES //
3028

31-
var SCALAR = ln( SQRT_HALF_PI ) + ( 0.5*GAMMA ) + 0.5;
29+
// ( ln(π/2)+1 ) / 2:
30+
var SCALAR = 0.7257913526447274;
3231

3332

3433
// MAIN //
@@ -41,11 +40,11 @@ var SCALAR = ln( SQRT_HALF_PI ) + ( 0.5*GAMMA ) + 0.5;
4140
*
4241
* @example
4342
* var v = entropy( 1.0 );
44-
* // returns ~1.014
43+
* // returns ~0.7258
4544
*
4645
* @example
4746
* var v = entropy( 5.0 );
48-
* // returns ~2.624
47+
* // returns ~2.3352
4948
*
5049
* @example
5150
* var v = entropy( -0.2 );

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/lib/native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ var addon = require( './../src/addon.node' );
3434
*
3535
* @example
3636
* var v = entropy( 1.0 );
37-
* // returns ~1.014
37+
* // returns ~0.7258
3838
*
3939
* @example
4040
* var v = entropy( 5.0 );
41-
* // returns ~2.624
41+
* // returns ~2.3352
4242
*
4343
* @example
4444
* var v = entropy( -0.2 );

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/manifest.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/unary",
42-
"@stdlib/math/base/assert/is-nan"
42+
"@stdlib/math/base/assert/is-nan",
43+
"@stdlib/math/base/special/ln"
4344
]
4445
},
4546
{
@@ -55,6 +56,7 @@
5556
"libpath": [],
5657
"dependencies": [
5758
"@stdlib/math/base/assert/is-nan",
59+
"@stdlib/math/base/special/ln",
5860
"@stdlib/constants/float64/eps"
5961
]
6062
},
@@ -70,7 +72,8 @@
7072
"libraries": [],
7173
"libpath": [],
7274
"dependencies": [
73-
"@stdlib/math/base/assert/is-nan"
75+
"@stdlib/math/base/assert/is-nan",
76+
"@stdlib/math/base/special/ln"
7477
]
7578
}
7679
]

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/halfnormal/entropy.h"
20+
#include "stdlib/math/base/special/ln.h"
2021
#include "stdlib/math/base/assert/is_nan.h"
2122

22-
// 0.5 + ln(sqrt(π/2)) + (eulergamma/2):
23-
static const double scalar = 1.5143991850954939;
23+
static const double scalar = 0.7257913526447274; // ( ln(π/2)+1 ) / 2
2424

2525
/**
2626
* Returns the differential entropy of a half-normal distribution.
@@ -30,11 +30,11 @@ static const double scalar = 1.5143991850954939;
3030
*
3131
* @example
3232
* double y = stdlib_base_dists_halfnormal_entropy( 1.0 );
33-
* // returns ~1.014
33+
* // returns ~0.7258
3434
*/
3535
double stdlib_base_dists_halfnormal_entropy( const double sigma ) {
3636
if ( stdlib_base_is_nan( sigma ) || sigma <= 0.0 ) {
3737
return 0.0/0.0; // NaN
3838
}
39-
return stdlib_base_ln( sigma ) + SCALAR;
39+
return stdlib_base_ln( sigma ) + scalar;
4040
}

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/test/fixtures/python/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/stats/base/dists/halfnormal/entropy/test/fixtures/python/runner.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020

2121
import os
2222
import json
23-
import numpy as np
2423
from numpy.random import rand
2524
from scipy.stats import halfnorm
2625

27-
# Get the file path
26+
# Get the file path:
2827
FILE = os.path.realpath(__file__)
28+
29+
# Extract the directory in which this file resides:
2930
DIR = os.path.dirname(FILE)
3031

3132

@@ -40,18 +41,16 @@ def gen(x, name):
4041
# Examples
4142
4243
``` python
43-
python> x = rand(1000) * 10.0 + 1.0
44-
python> gen(x, './data.json')
44+
python> x = (rand(1000) * 10.0) + 1.0
45+
python> gen(x, "data.json")
4546
```
4647
"""
47-
y = []
48-
for s in np.nditer(x):
49-
y.append(halfnorm.entropy(scale=float(s)))
48+
y = halfnorm.entropy(loc=0.0, scale=x)
5049

5150
# Store data to be written to file as a dictionary:
5251
data = {
5352
"sigma": x.tolist(),
54-
"expected": y
53+
"expected": y.tolist()
5554
}
5655

5756
# Based on the script directory, create an output filepath:

0 commit comments

Comments
 (0)