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 @@ -25,6 +25,7 @@ var betaln = require( '@stdlib/math/base/special/betaln' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var log1p = require( '@stdlib/math/base/special/log1p' );
var ln = require( '@stdlib/math/base/special/ln' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );


Expand Down Expand Up @@ -75,10 +76,20 @@ function factory( alpha, beta ) {
if ( isnan( x ) ) {
return NaN;
}
if ( x <= 0.0 ) {
// Support of the beta prime distribution: (0,∞)
if ( x < 0.0 ) {
// Support of the beta prime distribution: [0,∞)
return NINF;
}
// At `x = 0`, the density is infinite for `alpha < 1`, `1/B(1,beta) = beta` for `alpha = 1`, and `0` for `alpha > 1`:
if ( x === 0.0 ) {
if ( alpha < 1.0 ) {
return PINF;
}
if ( alpha > 1.0 ) {
return NINF;
}
return ln( beta );
}
out = ( alpha-1.0 ) * ln( x );
out -= ( alpha+beta ) * log1p( x );
out -= betalnAB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var betaln = require( '@stdlib/math/base/special/betaln' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var log1p = require( '@stdlib/math/base/special/log1p' );
var ln = require( '@stdlib/math/base/special/ln' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );


Expand Down Expand Up @@ -89,10 +90,20 @@ function logpdf( x, alpha, beta ) {
) {
return NaN;
}
if ( x <= 0.0 ) {
// Support of the beta prime distribution: (0,∞)
if ( x < 0.0 ) {
// Support of the beta prime distribution: [0,∞)
return NINF;
}
// At `x = 0`, the density is infinite for `alpha < 1`, `1/B(1,beta) = beta` for `alpha = 1`, and `0` for `alpha > 1`:
if ( x === 0.0 ) {
if ( alpha < 1.0 ) {
return PINF;
}
if ( alpha > 1.0 ) {
return NINF;
}
return ln( beta );
}
out = ( alpha-1.0 ) * ln( x );
out -= ( alpha+beta ) * log1p( x );
out -= betaln( alpha, beta );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@stdlib/math/base/special/betaln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf"
]
},
Expand All @@ -62,6 +63,7 @@
"@stdlib/math/base/special/betaln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf",
"@stdlib/constants/float64/eps"
]
Expand All @@ -82,6 +84,7 @@
"@stdlib/math/base/special/betaln",
"@stdlib/math/base/special/log1p",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf",
"@stdlib/constants/float64/eps"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "stdlib/math/base/special/betaln.h"
#include "stdlib/math/base/special/log1p.h"
#include "stdlib/math/base/special/ln.h"
#include "stdlib/constants/float64/pinf.h"
#include "stdlib/constants/float64/ninf.h"

/**
Expand All @@ -45,10 +46,20 @@ double stdlib_base_dists_betaprime_logpdf( const double x, const double alpha, c
) {
return 0.0 / 0.0;
}
if ( x <= 0.0 ) {
// Support of the beta prime distribution: (0,∞)
if ( x < 0.0 ) {
// Support of the beta prime distribution: [0,∞)
return STDLIB_CONSTANT_FLOAT64_NINF;
}
// At `x = 0`, the density is infinite for `alpha < 1`, `1/B(1,beta) = beta` for `alpha = 1`, and `0` for `alpha > 1`:
if ( x == 0.0 ) {
if ( alpha < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
if ( alpha > 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}
return stdlib_base_ln( beta );
}
out = ( alpha-1.0 ) * stdlib_base_ln( x );
out -= ( alpha+beta ) * stdlib_base_log1p( x );
out -= stdlib_base_betaln( alpha, 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 ln = require( '@stdlib/math/base/special/ln' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
Expand Down Expand Up @@ -94,6 +95,21 @@ tape( 'if provided a valid `alpha` and `beta`, the function returns a function w
t.end();
});

tape( 'the created function returns `+infinity`, `ln(beta)`, or `-infinity` at `x = 0` when `alpha` is less than, equal to, or greater than one', function test( t ) {
var logpdf;

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

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

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

t.end();
});

tape( 'if provided `beta <= 0`, the created function always returns `NaN`', function test( t ) {
var logpdf;
var y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var ln = require( '@stdlib/math/base/special/ln' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
Expand Down Expand Up @@ -69,6 +70,13 @@ tape( 'if provided a number smaller than zero for `x` and a valid `alpha` and `b
t.end();
});

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

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

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 ln = require( '@stdlib/math/base/special/ln' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var abs = require( '@stdlib/math/base/special/abs' );
Expand Down Expand Up @@ -78,6 +79,13 @@ tape( 'if provided a number smaller than zero for `x` and a valid `alpha` and `b
t.end();
});

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
t.end();
});

tape( 'if provided a valid `alpha` and `beta`, the function returns a function which returns `0` when provided a nonpositive number for `x`', function test( t ) {
tape( 'if provided a valid `alpha` and `beta`, the function returns a function which returns `0` when provided a negative number for `x`', function test( t ) {
var pdf;
var y;

Expand All @@ -90,8 +90,20 @@ tape( 'if provided a valid `alpha` and `beta`, the function returns a function w
y = pdf( -0.5 );
t.strictEqual( y, 0.0, 'returns expected value' );

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

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

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

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

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

t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
t.end();
});

tape( 'if provided a nonpositive number for `x` and a valid `alpha` and `beta`, the function returns `0`', opts, function test( t ) {
tape( 'if provided a negative number for `x` and a valid `alpha` and `beta`, the function returns `0`', opts, function test( t ) {
var y;

y = pdf( NINF, 1.0, 1.0 );
Expand All @@ -74,9 +74,13 @@ tape( 'if provided a nonpositive number for `x` and a valid `alpha` and `beta`,
y = pdf( -0.5, 1.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', functio
t.end();
});

tape( 'if provided a nonpositive number for `x` and a valid `alpha` and `beta`, the function returns `0`', function test( t ) {
tape( 'if provided a negative number for `x` and a valid `alpha` and `beta`, the function returns `0`', function test( t ) {
var y;

y = pdf( NINF, 1.0, 1.0 );
Expand All @@ -65,9 +65,13 @@ tape( 'if provided a nonpositive number for `x` and a valid `alpha` and `beta`,
y = pdf( -0.5, 1.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );

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

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

Expand Down
Loading