time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (4755B)


      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 > [Laplace][laplace-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 a [Laplace (double exponential)][laplace-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:laplace_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{\exp(\mu\,t)}{1-b^2\,t^2}\,\!\text{ for }|t|<1/b" alt="Moment-generating function (MGF) for a Laplace (double exponential) distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \frac{\exp(\mu\,t)}{1-b^2\,t^2}\,\!\text{ for }|t|&lt;1/b" data-equation="eq:laplace_mgf_function">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/laplace/mgf/docs/img/equation_laplace_mgf_function.svg" alt="Moment-generating function (MGF) for a Laplace (double exponential) distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `mu` is the location parameter and `b` is the scale parameter. For `|t| >= 1/b`, the [MGF][mgf] is undefined.
     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/laplace/mgf' );
     54 ```
     55 
     56 #### mgf( t, mu, b )
     57 
     58 Evaluates the [moment-generating function][mgf] (MGF) for a [Laplace][laplace-distribution] (double exponential) distribution with parameters `mu` (location) and `b` (scale).
     59 
     60 ```javascript
     61 var y = mgf( 0.5, 0.0, 1.0 );
     62 // returns ~1.333
     63 
     64 y = mgf( 0.0, 0.0, 1.0 );
     65 // returns 1.0
     66 
     67 y = mgf( -1.0, 4.0, 0.2 );
     68 // returns ~0.019
     69 ```
     70 
     71 If provided `NaN` as any argument, the function returns `NaN`.
     72 
     73 ```javascript
     74 var y = mgf( NaN, 0.0, 1.0 );
     75 // returns NaN
     76 
     77 y = mgf( 0.0, NaN, 1.0 );
     78 // returns NaN
     79 
     80 y = mgf( 0.0, 0.0, NaN );
     81 // returns NaN
     82 ```
     83 
     84 If `t` is not inside the interval `(-1/b, 1/b)`, the function returns `NaN`.
     85 
     86 ```javascript
     87 var y = mgf( 1.0, 0.0, 2.0 );
     88 // returns NaN
     89 
     90 y = mgf( -0.5, 0.0, 4.0 );
     91 // returns NaN
     92 ```
     93 
     94 If provided `b <= 0`, the function returns `NaN`.
     95 
     96 ```javascript
     97 var y = mgf( 2.0, 0.0, 0.0 );
     98 // returns NaN
     99 
    100 y = mgf( 2.0, 0.0, -1.0 );
    101 // returns NaN
    102 ```
    103 
    104 #### mgf.factory( mu, b )
    105 
    106 Returns a function for evaluating the [moment-generating function][mgf] (MGF) of a [Laplace][laplace-distribution] (double exponential) distribution with parameters `mu` and `b`.
    107 
    108 ```javascript
    109 var mymgf = mgf.factory( 4.0, 2.0 );
    110 
    111 var y = mymgf( 0.2 );
    112 // returns ~2.649
    113 
    114 y = mymgf( 0.4 );
    115 // returns ~13.758
    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 mgf = require( '@stdlib/stats/base/dists/laplace/mgf' );
    141 
    142 var mu;
    143 var b;
    144 var t;
    145 var y;
    146 var i;
    147 
    148 for ( i = 0; i < 10; i++ ) {
    149     t = randu();
    150     mu = (randu() * 10.0) - 5.0;
    151     b = randu() * 20.0;
    152     y = mgf( t, mu, b );
    153     console.log( 't: %d, µ: %d, b: %d, M_X(t;µ,b): %d', t.toFixed( 4 ), mu.toFixed( 4 ), b.toFixed( 4 ), y.toFixed( 4 ) );
    154 }
    155 ```
    156 
    157 </section>
    158 
    159 <!-- /.examples -->
    160 
    161 <!-- 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. -->
    162 
    163 <section class="references">
    164 
    165 </section>
    166 
    167 <!-- /.references -->
    168 
    169 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    170 
    171 <section class="links">
    172 
    173 [laplace-distribution]: https://en.wikipedia.org/wiki/Laplace_distribution
    174 
    175 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function
    176 
    177 </section>
    178 
    179 <!-- /.links -->