Skip to content

stdlib-js/stats-base-dists-logistic-mgf

 
 

Repository files navigation

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

Moment-Generating Function

NPM version Build Status Coverage Status

Logistic distribution moment-generating function (MGF).

The moment-generating function for a logistic random variable is

$$M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = e^{\mu t}\mathop{\mathrm{B}}(1-st, 1+st)$$

for st ∈ (-1,1), where mu is the location parameter and s is the scale parameter. In above equation, B denotes the Beta function. For st outside the interval (-1,1), the function is not defined.

Usage

To use in Observable,

mgf = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/stats-base-dists-logistic-mgf@umd/browser.js' )

To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:

var mgf = require( 'path/to/vendor/umd/stats-base-dists-logistic-mgf/index.js' )

To include the bundle in a webpage,

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/stats-base-dists-logistic-mgf@umd/browser.js"></script>

If no recognized module system is present, access bundle contents via the global scope:

<script type="text/javascript"> (function () { window.mgf; })(); </script>

mgf( t, mu, s )

Evaluates the logarithm of the moment-generating function (MGF) for a logistic distribution with parameters mu (location parameter) and s (scale parameter).

var y = mgf( 0.9, 0.0, 1.0 ); // returns ~9.15 y = mgf( 0.1, 4.0, 4.0 ); // returns ~1.971 y = mgf( -0.2, 4.0, 4.0 ); // returns ~1.921

If 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 NaN

If provided s < 0 or abs( s * t ) > 1, the function returns NaN.

var y = mgf( 0.5, 0.0, -1.0 ); // returns NaN y = mgf( 0.5, 0.0, 4.0 ); // returns NaN

mgf.factory( mu, s )

Returns a function for evaluating the moment-generating function (MGF) of a logistic distribution with parameters mu (location parameter) and s (scale parameter).

var mymgf = mgf.factory( 10.0, 0.5 ); var y = mymgf( 0.5 ); // returns ~164.846 y = mymgf( 2.0 ); // returns Infinity

Examples

<!DOCTYPE html> <html lang="en"> <body> <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/random-array-uniform@umd/browser.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/console-log-each-map@umd/browser.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/stats-base-dists-logistic-mgf@umd/browser.js"></script> <script type="text/javascript"> (function () { var opts = { 'dtype': 'float64' }; var t = uniform( 10, 0.0, 1.0, opts ); var mu = uniform( 10, -5.0, 5.0, opts ); var s = uniform( 10, 0.0, 2.0, opts ); logEachMap( 't: %0.4f, µ: %0.4f, s: %0.4f, M_X(t;µ,s): %0.4f', t, mu, s, mgf ); })(); </script> </body> </html>

C APIs

Usage

#include "stdlib/stats/base/dists/logistic/mgf.h"

stdlib_base_dists_logistic_mgf( t, mu, s )

Evaluates the logarithm of the moment-generating function (MGF) for a logistic distribution with parameters mu (location parameter) and s (scale parameter).

double out = stdlib_base_dists_logistic_mgf( 0.9, 0.0, 1.0 ); // returns ~9.15

The function accepts the following arguments:

  • t: [in] double input value.
  • mu: [in] double location parameter.
  • s: [in] double scale parameter.
double stdlib_base_dists_logistic_mgf( const double t, const double mu, const double s );

Examples

#include "stdlib/stats/base/dists/logistic/mgf.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 < 25; i++ ) { mu = random_uniform( -5.0, 5.0 ); s = random_uniform( 0.0, 20.0 ); t = random_uniform( 0.0, 10.0 ); y = stdlib_base_dists_logistic_mgf( t, mu, s ); printf( "t: %lf, µ: %lf, s: %lf, M_X(t;µ,s): %lf\n", t, mu, s, y ); } }

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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2025. The Stdlib Authors.