Skip to content

Commit e7130b8

Browse files
committed
feat(stats): use robust incremental summation
--- 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: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - 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 ---
1 parent c71a51a commit e7130b8

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var incrsum = require( '@stdlib/stats/incr/sum' );
2324
var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' );
2425
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2526
var PINF = require( '@stdlib/constants/float64/pinf' );
@@ -76,7 +77,7 @@ var pmf = require( '@stdlib/stats/base/dists/hypergeometric/pmf' );
7677
function entropy( N, K, n ) {
7778
var min;
7879
var max;
79-
var ent;
80+
var acc;
8081
var p;
8182
var i;
8283

@@ -100,14 +101,14 @@ function entropy( N, K, n ) {
100101
}
101102
min = ( n + K - N > 0 ) ? n + K - N : 0;
102103
max = ( n < K ) ? n : K;
103-
ent = 0;
104+
acc = incrsum();
104105
for ( i = min; i <= max; i++ ) {
105106
p = pmf( i, N, K, n );
106107
if ( p > 0 ) {
107-
ent -= p * ln( p );
108+
acc( -p * ln( p ) );
108109
}
109110
}
110-
return ent;
111+
return acc();
111112
}
112113

113114

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434
"bugs": {
3535
"url": "https://github.com/stdlib-js/stdlib/issues"
3636
},
37-
"dependencies": {},
37+
"dependencies": {
38+
"@stdlib/math/base/assert/is-nan": "^0.2.2",
39+
"@stdlib/math/base/assert/is-nonnegative-integer": "^0.2.2",
40+
"@stdlib/math/base/special/ln": "^0.2.2",
41+
"@stdlib/constants/float64/pinf": "^0.2.2",
42+
"@stdlib/stats/base/dists/hypergeometric/pmf": "^0.2.2",
43+
"@stdlib/stats/incr/sum": "^0.2.2"
44+
},
3845
"devDependencies": {},
3946
"engines": {
4047
"node": ">=0.10.0",

0 commit comments

Comments
 (0)