|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Moment-Generating Function |
| 22 | + |
| 23 | +> Planck (discrete exponential) distribution moment-generating function (MGF). |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +The [moment-generating function][mgf] for a Planck random variable is |
| 30 | + |
| 31 | +<!-- <equation class="equation" label="eq:planck_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{1 - e^{-\lambda}}{1 - e^{t - \lambda}}" alt="Moment-generating function (MGF) for the Planck distribution."> --> |
| 32 | + |
| 33 | +```math |
| 34 | +M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{1 - e^{-\lambda}}{1 - e^{t - \lambda}} |
| 35 | +``` |
| 36 | + |
| 37 | +<!-- </equation> --> |
| 38 | + |
| 39 | +where `λ` is the shape parameter. |
| 40 | + |
| 41 | +</section> |
| 42 | + |
| 43 | +<!-- /.intro --> |
| 44 | + |
| 45 | +<!-- Package usage documentation. --> |
| 46 | + |
| 47 | +<section class="usage"> |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +```javascript |
| 52 | +var mgf = require( '@stdlib/stats/base/dists/planck/mgf' ); |
| 53 | +``` |
| 54 | + |
| 55 | +#### mgf( t, lambda ) |
| 56 | + |
| 57 | +Evaluates the moment-generating function ([MGF][mgf]) of a Planck (discrete exponential) distribution with shape parameter `lambda`. |
| 58 | + |
| 59 | +```javascript |
| 60 | +var y = mgf( 0.2, 0.5 ); |
| 61 | +// returns ~1.5181 |
| 62 | + |
| 63 | +y = mgf( 0.4, 1.5 ); |
| 64 | +// returns ~1.1645 |
| 65 | +``` |
| 66 | + |
| 67 | +If provided `NaN` as any argument, the function returns `NaN`. |
| 68 | + |
| 69 | +```javascript |
| 70 | +var y = mgf( NaN, 0.0 ); |
| 71 | +// returns NaN |
| 72 | + |
| 73 | +y = mgf( 0.0, NaN ); |
| 74 | +// returns NaN |
| 75 | +``` |
| 76 | + |
| 77 | +If provided a shape parameter `lambda` which is nonpositive, the function returns `NaN`. |
| 78 | + |
| 79 | +```javascript |
| 80 | +var y = mgf( 2.0, -1.0 ); |
| 81 | +// returns NaN |
| 82 | +``` |
| 83 | + |
| 84 | +#### mgf.factory( lambda ) |
| 85 | + |
| 86 | +Returns a function for evaluating the [moment-generating function][mgf] of a Planck (discrete exponential) distribution with shape parameter `lambda`. |
| 87 | + |
| 88 | +```javascript |
| 89 | +var mymgf = mgf.factory( 0.8 ); |
| 90 | +var y = mymgf( -0.2 ); |
| 91 | +// returns ~0.8711 |
| 92 | +``` |
| 93 | + |
| 94 | +</section> |
| 95 | + |
| 96 | +<!-- /.usage --> |
| 97 | + |
| 98 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 99 | + |
| 100 | +<section class="notes"> |
| 101 | + |
| 102 | +</section> |
| 103 | + |
| 104 | +<!-- /.notes --> |
| 105 | + |
| 106 | +<!-- Package usage examples. --> |
| 107 | + |
| 108 | +<section class="examples"> |
| 109 | + |
| 110 | +## Examples |
| 111 | + |
| 112 | +<!-- eslint no-undef: "error" --> |
| 113 | + |
| 114 | +```javascript |
| 115 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 116 | +var mgf = require( '@stdlib/stats/base/dists/planck/mgf' ); |
| 117 | + |
| 118 | +var lambda = uniform( 10, 0.1, 5.0 ); |
| 119 | +var t = uniform( 10, 0.0, 10.0 ); |
| 120 | + |
| 121 | +var y; |
| 122 | +var i; |
| 123 | +for ( i = 0; i < lambda.length; i++ ) { |
| 124 | + y = mgf( t[ i ], lambda[ i ] ); |
| 125 | + console.log( 't: %d, λ: %d, M_X(t;λ): %d', t[ i ].toFixed( 4 ), lambda[ i ].toFixed( 4 ), y.toFixed( 4 ) ); |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +</section> |
| 130 | + |
| 131 | +<!-- /.examples --> |
| 132 | + |
| 133 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 134 | + |
| 135 | +<section class="references"> |
| 136 | + |
| 137 | +</section> |
| 138 | + |
| 139 | +<!-- /.references --> |
| 140 | + |
| 141 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 142 | + |
| 143 | +<section class="related"> |
| 144 | + |
| 145 | +</section> |
| 146 | + |
| 147 | +<!-- /.related --> |
| 148 | + |
| 149 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 150 | + |
| 151 | +<section class="links"> |
| 152 | + |
| 153 | +[mgf]: https://en.wikipedia.org/wiki/Moment-generating_function |
| 154 | + |
| 155 | +</section> |
| 156 | + |
| 157 | +<!-- /.links --> |
0 commit comments