@stdlib/stats-base-dists-cosine-mgf
v0.3.1
Published
Raised cosine distribution moment-generating function (MGF).
Readme
Moment-generating function
Raised cosine distribution moment-generating function.
The moment-generating function for a raised cosine random variable is
where μ is the location parameter and s > 0 is the scale parameter.
Installation
npm install @stdlib/stats-base-dists-cosine-mgfUsage
var mgf = require( '@stdlib/stats-base-dists-cosine-mgf' );mgf( t, mu, s )
Evaluates the moment-generating function (MGF) for a raised cosine distribution with parameters mu (location parameter) and s (scale parameter).
var y = mgf( 2.0, 0.0, 3.0 );
// returns ~7.234
y = mgf( 0.5, 0.0, 1.0 );
// returns ~1.016
y = mgf( -1.0, 4.0, 2.0 );
// returns ~0.024If provided NaN as any argument, the function returns NaN.
var y = mgf( NaN, 0.0, 1.0 );
// returns NaN
y = mgf( 0.0, NaN, 1.0 );
// returns NaN
y = mgf( 0.0, 0.0, NaN );
// returns NaNIf provided s <= 0, the function returns NaN.
var y = mgf( 0.5, 0.0, -1.0 );
// returns NaN
y = mgf( 0.5, 0.0, 0.0 );
// returns NaNmgf.factory( mu, s )
Returns a function for evaluating the moment-generating function of a raised cosine distribution with parameters mu (location parameter) and s (scale parameter).
var mymgf = mgf.factory( 10.0, 2.0 );
var y = mymgf( 0.1 );
// returns ~2.725Examples
var uniform = require( '@stdlib/random-array-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var mgf = require( '@stdlib/stats-base-dists-cosine-mgf' );
var opts = {
'dtype': 'float64'
};
var t = uniform( 10, 0.0, 10.0, opts );
var mu = uniform( 10, 0.0, 10.0, opts );
var s = uniform( 10, 0.0, 10.0, opts );
logEachMap( 'x: %0.4f, µ: %0.4f, s: %0.4f, M_X(t;µ,s): %0.4f', t, mu, s, mgf );C APIs
Usage
#include "stdlib/stats/base/dists/cosine/mgf.h"stdlib_base_dists_cosine_mgf( t, mu, s )
Returns the moment-generating function (MGF) for a raised cosine distribution with parameters mu (location parameter) and s (scale parameter).
double out = stdlib_base_dists_cosine_mgf( 0.5, 0.0, 1.0 );
// returns ~1.016The function accepts the following arguments:
- t:
[in] doubleinput value. - mu:
[in] doublelocation parameter. - s:
[in] doublescale parameter.
double stdlib_base_dists_cosine_mgf( const double t, const double mu, const double s );Examples
#include "stdlib/stats/base/dists/cosine/mgf.h"
#include "stdlib/constants/float64/eps.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 mu;
double s;
double t;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
t = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 );
mu = random_uniform( -50.0, 50.0 );
s = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_cosine_mgf( t, mu, s );
printf( "t: %lf, µ: %lf, s: %lf, M_X(t;µ,s): %lf\n", t, mu, s, y );
}
return 0;
}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.
