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 @@ -24,6 +24,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 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 @@ -73,9 +74,28 @@ function factory( a, b ) {
if ( isnan( x ) ) {
return NaN;
}
if ( x <= 0.0 || x >= 1.0 ) {
if ( x < 0.0 || x > 1.0 ) {
return NINF;
}
// At the boundaries of the support, the density is infinite, finite, or zero depending on whether the corresponding shape parameter is less than, equal to, or greater than one:
if ( x === 0.0 ) {
if ( a < 1.0 ) {
return PINF;
}
if ( a > 1.0 ) {
return NINF;
}
return ln( b );
}
if ( x === 1.0 ) {
if ( b < 1.0 ) {
return PINF;
}
if ( b > 1.0 ) {
return NINF;
}
return ln( a );
}
out = ln( a*b );
out += ( a - 1.0 ) * ln( x );
out += ( b - 1.0 ) * ln( 1.0 - pow( x, a ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
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 @@ -92,9 +93,28 @@ function logpdf( x, a, b ) {
) {
return NaN;
}
if ( x <= 0.0 || x >= 1.0 ) {
if ( x < 0.0 || x > 1.0 ) {
return NINF;
}
// At the boundaries of the support, the density is infinite, finite, or zero depending on whether the corresponding shape parameter is less than, equal to, or greater than one:
if ( x === 0.0 ) {
if ( a < 1.0 ) {
return PINF;
}
if ( a > 1.0 ) {
return NINF;
}
return ln( b );
}
if ( x === 1.0 ) {
if ( b < 1.0 ) {
return PINF;
}
if ( b > 1.0 ) {
return NINF;
}
return ln( a );
}
out = ln( a*b );
out += ( a - 1.0 ) * ln( x );
out += ( b - 1.0 ) * ln( 1.0 - pow( x, a ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf"
]
},
Expand All @@ -60,6 +61,7 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf"
]
},
Expand All @@ -78,6 +80,7 @@
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/pow",
"@stdlib/math/base/special/ln",
"@stdlib/constants/float64/pinf",
"@stdlib/constants/float64/ninf"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/pow.h"
#include "stdlib/math/base/special/ln.h"
#include "stdlib/constants/float64/pinf.h"
#include "stdlib/constants/float64/ninf.h"

/**
Expand All @@ -45,12 +46,28 @@ double stdlib_base_dists_kumaraswamy_logpdf( const double x, const double a, con
) {
return 0.0/0.0; // NaN
}
if (
x <= 0.0 ||
x >= 1.0
) {
if ( x < 0.0 || x > 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}
// At the boundaries of the support, the density is infinite, finite, or zero depending on whether the corresponding shape parameter is less than, equal to, or greater than one:
if ( x == 0.0 ) {
if ( a < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
if ( a > 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}
return stdlib_base_ln( b );
}
if ( x == 1.0 ) {
if ( b < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
if ( b > 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_NINF;
}
return stdlib_base_ln( a );
}
out = stdlib_base_ln( a*b );
out += ( a - 1.0 ) * stdlib_base_ln( x );
out += ( b - 1.0 ) * stdlib_base_ln( 1.0 - stdlib_base_pow( x, a ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tape( 'if provided `NaN` for any parameter, the created function returns `NaN`',
t.end();
});

tape( 'if provided a finite `a` and `b`, the function returns a function which returns `-infinity` when provided a number greater than or equal to one for `x`', function test( t ) {
tape( 'if provided a finite `a` and `b`, the function returns a function which returns `-infinity` when provided a number greater than one for `x`', function test( t ) {
var logpdf;
var y;

Expand All @@ -87,13 +87,10 @@ tape( 'if provided a finite `a` and `b`, the function returns a function which r
y = logpdf( 10.0 );
t.strictEqual( y, NINF, 'returns expected value' );

y = logpdf( 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

t.end();
});

tape( 'if provided a finite `a` and `b`, the function returns a function which returns `-infinity` when provided a number smaller than or equal to zero for `x`', function test( t ) {
tape( 'if provided a finite `a` and `b`, the function returns a function which returns `-infinity` when provided a number smaller than zero for `x`', function test( t ) {
var logpdf;
var y;

Expand All @@ -110,8 +107,35 @@ tape( 'if provided a finite `a` and `b`, the function returns a function which r
y = logpdf( -1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

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

tape( 'the created function returns `+infinity`, `ln(b)`, or `-infinity` at `x = 0` when `a` 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( 'the created function returns `+infinity`, `ln(a)`, or `-infinity` at `x = 1` when `b` is less than, equal to, or greater than one', function test( t ) {
var logpdf;

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

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

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

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

tape( 'if provided a number greater than or equal to one for `x` and a finite `a` and `b`, the function returns `-infinity`', function test( t ) {
tape( 'if provided a number greater than one for `x` and a finite `a` and `b`, the function returns `-infinity`', function test( t ) {
var y = logpdf( PINF, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

Expand All @@ -60,13 +60,10 @@ tape( 'if provided a number greater than or equal to one for `x` and a finite `a
y = logpdf( 10.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

y = logpdf( 1.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

t.end();
});

tape( 'if provided a number less than or equal to zero for `x` and a finite `a` and `b`, the function returns `-infinity`', function test( t ) {
tape( 'if provided a number less than zero for `x` and a finite `a` and `b`, the function returns `-infinity`', function test( t ) {
var y = logpdf( NINF, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

Expand All @@ -76,9 +73,20 @@ tape( 'if provided a number less than or equal to zero for `x` and a finite `a`
y = logpdf( -1.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

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

tape( 'the function returns `+infinity`, `ln(b)`, or `-infinity` at `x = 0` when `a` 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( 'the function returns `+infinity`, `ln(a)`, or `-infinity` at `x = 1` when `b` is less than, equal to, or greater than one', function test( t ) {
t.strictEqual( logpdf( 1.0, 3.0, 0.5 ), PINF, 'returns expected value' );
t.strictEqual( logpdf( 1.0, 3.0, 1.0 ), ln( 3.0 ), 'returns expected value' );
t.strictEqual( logpdf( 1.0, 3.0, 2.0 ), NINF, 'returns expected value' );
t.end();
});

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

tape( 'if provided a number greater than or equal to one for `x` and a finite `a` and `b`, the function returns `-infinity`', opts, function test( t ) {
tape( 'if provided a number greater than one for `x` and a finite `a` and `b`, the function returns `-infinity`', opts, function test( t ) {
var y = logpdf( PINF, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

Expand All @@ -69,13 +69,10 @@ tape( 'if provided a number greater than or equal to one for `x` and a finite `a
y = logpdf( 10.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

y = logpdf( 1.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

t.end();
});

tape( 'if provided a number less than or equal to zero for `x` and a finite `a` and `b`, the function returns `-infinity`', opts, function test( t ) {
tape( 'if provided a number less than zero for `x` and a finite `a` and `b`, the function returns `-infinity`', opts, function test( t ) {
var y = logpdf( NINF, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

Expand All @@ -85,9 +82,20 @@ tape( 'if provided a number less than or equal to zero for `x` and a finite `a`
y = logpdf( -1.0, 0.5, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );

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

tape( 'the function returns `+infinity`, `ln(b)`, or `-infinity` at `x = 0` when `a` 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( 'the function returns `+infinity`, `ln(a)`, or `-infinity` at `x = 1` when `b` is less than, equal to, or greater than one', opts, function test( t ) {
t.strictEqual( logpdf( 1.0, 3.0, 0.5 ), PINF, 'returns expected value' );
t.strictEqual( logpdf( 1.0, 3.0, 1.0 ), ln( 3.0 ), 'returns expected value' );
t.strictEqual( logpdf( 1.0, 3.0, 2.0 ), NINF, 'returns expected value' );
t.end();
});

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 @@ -69,9 +70,28 @@ function factory( a, b ) {
if ( isnan( x ) ) {
return NaN;
}
if ( x <= 0.0 || x >= 1.0 ) {
if ( x < 0.0 || x > 1.0 ) {
return 0.0;
}
// At the boundaries of the support, the density is infinite, finite, or zero depending on whether the corresponding shape parameter is less than, equal to, or greater than one:
if ( x === 0.0 ) {
if ( a < 1.0 ) {
return PINF;
}
if ( a > 1.0 ) {
return 0.0;
}
return b;
}
if ( x === 1.0 ) {
if ( b < 1.0 ) {
return PINF;
}
if ( b > 1.0 ) {
return 0.0;
}
return a;
}
return ( a*b ) * pow( x, a - 1.0 ) * pow( 1.0 - pow( x, a ), b - 1.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 Down Expand Up @@ -88,9 +89,28 @@ function pdf( x, a, b ) {
) {
return NaN;
}
if ( x <= 0.0 || x >= 1.0 ) {
if ( x < 0.0 || x > 1.0 ) {
return 0.0;
}
// At the boundaries of the support, the density is infinite, finite, or zero depending on whether the corresponding shape parameter is less than, equal to, or greater than one:
if ( x === 0.0 ) {
if ( a < 1.0 ) {
return PINF;
}
if ( a > 1.0 ) {
return 0.0;
}
return b;
}
if ( x === 1.0 ) {
if ( b < 1.0 ) {
return PINF;
}
if ( b > 1.0 ) {
return 0.0;
}
return a;
}
return ( a*b ) * pow( x, a - 1.0 ) * pow( 1.0 - pow( x, a ), b - 1.0 );
}

Expand Down
Loading
Loading