README.md (4779B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 > [Erlang][erlang-distribution] 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 an [Erlang][erlang-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:erlang_mgf" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \left(1 \,-\, \frac{t}{\lambda}\right)^{-k}" alt="Moment-generating function (MGF) for an Erlang distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \left(1 \,-\, \frac{t}{\lambda}\right)^{-k}" data-equation="eq:erlang_mgf"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/docs/img/equation_erlang_mgf.svg" alt="Moment-generating function (MGF) for an Erlang distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 for `t < lambda`, where the nonnegative integer `k` is the shape parameter and `lambda > 0` is the rate parameter of the distribution. In the case that `t >= lambda`, the MGF is not defined. 41 42 </section> 43 44 <!-- /.intro --> 45 46 <!-- Package usage documentation. --> 47 48 <section class="usage"> 49 50 ## Usage 51 52 ```javascript 53 var mgf = require( '@stdlib/stats/base/dists/erlang/mgf' ); 54 ``` 55 56 #### mgf( t, k, lambda ) 57 58 Evaluates the [moment-generating function][mgf] (mgf) for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter). 59 60 ```javascript 61 var y = mgf( 0.3, 1, 1.0 ); 62 // returns ~1.429 63 64 y = mgf( 2.0, 2, 3.0 ); 65 // returns ~9.0 66 67 y = mgf( -1.0, 2, 2.0 ); 68 // returns ~0.444 69 ``` 70 71 If provided `NaN` as any argument, the function returns `NaN`. 72 73 ```javascript 74 var y = mgf( NaN, 1, 1.0 ); 75 // returns NaN 76 77 y = mgf( 0.0, NaN, 1.0 ); 78 // returns NaN 79 80 y = mgf( 0.0, 1, NaN ); 81 // returns NaN 82 ``` 83 84 If not provided a nonnegative integer for `k`, the function returns `NaN`. 85 86 ```javascript 87 var y = mgf( 0.2, -2, 0.5 ); 88 // returns NaN 89 90 y = mgf( 0.2, 0.5, 0.5 ); 91 // returns NaN 92 ``` 93 94 If provided `lambda <= 0`, the function returns `NaN`. 95 96 ```javascript 97 var y = mgf( 0.2, 1, 0.0 ); 98 // returns NaN 99 100 y = mgf( 0.2, 1, -5.0 ); 101 // returns NaN 102 ``` 103 104 #### mgf.factory( k, lambda ) 105 106 Returns a function for evaluating the [moment-generating function][mgf] for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter). 107 108 ```javascript 109 var myMGF = mgf.factory( 2, 0.5 ); 110 111 var y = myMGF( 0.2 ); 112 // returns ~2.778 113 114 y = myMGF( -0.5 ); 115 // returns 0.25 116 ``` 117 118 </section> 119 120 <!-- /.usage --> 121 122 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 123 124 <section class="notes"> 125 126 </section> 127 128 <!-- /.notes --> 129 130 <!-- Package usage examples. --> 131 132 <section class="examples"> 133 134 ## Examples 135 136 <!-- eslint no-undef: "error" --> 137 138 ```javascript 139 var randu = require( '@stdlib/random/base/randu' ); 140 var round = require( '@stdlib/math/base/special/round' ); 141 var mgf = require( '@stdlib/stats/base/dists/erlang/mgf' ); 142 143 var lambda; 144 var k; 145 var t; 146 var y; 147 var i; 148 149 for ( i = 0; i < 10; i++ ) { 150 k = round( randu() * 10.0 ); 151 lambda = randu() * 10.0; 152 t = randu() * lambda; 153 y = mgf( t, k, lambda ); 154 console.log( 't: %d, k: %d, λ: %d, M_X(t;k,λ): %d', t.toFixed( 4 ), k, lambda.toFixed( 4 ), y.toFixed( 4 ) ); 155 } 156 ``` 157 158 </section> 159 160 <!-- /.examples --> 161 162 <!-- 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. --> 163 164 <section class="references"> 165 166 </section> 167 168 <!-- /.references --> 169 170 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 171 172 <section class="links"> 173 174 [erlang-distribution]: https://en.wikipedia.org/wiki/Erlang_distribution 175 176 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function 177 178 </section> 179 180 <!-- /.links -->