Skip to content
Open
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 @@ -23,7 +23,8 @@
var constantFunction = require( '@stdlib/utils/constant-function' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var ln = require( '@stdlib/math/base/special/ln' );
var log1p = require( '@stdlib/math/base/special/log1p' );
var max = require( '@stdlib/math/base/special/max' );
var PINF = require( '@stdlib/constants/float64/pinf' );


Expand Down Expand Up @@ -70,7 +71,7 @@ function factory( lambda ) {
if ( p === 1.0 ) {
return PINF;
}
return ceil( -ln( 1.0-p ) / lambda ) - 1.0;
return max( 0.0, ceil( -log1p( -p ) / lambda ) - 1.0 );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var ln = require( '@stdlib/math/base/special/ln' );
var log1p = require( '@stdlib/math/base/special/log1p' );
var max = require( '@stdlib/math/base/special/max' );
var PINF = require( '@stdlib/constants/float64/pinf' );


Expand Down Expand Up @@ -74,7 +75,7 @@ function quantile( p, lambda ) {
if ( p === 1.0 ) {
return PINF;
}
return ceil( -ln( 1.0-p ) / lambda ) - 1.0;
return max( 0.0, ceil( -log1p( -p ) / lambda ) - 1.0 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ceil",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/max",
"@stdlib/constants/float64/pinf"
]
},
Expand All @@ -59,7 +60,8 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ceil",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/max",
"@stdlib/constants/float64/pinf"
]
},
Expand All @@ -77,7 +79,8 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/ceil",
"@stdlib/math/base/special/ln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/max",
"@stdlib/constants/float64/pinf"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#include "stdlib/stats/base/dists/planck/quantile.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/ceil.h"
#include "stdlib/math/base/special/ln.h"
#include "stdlib/math/base/special/log1p.h"
#include "stdlib/math/base/special/max.h"
#include "stdlib/constants/float64/pinf.h"

/**
Expand All @@ -40,5 +41,5 @@ double stdlib_base_dists_planck_quantile( const double p, const double lambda )
if ( p == 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
return stdlib_base_ceil( -stdlib_base_ln( 1.0 - p ) / lambda ) - 1.0;
return stdlib_base_max( 0.0, stdlib_base_ceil( -stdlib_base_log1p( -p ) / lambda ) - 1.0 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,42 @@ tape( 'the returned function evaluates the quantile for `p` given large paramete
}
t.end();
});

tape( 'the returned function evaluates the quantile for small `p`', function test( t ) {
var quantile;
var y;

quantile = factory( 1.0 );
y = quantile( 1.0e-20 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-300 );
t.strictEqual( y, 0.0, 'returns expected value' );

quantile = factory( 1.0e-17 );
y = quantile( 1.0e-15 );
t.strictEqual( y, 100.0, 'returns expected value' );

quantile = factory( 1.0e-14 );
y = quantile( 1.0e-12 );
t.strictEqual( y, 100.0, 'returns expected value' );
t.end();
});

tape( 'the returned function returns `0` for `p = 0` and where `-ln(1-p)/lambda` underflows', function test( t ) {
var quantile;
var y;

quantile = factory( 1.0 );
y = quantile( 0.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

quantile = factory( 2.0 );
y = quantile( 5.0e-324 );
t.strictEqual( y, 0.0, 'returns expected value' );

quantile = factory( 1.0e300 );
y = quantile( 1.0e-300 );
t.strictEqual( y, 0.0, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,34 @@ tape( 'the function evaluates the quantile for `p` given large parameter `lambda
}
t.end();
});

tape( 'the function evaluates the quantile for small `p`', opts, function test( t ) {
var y;

y = quantile( 1.0e-20, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-300, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-15, 1.0e-17 );
t.strictEqual( y, 100.0, 'returns expected value' );

y = quantile( 1.0e-12, 1.0e-14 );
t.strictEqual( y, 100.0, 'returns expected value' );
t.end();
});

tape( 'the function returns `0` for `p = 0` and where `-ln(1-p)/lambda` underflows', opts, function test( t ) {
var y;

y = quantile( 0.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 5.0e-324, 2.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-300, 1.0e300 );
t.strictEqual( y, 0.0, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,34 @@ tape( 'the function evaluates the quantile for `p` given large parameter `lambda
}
t.end();
});

tape( 'the function evaluates the quantile for small `p`', function test( t ) {
var y;

y = quantile( 1.0e-20, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-300, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-15, 1.0e-17 );
t.strictEqual( y, 100.0, 'returns expected value' );

y = quantile( 1.0e-12, 1.0e-14 );
t.strictEqual( y, 100.0, 'returns expected value' );
t.end();
});

tape( 'the function returns `0` for `p = 0` and where `-ln(1-p)/lambda` underflows', function test( t ) {
var y;

y = quantile( 0.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 5.0e-324, 2.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

y = quantile( 1.0e-300, 1.0e300 );
t.strictEqual( y, 0.0, 'returns expected value' );
t.end();
});
Loading