README.md (3616B)
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 > [Raised cosine][cosine-distribution] distribution [moment-generating function][mgf]. 24 25 <section class="intro"> 26 27 The [moment-generating function][mgf] for a [raised cosine][cosine-distribution] random variable is 28 29 <!-- <equation class="equation" label="eq:cosine_mgf" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{ \pi^{2} \sinh(st) }{ st(\pi^{2}+s^{2}t^{2}) } \,e^{\mu t}" alt="Moment-generating function for a raised cosine distribution."> --> 30 31 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{ \pi^{2} \sinh(st) }{ st(\pi^{2}+s^{2}t^{2}) } \,e^{\mu t}" data-equation="eq:cosine_mgf"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/cosine/mgf/docs/img/equation_cosine_mgf.svg" alt="Moment-generating function for a raised cosine distribution."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `μ` is the location parameter and `s > 0` is the scale parameter. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var mgf = require( '@stdlib/stats/base/dists/cosine/mgf' ); 50 ``` 51 52 #### mgf( t, mu, s ) 53 54 Evaluates the [moment-generating function][mgf] (MGF) for a [raised cosine][cosine-distribution] distribution with parameters `mu` (location parameter) and `s` (scale parameter). 55 56 ```javascript 57 var y = mgf( 2.0, 0.0, 3.0 ); 58 // returns ~7.234 59 60 y = mgf( 0.5, 0.0, 1.0 ); 61 // returns ~1.016 62 63 y = mgf( -1.0, 4.0, 2.0 ); 64 // returns ~0.024 65 ``` 66 67 If provided `NaN` as any argument, the function returns `NaN`. 68 69 ```javascript 70 var y = mgf( NaN, 0.0, 1.0 ); 71 // returns NaN 72 73 y = mgf( 0.0, NaN, 1.0 ); 74 // returns NaN 75 76 y = mgf( 0.0, 0.0, NaN ); 77 // returns NaN 78 ``` 79 80 If provided `s <= 0`, the function returns `NaN`. 81 82 ```javascript 83 var y = mgf( 0.5, 0.0, -1.0 ); 84 // returns NaN 85 86 y = mgf( 0.5, 0.0, 0.0 ); 87 // returns NaN 88 ``` 89 90 #### mgf.factory( mu, s ) 91 92 Returns a function for evaluating the [moment-generating function][mgf] of a [raised cosine][cosine-distribution] distribution with parameters `mu` (location parameter) and `s` (scale parameter). 93 94 ```javascript 95 var mymgf = mgf.factory( 10.0, 2.0 ); 96 97 var y = mymgf( 0.1 ); 98 // returns ~2.725 99 ``` 100 101 </section> 102 103 <!-- /.usage --> 104 105 <section class="examples"> 106 107 ## Examples 108 109 <!-- eslint no-undef: "error" --> 110 111 ```javascript 112 var randu = require( '@stdlib/random/base/randu' ); 113 var mgf = require( '@stdlib/stats/base/dists/cosine/mgf' ); 114 115 var mu; 116 var s; 117 var t; 118 var y; 119 var i; 120 121 for ( i = 0; i < 10; i++ ) { 122 t = randu() * 10.0; 123 mu = randu() * 10.0; 124 s = randu() * 10.0; 125 y = mgf( t, mu, s ); 126 console.log( 't: %d, µ: %d, s: %d, M_X(t;µ,s): %d', t.toFixed( 4 ), mu.toFixed( 4 ), s.toFixed( 4 ), y.toFixed( 4 ) ); 127 } 128 ``` 129 130 </section> 131 132 <!-- /.examples --> 133 134 <section class="links"> 135 136 [cosine-distribution]: https://en.wikipedia.org/wiki/Raised_cosine_distribution 137 138 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function 139 140 </section> 141 142 <!-- /.links -->