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 @@ -78,6 +78,10 @@ function factory( k, lambda ) {
return NINF;
}
if ( x === 0.0 ) {
// The density at `0` is infinite for `k < 1`, `1/lambda` for `k = 1`, and `0` for `k > 1`:
if ( k < 1.0 ) {
return PINF;
}
return ( k === 1.0 ) ? ln( k / lambda ) : NINF;
}
xol = x / lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function logpdf( x, k, lambda ) {
return NINF;
}
if ( x === 0.0 ) {
// The density at `0` is infinite for `k < 1`, `1/lambda` for `k = 1`, and `0` for `k > 1`:
if ( k < 1.0 ) {
return PINF;
}
return ( k === 1.0 ) ? ln( k/lambda ): NINF;
}
xol = x / lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ double stdlib_base_dists_weibull_logpdf( const double x, const double k, const d
return STDLIB_CONSTANT_FLOAT64_NINF;
}
if ( x == 0.0 ) {
// The density at `0` is infinite for `k < 1`, `1/lambda` for `k = 1`, and `0` for `k > 1`:
if ( k < 1.0 ) {
return STDLIB_CONSTANT_FLOAT64_PINF;
}
return ( k == 1.0 ) ? stdlib_base_ln( k/lambda ) : STDLIB_CONSTANT_FLOAT64_NINF;
}
xol = x / lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ tape( 'if provided a positive `lambda` and `k` equal to one, the created functio
t.end();
});

tape( 'if provided a positive `lambda` and `k` not equal to one, the created function returns `-infinity` for `x=0`', function test( t ) {
tape( 'if provided a positive `lambda` and `k` greater than one, the created function returns `-infinity` for `x=0`', function test( t ) {
var logpdf;
var y;

Expand All @@ -199,6 +199,16 @@ tape( 'if provided a positive `lambda` and `k` not equal to one, the created fu
t.end();
});

tape( 'if provided a positive `lambda` and `k` less than one, the created function returns `+infinity` for `x=0`', function test( t ) {
var logpdf;
var y;

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

tape( 'the created function evaluates the logpdf for `x` given large `lambda` and `k`', function test( t ) {
var expected;
var logpdf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` equal to one, the
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` not equal to one, the function returns `-Infinity`', function test( t ) {
tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` greater than one, the function returns `-Infinity`', function test( t ) {
var y = logpdf( 0.0, 2.0, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` less than one, the function returns `+Infinity`', function test( t ) {
var y = logpdf( 0.0, 0.5, 1.0 );
t.strictEqual( y, PINF, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the logpdf for `x` given large `lambda` and `k`', function test( t ) {
var expected;
var lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` equal to one, the
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` not equal to one, the function returns `-Infinity`', opts, function test( t ) {
tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` greater than one, the function returns `-Infinity`', opts, function test( t ) {
var y = logpdf( 0.0, 2.0, 1.0 );
t.strictEqual( y, NINF, 'returns expected value' );
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` less than one, the function returns `+Infinity`', opts, function test( t ) {
var y = logpdf( 0.0, 0.5, 1.0 );
t.strictEqual( y, PINF, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the logpdf for `x` given large `lambda` and `k`', opts, function test( t ) {
var expected;
var lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function factory( k, lambda ) {
return 0.0;
}
if ( x === 0.0 ) {
// The density at `0` is infinite for `k < 1`, `1/lambda` for `k = 1`, and `0` for `k > 1`:
if ( k < 1.0 ) {
return PINF;
}
return ( k === 1.0 ) ? k / lambda : 0.0;
}
xol = x / lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function pdf( x, k, lambda ) {
return 0.0;
}
if ( x === 0.0 ) {
// The density at `0` is infinite for `k < 1`, `1/lambda` for `k = 1`, and `0` for `k > 1`:
if ( k < 1.0 ) {
return PINF;
}
return ( k === 1.0 ) ? k/lambda : 0.0;
}
xol = x / lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ tape( 'if provided a positive `lambda` and `k` equal to one, the created functio
t.end();
});

tape( 'if provided a positive `lambda` and `k` not equal to one, the created function returns `0` for `x=0`', function test( t ) {
tape( 'if provided a positive `lambda` and `k` greater than one, the created function returns `0` for `x=0`', function test( t ) {
var pdf;
var y;

Expand All @@ -196,6 +196,16 @@ tape( 'if provided a positive `lambda` and `k` not equal to one, the created fu
t.end();
});

tape( 'if provided a positive `lambda` and `k` less than one, the created function returns `+infinity` for `x=0`', function test( t ) {
var pdf;
var y;

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

tape( 'the created function evaluates the pdf for `x` given large `lambda` and `k`', function test( t ) {
var expected;
var lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` equal to one, the
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` not equal to one, the function returns `0`', opts, function test( t ) {
tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` greater than one, the function returns `0`', opts, function test( t ) {
var y = pdf( 0.0, 2.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` less than one, the function returns `+Infinity`', opts, function test( t ) {
var y = pdf( 0.0, 0.5, 1.0 );
t.strictEqual( y, PINF, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the pdf for `x` given large `lambda` and `k`', opts, function test( t ) {
var expected;
var lambda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,18 @@ tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` equal to one, the
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` not equal to one, the function returns `0`', function test( t ) {
tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` greater than one, the function returns `0`', function test( t ) {
var y = pdf( 0.0, 2.0, 1.0 );
t.strictEqual( y, 0.0, 'returns expected value' );
t.end();
});

tape( 'if provided `0.0` for `x`, a positive `lambda` and `k` less than one, the function returns `+Infinity`', function test( t ) {
var y = pdf( 0.0, 0.5, 1.0 );
t.strictEqual( y, PINF, 'returns expected value' );
t.end();
});

tape( 'the function evaluates the pdf for `x` given large `lambda` and `k`', function test( t ) {
var expected;
var lambda;
Expand Down
Loading