time-to-botec

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

README.md (4971B)


      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 > [Triangular][triangular-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 [triangular][triangular-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:triangular_mgf_function" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = 2\frac{(b\!-\!c)e^{at}\!-\!(b\!-\!a)e^{ct}\!+\!(c\!-\!a)e^{bt}} {(b-a)(c-a)(b-c)t^2}" alt="Moment-generating function (MGF) for a triangular distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = 2\frac{(b\!-\!c)e^{at}\!-\!(b\!-\!a)e^{ct}\!+\!(c\!-\!a)e^{bt}} {(b-a)(c-a)(b-c)t^2}" data-equation="eq:triangular_mgf_function">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/docs/img/equation_triangular_mgf_function.svg" alt="Moment-generating function (MGF) for a triangular distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `a` is the lower limit, `b` is the upper limit, and `c` is the mode of the distribution. The parameters must satisfy `b > a` and `a <= b <= c`.
     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/triangular/mgf' );
     54 ```
     55 
     56 #### mgf( t, a, b, c )
     57 
     58 Evaluates the [moment-generating function][mgf] (MGF) for a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit), and `c` (mode).
     59 
     60 ```javascript
     61 var y = mgf( 0.5, -1.0, 1.0, 0.0 );
     62 // returns ~1.021
     63 
     64 y = mgf( 0.5, -1.0, 1.0, 0.5 );
     65 // returns ~1.111
     66 
     67 y = mgf( -0.3, -20.0, 0.0, -2.0 );
     68 // returns ~24.334
     69 
     70 y = mgf( -2.0, -1.0, 1.0, 0.0 );
     71 // returns ~1.381
     72 ```
     73 
     74 If provided `NaN` as any argument, the function returns `NaN`.
     75 
     76 ```javascript
     77 var y = mgf( NaN, 0.0, 1.0, 0.5 );
     78 // returns NaN
     79 
     80 y = mgf( 0.0, NaN, 1.0, 0.5 );
     81 // returns NaN
     82 
     83 y = mgf( 0.0, 0.0, NaN, 0.5 );
     84 // returns NaN
     85 
     86 y = mgf( 2.0, 1.0, 0.0, NaN );
     87 // returns NaN
     88 ```
     89 
     90 If provided parameters not satisfying `a <= c <= b`, the function returns `NaN`.
     91 
     92 ```javascript
     93 var y = mgf( 2.0, 1.0, 0.0, 1.5 );
     94 // returns NaN
     95 
     96 y = mgf( 2.0, 1.0, 0.0, -1.0 );
     97 // returns NaN
     98 
     99 y = mgf( 2.0, 0.0, -1.0, 0.5 );
    100 // returns NaN
    101 ```
    102 
    103 #### mgf.factory( a, b, c )
    104 
    105 Returns a function for evaluating the [moment-generating function][mgf] of a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit), and `c` (mode).
    106 
    107 ```javascript
    108 var mymgf = mgf.factory( 0.0, 2.0, 1.0 );
    109 
    110 var y = mymgf( -1.0 );
    111 // returns ~0.3996
    112 
    113 y = mymgf( 2.0 );
    114 // returns ~10.205
    115 ```
    116 
    117 </section>
    118 
    119 <!-- /.usage -->
    120 
    121 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    122 
    123 <section class="notes">
    124 
    125 </section>
    126 
    127 <!-- /.notes -->
    128 
    129 <!-- Package usage examples. -->
    130 
    131 <section class="examples">
    132 
    133 ## Examples
    134 
    135 <!-- eslint no-undef: "error" -->
    136 
    137 ```javascript
    138 var randu = require( '@stdlib/random/base/randu' );
    139 var mgf = require( '@stdlib/stats/base/dists/triangular/mgf' );
    140 
    141 var a;
    142 var b;
    143 var c;
    144 var t;
    145 var v;
    146 var i;
    147 
    148 for ( i = 0; i < 10; i++ ) {
    149     t = randu() * 5.0;
    150     a = randu() * 10.0;
    151     b = a + (randu() * 40.0);
    152     c = a + (( b - a ) * randu());
    153     v = mgf( t, a, b, c );
    154     console.log( 't: %d, a: %d, b: %d, c: %d, M_X(t;a,b,c): %d', t.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), c.toFixed( 4 ), v.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 [triangular-distribution]: https://en.wikipedia.org/wiki/Triangular_distribution
    175 
    176 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function
    177 
    178 </section>
    179 
    180 <!-- /.links -->