@stdlib/stats-base-dists-degenerate-mgf
v0.3.1
Published
Degenerate distribution moment-generating function (MGF).
Readme
Moment-Generating Function
Degenerate distribution moment-generating function (MGF).
The moment-generating function for a degenerate random variable is
where mu is the distribution mean.
Installation
npm install @stdlib/stats-base-dists-degenerate-mgfUsage
var mgf = require( '@stdlib/stats-base-dists-degenerate-mgf' );mgf( t, mu )
Evaluates the moment-generating function (MGF) of a degenerate distribution with parameter mu (mean).
var y = mgf( 1.0, 1.0 );
// returns ~2.718
y = mgf( 2.0, 3.0 );
// returns ~403.429If provided NaN for any argument, the function returns NaN.
var y = mgf( NaN, 0.0 );
// returns NaN
y = mgf( 0.0, NaN );
// returns NaNmgf.factory( mu )
Returns a function for evaluating the moment-generating function of a degenerate distribution with parameter mu (mean).
var mymgf = mgf.factory( 10.0 );
var y = mymgf( 0.1 );
// returns ~2.718Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var mgf = require( '@stdlib/stats-base-dists-degenerate-mgf' );
var opts = {
'dtype': 'float64'
};
var t = discreteUniform( 100, 0, 5, opts );
var mu = discreteUniform( 100, 0, 5, opts );
logEachMap( 'x: %0.4f, µ: %0.4f, M_X(t;µ): %0.4f', t, mu, mgf );C APIs
Usage
#include "stdlib/stats/base/dists/degenerate/mgf.h"stdlib_base_dists_degenerate_mgf( t, mu )
Evaluates the moment-generating function (MGF) of a degenerate distribution with parameter mu (mean).
double out = stdlib_base_dists_degenerate_mgf( 1.0, 1.0 );
// returns ~2.718The function accepts the following arguments:
- t:
[in] doubleinput value. - mu:
[in] doublevalue at which to center the distribution.
double stdlib_base_dists_degenerate_mgf( const double t, const double mu );Examples
#include "stdlib/stats/base/dists/degenerate/mgf.h"
#include "stdlib/math/base/special/round.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v * ( max - min ) );
}
int main( void ) {
double result;
double mu;
double t;
int i;
for ( i = 0; i < 10; i++ ) {
t = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
mu = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
result = stdlib_base_dists_degenerate_mgf( t, mu );
printf( "t: %lf, µ: %lf, M_X(t;µ): %lf\n", t, mu, result );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
