time-to-botec

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

README.md (4680B)


      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 > [Uniform][uniform-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 [continuous uniform][uniform-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:uniform_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right]= \begin{cases} \frac{\mathrm{e}^{tb}-\mathrm{e}^{ta}}{t(b-a)} & \text{for } t \neq 0 \\ 1 & \text{for } t = 0 \end{cases}" alt="Moment-generating function (MGF) for a uniform distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right]= \begin{cases} \frac{\mathrm{e}^{tb}-\mathrm{e}^{ta}}{t(b-a)} &amp; \text{for } t \neq 0 \\ 1 &amp; \text{for } t = 0 \end{cases}" data-equation="eq:uniform_mgf_function">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/docs/img/equation_uniform_mgf_function.svg" alt="Moment-generating function (MGF) for a uniform distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `a` is the minimum support and `b` is the maximum support. The parameters must satisfy `a < b`.
     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/uniform/mgf' );
     54 ```
     55 
     56 #### mgf( t, a, b )
     57 
     58 Evaluates the [moment-generating function][mgf] (MGF) for a [continuous uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
     59 
     60 ```javascript
     61 var y = mgf( 2.0, 0.0, 4.0 );
     62 // returns ~372.495
     63 
     64 y = mgf( -0.2, 0.0, 4.0 );
     65 // returns ~0.688
     66 
     67 y = mgf( 2.0, 0.0, 1.0 );
     68 // returns ~3.195
     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 provided `a >= b`, the function returns `NaN`.
     85 
     86 ```javascript
     87 var y = mgf( 0.5, 3.0, 2.0 );
     88 // returns NaN
     89 
     90 y = mgf( 0.5, 3.0, 3.0 );
     91 // returns NaN
     92 ```
     93 
     94 #### mgf.factory( a, b )
     95 
     96 Returns a function for evaluating the [moment-generating function][mgf] (MGF) of a [continuous uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
     97 
     98 ```javascript
     99 var mymgf = mgf.factory( 6.0, 7.0 );
    100 var y = mymgf( 0.1 );
    101 // returns ~1.916
    102 
    103 y = mymgf( 1.1 );
    104 // returns ~1339.321
    105 ```
    106 
    107 </section>
    108 
    109 <!-- /.usage -->
    110 
    111 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    112 
    113 <section class="notes">
    114 
    115 </section>
    116 
    117 <!-- /.notes -->
    118 
    119 <!-- Package usage examples. -->
    120 
    121 <section class="examples">
    122 
    123 ## Examples
    124 
    125 <!-- eslint no-undef: "error" -->
    126 
    127 ```javascript
    128 var randu = require( '@stdlib/random/base/randu' );
    129 var mgf = require( '@stdlib/stats/base/dists/uniform/mgf' );
    130 
    131 var a;
    132 var b;
    133 var t;
    134 var v;
    135 var i;
    136 
    137 for ( i = 0; i < 10; i++ ) {
    138     t = randu();
    139     a = randu() * 5.0;
    140     b = a + (randu() * 5.0);
    141     v = mgf( t, a, b );
    142     console.log( 't: %d, a: %d, b: %d, M_X(t;a,b): %d', t.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), v.toFixed( 4 ) );
    143 }
    144 ```
    145 
    146 </section>
    147 
    148 <!-- /.examples -->
    149 
    150 <!-- 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. -->
    151 
    152 <section class="references">
    153 
    154 </section>
    155 
    156 <!-- /.references -->
    157 
    158 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    159 
    160 <section class="links">
    161 
    162 [uniform-distribution]: https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
    163 
    164 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function
    165 
    166 </section>
    167 
    168 <!-- /.links -->