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 @@ -224,7 +224,7 @@ Evaluates the [moment-generating function][mgf] (MGF).
var geometric = new Geometric( 0.2 );

var y = geometric.mgf( 0.1 );
// returns ~1.908
// returns ~1.726
```

#### Geometric.prototype.pmf( x )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
> geometric.logpmf( 4.0 )
~-4.176
> geometric.mgf( 0.5 )
~2.905
~1.762
> geometric.pmf( 2.0 )
~0.096
> geometric.quantile( 0.7 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ setReadOnly( Geometric.prototype, 'logpmf', geometricLogPMF );
* var geometric = new Geometric( 0.2 );
*
* var v = geometric.mgf( 0.1 );
* // returns ~1.908
* // returns ~1.726
*/
setReadOnly( Geometric.prototype, 'mgf', geometricMGF );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ limitations under the License.

The [moment-generating function][mgf] for a [geometric][geometric-distribution] random variable is

<!-- <equation class="equation" label="eq:geometric_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{pe^t}{1-(1-p) e^t} \text{ for } t<-\ln(1-p)" alt="Moment-generating function (MGF) for a geometric distribution."> -->
<!-- <equation class="equation" label="eq:geometric_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{p}{1-(1-p) e^t} \text{ for } t<-\ln(1-p)" alt="Moment-generating function (MGF) for a geometric distribution."> -->

```math
M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{pe^t}{1-(1-p) e^t} \text{ for } t<-\ln(1-p)
M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{p}{1-(1-p) e^t} \text{ for } t<-\ln(1-p)
```

<!-- <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{pe^t}{1-(1-p) e^t} \text{ for } t&lt;-\ln(1-p)" data-equation="eq:geometric_mgf_function">
<!-- <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{p}{1-(1-p) e^t} \text{ for } t&lt;-\ln(1-p)" data-equation="eq:geometric_mgf_function">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/mgf/docs/img/equation_geometric_mgf_function.svg" alt="Moment-generating function (MGF) for a geometric distribution.">
<br>
</div> -->
Expand Down Expand Up @@ -63,10 +63,10 @@ Evaluates the moment-generating function ([MGF][mgf]) of a [geometric][geometric

```javascript
var y = mgf( 0.2, 0.5 );
// returns ~1.569
// returns ~1.284

