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 @@ -223,7 +223,7 @@ int main( void ) {
for ( i = 0; i < 25; i++ ) {
x = random_uniform( 0.0, 10.0 );
x0 = random_uniform( -5.0, 5.0 );
gamma = random_uniform( 0.0, 20.0 ) + STDLIB_CONSTANT_FLOAT64_EPS;
gamma = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_cauchy_pdf( x, x0, gamma );
printf( "x: %lf, k: %lf, γ: %lf, f(x;x0,γ): %lf\n", x, x0, gamma, y );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var tryRequire = require( '@stdlib/utils/try-require' );
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 @@ -121,9 +119,7 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', op

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (large `gamma`)', opts, function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -135,22 +131,14 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (large `gam
gamma = largeGamma.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 < 0`)', opts, function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -162,22 +150,14 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 < 0`)'
gamma = negativeMedian.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 > 0`)', opts, function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -189,13 +169,7 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 > 0`)'
gamma = positiveMedian.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

var tape = require( 'tape' );
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 pdf = require( './../lib' );


Expand Down Expand Up @@ -112,9 +110,7 @@ tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', fu

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (large `gamma`)', function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -126,22 +122,14 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (large `gam
gamma = largeGamma.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 < 0`)', function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -153,22 +141,14 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 < 0`)'
gamma = negativeMedian.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});

tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 > 0`)', function test( t ) {
var expected;
var delta;
var gamma;
var tol;
var x0;
var x;
var y;
Expand All @@ -180,13 +160,7 @@ tape( 'the function evaluates the pdf for `x` given `x0` and `gamma` (`x0 > 0`)'
gamma = positiveMedian.gamma;
for ( i = 0; i < x.length; i++ ) {
y = pdf( x[i], x0[i], gamma[i] );
if ( y === expected[i] ) {
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 1.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. x0: '+x0[i]+'. gamma: '+gamma[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'x: '+x[i]+', x0 :'+x0[i]+', gamma: '+gamma[i]+', y: '+y+', expected: '+expected[i] );
}
t.end();
});