Skip to content

Commit 4681eee

Browse files
chore: initial clean up
1 parent f15f0c9 commit 4681eee

6 files changed

Lines changed: 18 additions & 18 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ logEachMap( 'λ: %0.4f, H(X;λ): %0.4f', lambda, entropy );
139139
#include "stdlib/stats/base/dists/poisson/entropy.h"
140140
```
141141

142-
#### stdlib\_base\_dists\_poisson\_entropy( lambda )
142+
#### stdlib_base_dists_poisson_entropy( lambda )
143143

144144
Returns the [entropy][entropy] of a [Poisson][poisson-distribution] distribution with mean parameter `lambda` (in [nats][nats]).
145145

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ var opts = {
4141
// MAIN //
4242

4343
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
44+
var arrayOpts;
4445
var lambda;
45-
var opts;
4646
var y;
4747
var i;
4848

49-
opts = {
49+
arrayOpts = {
5050
'dtype': 'float64'
5151
};
52-
lambda = uniform( 100, EPS, 20.0, opts );
52+
lambda = uniform( 100, EPS, 20.0, arrayOpts );
5353

5454
b.tic();
5555
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/stats/base/dists/poisson/entropy/benchmark/c/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ static double random_uniform( const double min, const double max ) {
9393
* @return elapsed time in seconds
9494
*/
9595
static double benchmark( void ) {
96-
double elapsed;
9796
double lambda[ 100 ];
97+
double elapsed;
9898
double y;
9999
double t;
100100
int i;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
* // returns ~2.508
3535
*/
3636
double stdlib_base_dists_poisson_entropy( const double lambda ) {
37+
double term;
3738
double sum;
38-
double lk;
3939
double out;
40+
double lk;
4041
int k;
4142

4243
if ( stdlib_base_is_nan( lambda ) || lambda < 0.0 ) {
@@ -47,14 +48,18 @@ double stdlib_base_dists_poisson_entropy( const double lambda ) {
4748
}
4849
out = lambda * ( 1.0 - stdlib_base_ln( lambda ) );
4950

50-
// Compute the series: sum_{k=0}^{infty} lambda^k * ln(k!) / k!
51-
// Starting from k=2, since ln(0!) = 0 and ln(1!) = 0:
51+
// Compute: sum_{k=2}^{inf} lambda^k * ln(k!) / k!
52+
// k starts at 1, lk = lambda^1, first iteration makes k=2, lk=lambda^2
5253
sum = 0.0;
54+
k = 1;
5355
lk = lambda; // lambda^1
5456
for ( k = 2; k < 1000; k++ ) {
5557
lk *= lambda;
56-
sum += lk * stdlib_base_factorialln( k ) / stdlib_base_factorial( k );
57-
if ( lk / stdlib_base_factorial( k ) < 1.0e-16 ) {
58+
term = lk * stdlib_base_factorialln( k ) / stdlib_base_factorial( k );
59+
sum += term;
60+
61+
// Convergence: check relative size of term
62+
if ( term < 1.0e-16 * sum ) {
5863
break;
5964
}
6065
}

lib/node_modules/@stdlib/stats/base/dists/poisson/entropy/test/test.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
25+
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
2626
var NINF = require( '@stdlib/constants/float64/ninf' );
27-
var EPS = require( '@stdlib/constants/float64/eps' );
2827
var entropy = require( './../lib' );
2928

3029

@@ -71,8 +70,6 @@ tape( 'if provided a `lambda` equal to `0`, the function returns `0`', function
7170
tape( 'the function returns the entropy of a Poisson distribution', function test( t ) {
7271
var expected;
7372
var lambda;
74-
var delta;
75-
var tol;
7673
var i;
7774
var y;
7875

@@ -83,9 +80,7 @@ tape( 'the function returns the entropy of a Poisson distribution', function tes
8380
if ( y === expected[i] ) {
8481
t.strictEqual( y, expected[i], 'lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] );
8582
} else {
86-
delta = abs( y - expected[ i ] );
87-
tol = 15.0 * EPS * abs( expected[ i ] );
88-
t.ok( delta <= tol, 'within tolerance. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
83+
t.ok( isAlmostSameValue( y, expected[i], 20 ), 'within tolerance. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' );
8984
}
9085
}
9186
t.end();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ tape( 'the function returns the entropy of a Poisson distribution', opts, functi
8989
if ( y === expected[i] ) {
9090
t.strictEqual( y, expected[i], 'lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] );
9191
} else {
92-
t.ok( isAlmostSameValue( y, expected[i], 1500 ), 'within tolerance. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' );
92+
t.ok( isAlmostSameValue( y, expected[i], 20 ), 'within tolerance. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' );
9393
}
9494
}
9595
t.end();

0 commit comments

Comments
 (0)