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,11 +21,10 @@
// 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 PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var factory = require( './../lib/factory.js' );


Expand Down Expand Up @@ -131,61 +130,28 @@ tape( 'if provided a nonpositive `gamma`, the created function always returns `N
tape( 'the created function evaluates the quantile function at `p` given parameters `x0` and `gamma` (large `gamma`)', function test( t ) {
var expected;
var quantile;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
var i;

/*
* Higher tolerance than EPS because Julia gives slightly different results for
* |x| ~<= 3*pi/4:
*
* Example 1:
* x = -1.35646279095478;
* Julia (tan): -4.593961172862999
* stdlib (tan): -4.593961172863
* Mathematica: -4.59396117286300026311049650877442413097818001966176559315
*
* Example 2:
* x = 1.4710248292410089
* Julia (tan): 9.989623320530624
* stdlib (tan): 9.989623320530626
* Mathematica: 9.989623320530629158499137574831736702146195199133529403233
*
* Example 3:
* x = 1.528545878614728
* Julia (tan): 23.654302824341386
* stdlib (tan): 23.65430282434139
* Mathematica: 23.65430282434144042648214719732782590575979471046811610915...
*/

expected = largeGamma.expected;
p = largeGamma.p;
x0 = largeGamma.x0;
gamma = largeGamma.gamma;
for ( i = 0; i < p.length; i++ ) {
quantile = factory( x0[i], gamma[i] );
y = quantile( p[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0: '+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 50.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the created function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 > 0`)', function test( t ) {
var expected;
var quantile;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -198,23 +164,15 @@ tape( 'the created function evaluates the quantile function at `p` given `x0` an
for ( i = 0; i < p.length; i++ ) {
quantile = factory( x0[i], gamma[i] );
y = quantile( p[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0: '+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 125.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the created function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 < 0`)', function test( t ) {
var expected;
var quantile;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -227,13 +185,7 @@ tape( 'the created function evaluates the quantile function at `p` given `x0` an
for ( i = 0; i < p.length; i++ ) {
quantile = factory( x0[i], gamma[i] );
y = quantile( p[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0: '+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 50.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var tryRequire = require( '@stdlib/utils/try-require' );
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 PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );


// FIXTURES //
Expand Down Expand Up @@ -104,58 +103,25 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', op
tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` (large `gamma`)', opts, function test( t ) {
var expected;
var gamma;
var delta;
var tol;
var x0;
var p;
var y;
var i;

/*
* Higher tolerance than EPS because Julia gives slightly different results for
* |x| ~<= 3*pi/4:
*
* Example 1:
* x = -1.35646279095478;
* Julia (tan): -4.593961172862999
* stdlib (tan): -4.593961172863
* Mathematica: -4.59396117286300026311049650877442413097818001966176559315
*
* Example 2:
* x = 1.4710248292410089
* Julia (tan): 9.989623320530624
* stdlib (tan): 9.989623320530626
* Mathematica: 9.989623320530629158499137574831736702146195199133529403233
*
* Example 3:
* x = 1.528545878614728
* Julia (tan): 23.654302824341386
* stdlib (tan): 23.65430282434139
* Mathematica: 23.65430282434144042648214719732782590575979471046811610915...
*/

expected = largeGamma.expected;
p = largeGamma.p;
x0 = largeGamma.x0;
gamma = largeGamma.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 50.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 > 0`)', opts, function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -167,22 +133,14 @@ tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma
gamma = positiveMedian.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 125.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 < 0`)', opts, function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -194,13 +152,7 @@ tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma
gamma = negativeMedian.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 90.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
// 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 PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var quantile = require( './../lib' );


Expand Down Expand Up @@ -95,58 +94,25 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', fu
tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` ( large `gamma`)', function test( t ) {
var expected;
var gamma;
var delta;
var tol;
var x0;
var p;
var y;
var i;

/*
* Higher tolerance than EPS because Julia gives slightly different results for
* |x| ~<= 3*pi/4:
*
* Example 1:
* x = -1.35646279095478;
* Julia (tan): -4.593961172862999
* stdlib (tan): -4.593961172863
* Mathematica: -4.59396117286300026311049650877442413097818001966176559315
*
* Example 2:
* x = 1.4710248292410089
* Julia (tan): 9.989623320530624
* stdlib (tan): 9.989623320530626
* Mathematica: 9.989623320530629158499137574831736702146195199133529403233
*
* Example 3:
* x = 1.528545878614728
* Julia (tan): 23.654302824341386
* stdlib (tan): 23.65430282434139
* Mathematica: 23.65430282434144042648214719732782590575979471046811610915...
*/

expected = largeGamma.expected;
p = largeGamma.p;
x0 = largeGamma.x0;
gamma = largeGamma.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 50.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 > 0`)', function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -158,22 +124,14 @@ tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma
gamma = positiveMedian.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 125.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma` (`x0 < 0`)', function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var p;
var y;
Expand All @@ -185,13 +143,7 @@ tape( 'the function evaluates the quantile function at `p` given `x0` and `gamma
gamma = negativeMedian.gamma;
for ( i = 0; i < p.length; i++ ) {
y = quantile( p[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'p: '+p[i]+', x0:'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 50.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 0 ), true, 'returns expected value' );
}
t.end();
});
Loading