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 @@ -95,7 +95,7 @@
> weibull.logpdf( 1.0 )
~-7.865
> weibull.mgf( -0.5 )
~0.075
~0.109
> weibull.pdf( 3.0 )
~0.089
> weibull.quantile( 0.8 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var y = mgf( 1.0, 1.0, 0.5);
// returns ~2.0

y = mgf( -1.0, 4.0, 4.0 );
// returns ~0.019
// returns ~0.045
```

If provided `NaN` as any argument, the function returns `NaN`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
> var y = {{alias}}( 1.0, 1.0, 0.5 )
~2.0
> y = {{alias}}( -1.0, 4.0, 4.0 )
~0.019
~0.045

> y = {{alias}}( NaN, 1.0, 1.0 )
NaN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface MGF {
*
* @example
* var y = mgf( -1.0, 4.0, 4.0 );
* // returns ~0.019
* // returns ~0.045
*
* @example
* var y = mgf( NaN, 1.0, 1.0 );
Expand Down Expand Up @@ -112,7 +112,7 @@ interface MGF {
* // returns ~2.0
*
* y = mgf( -1.0, 4.0, 4.0 );
* // returns ~0.019
* // returns ~0.045
*
* var myMGF = mgf.factory( 8.0, 10.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 gamma = require( '@stdlib/math/base/special/gamma' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );


Expand Down Expand Up @@ -87,7 +88,7 @@ function factory( k, lambda ) {
summand = c * gamma( 1.0 + (n / k) );
}
sum += summand;
} while ( summand / sum > EPS );
} while ( abs( summand / sum ) > EPS );
return sum;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* // returns ~2.0
*
* y = mgf( -1.0, 4.0, 4.0 );
* // returns ~0.019
* // returns ~0.045
*
* var myMGF = mgf.factory( 8.0, 10.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 gamma = require( '@stdlib/math/base/special/gamma' );
var abs = require( '@stdlib/math/base/special/abs' );
var EPS = require( '@stdlib/constants/float64/eps' );


Expand All @@ -41,7 +42,7 @@ var EPS = require( '@stdlib/constants/float64/eps' );
*
* @example
* var y = mgf( -1.0, 4.0, 4.0 );
* // returns ~0.019
* // returns ~0.045
*
* @example
* var y = mgf( NaN, 1.0, 1.0 );
Expand Down Expand Up @@ -98,7 +99,7 @@ function mgf( t, k, lambda ) {
summand = c * gamma( 1.0 + (n / k) );
}
sum += summand;
} while ( summand / sum > EPS );
} while ( abs( summand / sum ) > EPS );
return sum;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var addon = require( './../src/addon.node' );
*
* @example
* var y = mgf( -1.0, 4.0, 4.0 );
* // returns ~0.019
* // returns ~0.045
*
* @example
* var y = mgf( NaN, 1.0, 1.0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@stdlib/math/base/napi/ternary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/gamma",
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -58,6 +59,7 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/gamma",
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/eps"
]
},
Expand All @@ -75,6 +77,7 @@
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/special/gamma",
"@stdlib/math/base/special/abs",
"@stdlib/constants/float64/eps"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "stdlib/stats/base/dists/weibull/mgf.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/gamma.h"
#include "stdlib/math/base/special/abs.h"
#include "stdlib/constants/float64/eps.h"

/**
Expand Down Expand Up @@ -60,6 +61,6 @@ double stdlib_base_dists_weibull_mgf( const double t, const double k, const doub
summand = c * stdlib_base_gamma( 1.0 + (n / k) );
}
sum += summand;
} while ( summand / sum > STDLIB_CONSTANT_FLOAT64_EPS );
} while ( stdlib_base_abs( summand / sum ) > STDLIB_CONSTANT_FLOAT64_EPS );
return sum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var tape = require( 'tape' );
var isNumber = require( '@stdlib/assert/is-number' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var randu = require( '@stdlib/random/base/randu' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
Expand Down Expand Up @@ -163,7 +164,7 @@
var x;
var y;

// TODO: Add test fixtures (function is not available in R and Julia)

Check warning on line 167 in lib/node_modules/@stdlib/stats/base/dists/weibull/mgf/test/test.factory.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: Add test fixtures (function is not...'
mgf = factory( 2.0, 2.0 );
for ( i = 0; i < 100; i++ ) {
x = randu();
Expand All @@ -172,3 +173,28 @@
}
t.end();
});

tape( 'the created function evaluates the mgf for negative `t`', function test( t ) {
var expected;
var mgf;
var x;
var y;
var i;

// Reference values computed by summing the series in 1024-bit precision:
mgf = factory( 2.0, 4.0 );
x = [ -0.3 ];
expected = [ 0.39615540526349546 ];
for ( i = 0; i < x.length; i++ ) {
y = mgf( x[ i ] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
mgf = factory( 1.0, 1.0 );
x = [ -0.1, -0.5 ];
expected = [ 0.9090909090909091, 0.6666666666666666 ];
for ( i = 0; i < x.length; i++ ) {
y = mgf( x[ i ] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var tape = require( 'tape' );
var isNumber = require( '@stdlib/assert/is-number' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var randu = require( '@stdlib/random/base/randu' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
Expand Down Expand Up @@ -124,7 +125,7 @@
var x;
var y;

// TODO: Add test fixtures (function is not available in R and Julia)

Check warning on line 128 in lib/node_modules/@stdlib/stats/base/dists/weibull/mgf/test/test.mgf.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: Add test fixtures (function is not...'
for ( i = 0; i < 100; i++ ) {
x = randu() * 5.0;
lambda = (randu() * 10.0) + EPS;
Expand All @@ -134,3 +135,30 @@
}
t.end();
});

tape( 'the function evaluates the mgf for negative `t`', function test( t ) {
var expected;
var lambda;
var k;
var x;
var y;
var i;

// Reference values computed by summing the series in 1024-bit precision:
x = [ -0.1, -0.5, -0.2, -0.3, -2.0, -0.5 ];
k = [ 1.0, 1.0, 3.0, 2.0, 2.0, 1.5 ];
lambda = [ 1.0, 1.0, 0.5, 4.0, 1.0, 2.0 ];
expected = [
0.9090909090909091,
0.6666666666666666,
0.9150539469807932,
0.39615540526349546,
0.2421278438586879,
0.4728095755272915
];
for ( i = 0; i < x.length; i++ ) {
y = mgf( x[ i ], k[ i ], lambda[ i ] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
var tryRequire = require( '@stdlib/utils/try-require' );
var isNumber = require( '@stdlib/assert/is-number' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var randu = require( '@stdlib/random/base/randu' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
Expand Down Expand Up @@ -118,7 +119,7 @@
var x;
var y;

// TODO: Add test fixtures (function is not available in R and Julia)

Check warning on line 122 in lib/node_modules/@stdlib/stats/base/dists/weibull/mgf/test/test.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: Add test fixtures (function is not...'
for ( i = 0; i < 100; i++ ) {
x = randu() * 5.0;
lambda = (randu() * 10.0) + EPS;
Expand All @@ -128,3 +129,30 @@
}
t.end();
});

tape( 'the function evaluates the mgf for negative `t`', opts, function test( t ) {
var expected;
var lambda;
var k;
var x;
var y;
var i;

// Reference values computed by summing the series in 1024-bit precision:
x = [ -0.1, -0.5, -0.2, -0.3, -2.0, -0.5 ];
k = [ 1.0, 1.0, 3.0, 2.0, 2.0, 1.5 ];
lambda = [ 1.0, 1.0, 0.5, 4.0, 1.0, 2.0 ];
expected = [
0.9090909090909091,
0.6666666666666666,
0.9150539469807932,
0.39615540526349546,
0.2421278438586879,
0.4728095755272915
];
for ( i = 0; i < x.length; i++ ) {
y = mgf( x[ i ], k[ i ], lambda[ i ] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 4 ), true, 'returns expected value' );
}
t.end();
});
Loading