y = mgf( 0.4, 0.5 );
// returns ~2.936
// returns ~1.968
```

If provided `NaN` as any argument, the function returns `NaN`.
Expand Down Expand Up @@ -103,7 +103,7 @@ Returns a function for evaluating the [moment-generating function][mgf] of a [ge
```javascript
var mymgf = mgf.factory( 0.8 );
var y = mymgf( -0.2 );
// returns ~0.783
// returns ~0.957
```

</section>
Expand Down Expand Up @@ -176,7 +176,7 @@ Evaluates the [moment-generating function][mgf] of a [geometric][geometric-distr

```c
double out = stdlib_base_dists_geometric_mgf( 0.2, 0.5 );
// returns ~1.569
// returns ~1.284
```

The function accepts the following arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
Examples
--------
> var y = {{alias}}( 0.2, 0.5 )
~1.569
~1.284
> y = {{alias}}( 0.4, 0.5 )
~2.936
~1.968
// Case: t >= -ln(1-p)
> y = {{alias}}( 0.8, 0.5 )
NaN
Expand Down Expand Up @@ -59,7 +59,7 @@
--------
> var mymgf = {{alias}}.factory( 0.8 );
> var y = mymgf( -0.2 )
~0.783
~0.957

See Also
--------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ interface MGF {
*
* @example
* var y = mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*
* @example
* var y = mgf( 0.4, 0.5 );
* // returns ~2.936
* // returns ~1.968
*
* @example
* // Case: t >= -ln(1-p)
Expand Down Expand Up @@ -81,7 +81,7 @@ interface MGF {
* @example
* var mymgf = mgf.factory( 0.8 );
* var y = mymgf( -0.2 );
* // returns ~0.783
* // returns ~0.957
*/
factory( p: number ): Unary;
}
Expand All @@ -95,14 +95,14 @@ interface MGF {
*
* @example
* var y = mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*
* y = mgf( 0.4, 0.5 );
* // returns ~2.936
* // returns ~1.968
*
* var mymgf = mgf.factory( 0.8 );
* y = mymgf( -0.2 );
* // returns ~0.783
* // returns ~0.957
*/
declare var mgf: MGF;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var ln = require( '@stdlib/math/base/special/ln' );
* @example
* var mgf = factory( 0.8 );
* var y = mgf( -0.2 );
* // returns ~0.783
* // returns ~0.957
*/
function factory( p ) {
if ( !isProbability( p ) ) {
Expand Down Expand Up @@ -68,7 +68,7 @@ function factory( p ) {
return NaN;
}
et = exp( t );
return ( p * et ) / ( 1.0 - (q * et ));
return p / ( 1.0 - (q * et) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
* var mgf = require( '@stdlib/stats/base/dists/geometric/mgf' );
*
* var y = mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*
* y = mgf( 0.4, 0.5 );
* // returns ~2.936
* // returns ~1.968
*
* var mymgf = mgf.factory( 0.8 );
* y = mymgf( -0.2 );
* // returns ~0.783
* // returns ~0.957
*/

// MODULES //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var ln = require( '@stdlib/math/base/special/ln' );
*
* @example
* var y = mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*
* @example
* var y = mgf( 0.4, 0.5 );
* // returns ~2.936
* // returns ~1.968
*
* @example
* // Case: t >= -ln(1-p)
Expand Down Expand Up @@ -75,7 +75,7 @@ function mgf( t, p ) {
return NaN;
}
et = exp( t );
return ( p * et ) / ( 1.0 - (q * et) );
return p / ( 1.0 - (q * et) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ var addon = require( './../src/addon.node' );
*
* @example
* var y = mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*
* @example
* var y = mgf( 0.4, 0.5 );
* // returns ~2.936
* // returns ~1.968
*
* @example
* // Case: t >= -ln(1-p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @example
* double y = stdlib_base_dists_geometric_mgf( 0.2, 0.5 );
* // returns ~1.569
* // returns ~1.284
*/
double stdlib_base_dists_geometric_mgf( const double t, const double p ) {
if (
Expand All @@ -45,5 +45,5 @@ double stdlib_base_dists_geometric_mgf( const double t, const double p ) {
if ( t >= -stdlib_base_ln( q ) ) {
return 0.0/0.0; // NaN
}
return ( p * stdlib_base_exp( t ) ) / ( 1.0 - ( q * stdlib_base_exp( t ) ) );
return p / ( 1.0 - ( q * stdlib_base_exp( t ) ) );
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Distributions 0.23.8
julia 1.5
JSON 0.21
Distributions 0.25.131
julia 1.10.10
JSON 1.10.0

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
var ln = require( '@stdlib/math/base/special/ln' );
var exp = require( '@stdlib/math/base/special/exp' );
var mgf = require( './../lib' );


Expand Down Expand Up @@ -167,11 +166,14 @@ tape( 'the function returns `NaN` when `p` equals `0`', function test( t ) {
t.end();
});

tape( 'the function returns `e^t` when `p` equals `1`', function test( t ) {
tape( 'the function returns `1` when `p` equals `1`', function test( t ) {
var y;

y = mgf( 0.5, 1.0 );
t.strictEqual( y, exp( 0.5 ), 'returns expected value' );
t.strictEqual( y, 1.0, 'returns expected value' );

y = mgf( -2.0, 1.0 );
t.strictEqual( y, 1.0, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
var ln = require( '@stdlib/math/base/special/ln' );
var exp = require( '@stdlib/math/base/special/exp' );


// FIXTURES //
Expand Down Expand Up @@ -176,11 +175,14 @@ tape( 'the function returns `NaN` when `p` equals `0`', opts, function test( t )
t.end();
});

tape( 'the function returns `e^t` when `p` equals `1`', opts, function test( t ) {
tape( 'the function returns `1` when `p` equals `1`', opts, function test( t ) {
var y;

y = mgf( 0.5, 1.0 );
t.strictEqual( y, exp( 0.5 ), 'returns expected value' );
t.strictEqual( y, 1.0, 'returns expected value' );

y = mgf( -2.0, 1.0 );
t.strictEqual( y, 1.0, 'returns expected value' );
t.end();
});

Expand Down
Loading