Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
// MODULES //

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


Expand Down Expand Up @@ -65,38 +64,28 @@ tape( 'if provided `c <= 0`, the function returns `NaN`', function test( t ) {

tape( 'the function returns the differential entropy of a Bradford distribution given small parameter `c`', function test( t ) {
var expected;
var delta;
var tol;
var i;
var c;
var y;

expected = smallC.expected;
c = smallC.c;

/*
* NOTE: the ULP bound is set high in this case due to:
*
* 1. The shape parameter being very small which causes differences in the nested `ln` calculations when compared to the test fixtures by SciPy.
* 2. The expected values being very small.
*/
for ( i = 0; i < expected.length; i++ ) {
y = entropy( c[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );

/*
* NOTE: the tolerance is set high in this case due to:
*
* 1. The shape parameter being very small which causes differences in the nested `ln` calculations when compared to the test fixtures by SciPy.
* 2. The expected values being very small.
*/
tol = 1523.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1984 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function returns the differential entropy of a Bradford distribution given large parameter `c`', function test( t ) {
var expected;
var delta;
var tol;
var i;
var c;
var y;
Expand All @@ -105,13 +94,7 @@ tape( 'the function returns the differential entropy of a Bradford distribution
c = largeC.c;
for ( i = 0; i < expected.length; i++ ) {
y = entropy( c[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 45.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 64 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -74,31 +73,28 @@ tape( 'if provided `c <= 0`, the function returns `NaN`', opts, function test( t

tape( 'the function returns the differential entropy of a Bradford distribution given small parameter `c`', opts, function test( t ) {
var expected;
var delta;
var tol;
var i;
var c;
var y;

expected = smallC.expected;
c = smallC.c;

/*
* NOTE: the ULP bound is set high in this case due to:
*
* 1. The shape parameter being very small which causes differences in the nested `ln` calculations when compared to the test fixtures by SciPy.
* 2. The expected values being very small.
*/
for ( i = 0; i < expected.length; i++ ) {
y = entropy( c[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1523.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1984 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function returns the differential entropy of a Bradford distribution given large parameter `c`', opts, function test( t ) {
var expected;
var delta;
var tol;
var i;
var c;
var y;
Expand All @@ -107,13 +103,7 @@ tape( 'the function returns the differential entropy of a Bradford distribution
c = largeC.c;
for ( i = 0; i < expected.length; i++ ) {
y = entropy( c[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 45.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 64 ), true, 'returns expected value' );
}
t.end();
});
Loading