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 @@ -33,7 +33,7 @@
> y = {{alias}}( -1.0, 1.0, 1.0 )
0.0
> y = {{alias}}( 0.0, 1.0, 1.0 )
0.0
1.0
> y = {{alias}}( NaN, 1.0, 1.0 )
NaN
> y = {{alias}}( 1.0, NaN, 1.0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface PDF {
*
* @example
* var y = pdf( 0.0, 1.0, 1.0 );
* // returns 0.0
* // returns 1.0
*
* @example
* var y = pdf( NaN, 1.0, 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var constantFunction = require( '@stdlib/utils/constant-function' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var PINF = require( '@stdlib/constants/float64/pinf' );


// MAIN //
Expand Down Expand Up @@ -66,9 +67,16 @@ function factory( alpha, beta ) {
if ( isnan( x ) ) {
return NaN;
}
if ( x <= 0.0 ) {
if ( x < 0.0 ) {
return 0.0;
}
// At `x = 0`, the density is infinite for `beta < 1`, `1/alpha` for `beta = 1`, and `0` for `beta > 1`:
if ( x === 0.0 ) {
if ( beta < 1.0 ) {
return PINF;
}
return ( beta === 1.0 ) ? 1.0 / alpha : 0.0;
}
xa = x / alpha;
xb = pow( xa, beta );
return ( beta / alpha ) * pow( xa, beta - 1.0 ) / pow( 1.0 + xb, 2.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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


// MAIN //
Expand All @@ -48,7 +49,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
*
* @example
* var y = pdf( 0.0, 1.0, 1.0 );
* // returns 0.0
* // returns 1.0
*
* @example
* var y = pdf( NaN, 1.0, 1.0 );
Expand Down Expand Up @@ -82,9 +83,16 @@ function pdf( x, alpha, beta ) {
) {
return NaN;
}
if ( x <= 0.0 ) {
if ( x < 0.0 ) {
return 0.0;
}
// At `x = 0`, the density is infinite for `beta < 1`, `1/alpha` for `beta = 1`, and `0` for `beta > 1`:
if ( x === 0.0 ) {
if ( beta < 1.0 ) {
return PINF;
}
return ( beta === 1.0 ) ? 1.0 / alpha : 0.0;
}
xa = x / alpha;
xb = pow( xa, beta );
return ( beta / alpha ) * pow( xa, beta - 1.0 ) / pow( 1.0 + xb, 2.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var addon = require( './../src/addon.node' );
*
* @example
* var y = pdf( 0.0, 1.0, 1.0 );
* // returns 0.0
* // returns 1.0
*
* @example
* var y = pdf( NaN, 1.0, 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"dependencies": [
"@stdlib/math/base/napi/ternary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow"
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pinf"
]
},
{
Expand All @@ -57,6 +58,7 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -73,7 +75,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow"
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pinf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "stdlib/stats/base/dists/log-logistic/pdf.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/pow.h"
#include "stdlib/constants/float64/pinf.h"

/**
* Evaluates the probability density function (PDF) for a log-logistic distribution with scale parameter `alpha` and shape parameter `beta` at a value `x`.
Expand All @@ -45,9 +46,16 @@ double stdlib_base_dists_log_logistic_pdf( const double x, const double alpha, c
) {
return 0.0 / 0.0; // NaN
}
if ( x <= 0.0 ) {
if ( x < 0.0 ) {
return 0.0;
}
// At `x = 0`, the density is infinite for `beta < 1`, `1/alpha` for `beta = 1`, and `0` for `beta > 1`:
if ( x == 0.0 ) {
if ( beta < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
return ( beta == 1.0 ) ? 1.0 / alpha : 0.0;
}
xa = x / alpha;
xb = stdlib_base_pow( xa, beta );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var NINF = require( '@stdlib/constants/float64/ninf' );
Expand Down Expand Up @@ -103,15 +104,12 @@ tape( 'the returned function returns `NaN` if provided `NaN` for `x`', function
t.end();
});

tape( 'the returned function returns `0` if provided `x <= 0`', function test( t ) {
tape( 'the returned function returns `0` if provided `x < 0`', function test( t ) {
var pdf;
var y;

pdf = factory( 1.0, 1.0 );

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

y = pdf( -1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );
y = pdf( NINF );
Expand All @@ -120,6 +118,21 @@ tape( 'the returned function returns `0` if provided `x <= 0`', function test( t
t.end();
});

tape( 'the returned function returns `+infinity`, `1/alpha`, or `0` at `x = 0` when `beta` is less than, equal to, or greater than one', function test( t ) {
var pdf;

pdf = factory( 2.0, 0.5 );
t.strictEqual( pdf( 0.0 ), PINF, 'returns expected value' );

pdf = factory( 2.0, 1.0 );
t.strictEqual( pdf( 0.0 ), 0.5, 'returns expected value' );

pdf = factory( 2.0, 3.0 );
t.strictEqual( pdf( 0.0 ), 0.0, 'returns expected value' );

t.end();
});

tape( 'the returned function evaluates the log-logistic pdf for positive `x`, `alpha`, and `beta`', function test( t ) {
var expected;
var alpha;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var tryRequire = require( '@stdlib/utils/try-require' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
Expand Down Expand Up @@ -97,12 +98,9 @@ tape( 'if provided a non-positive `beta`, the function returns `NaN`', opts, fun
t.end();
});

tape( 'if provided `x <= 0`, the function returns `0`', opts, function test( t ) {
tape( 'if provided `x < 0`, the function returns `0`', opts, function test( t ) {
var y;

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

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

Expand All @@ -115,6 +113,13 @@ tape( 'if provided `x <= 0`, the function returns `0`', opts, function test( t )
t.end();
});

tape( 'the function returns `+infinity`, `1/alpha`, or `0` at `x = 0` when `beta` is less than, equal to, or greater than one', opts, function test( t ) {
t.strictEqual( pdf( 0.0, 2.0, 0.5 ), PINF, 'returns expected value' );
t.strictEqual( pdf( 0.0, 2.0, 1.0 ), 0.5, 'returns expected value' );
t.strictEqual( pdf( 0.0, 2.0, 3.0 ), 0.0, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the log-logistic pdf for positive `x`, `alpha`, and `beta`', opts, function test( t ) {
var expected;
var alpha;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var NINF = require( '@stdlib/constants/float64/ninf' );
Expand Down Expand Up @@ -88,12 +89,9 @@ tape( 'if provided a non-positive `beta`, the function returns `NaN`', function
t.end();
});

tape( 'if provided `x <= 0`, the function returns `0`', function test( t ) {
tape( 'if provided `x < 0`, the function returns `0`', function test( t ) {
var y;

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

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

Expand All @@ -106,6 +104,13 @@ tape( 'if provided `x <= 0`, the function returns `0`', function test( t ) {
t.end();
});

tape( 'the function returns `+infinity`, `1/alpha`, or `0` at `x = 0` when `beta` is less than, equal to, or greater than one', function test( t ) {
t.strictEqual( pdf( 0.0, 2.0, 0.5 ), PINF, 'returns expected value' );
t.strictEqual( pdf( 0.0, 2.0, 1.0 ), 0.5, 'returns expected value' );
t.strictEqual( pdf( 0.0, 2.0, 3.0 ), 0.0, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the log-logistic pdf for positive `x`, `alpha`, and `beta`', function test( t ) {
var expected;
var alpha;
Expand Down
Loading