time-to-botec

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

README.md (4826B)


      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 > [Weibull][weibull-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 [Weibull][weibull-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:weibull_mgf" align="center" raw="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \sum_{n=0}^\infty \frac{t^n\lambda^n}{n!}\Gamma\left(1+\frac{n}{k}\right)" alt="Moment-generating function (MGF) for a Weibull distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \sum_{n=0}^\infty \frac{t^n\lambda^n}{n!}\Gamma\left(1+\frac{n}{k}\right)" data-equation="eq:weibull_mgf">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/weibull/mgf/docs/img/equation_weibull_mgf.svg" alt="Moment-generating function (MGF) for a Weibull distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `lambda > 0` is the scale paramater and `k > 0` is the shape parameter.
     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/weibull/mgf' );
     54 ```
     55 
     56 #### mgf( t, k, lambda )
     57 
     58 Evaluates the [moment-generating function][mgf] (MGF) for a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
     59 
     60 ```javascript
     61 var y = mgf( 1.0, 1.0, 0.5);
     62 // returns ~2.0
     63 
     64 y = mgf( -1.0, 4.0, 4.0 );
     65 // returns ~0.019
     66 ```
     67 
     68 If provided `NaN` as any argument, the function returns `NaN`.
     69 
     70 ```javascript
     71 var y = mgf( NaN, 1.0, 1.0 );
     72 // returns NaN
     73 
     74 y = mgf( 0.0, NaN, 1.0 );
     75 // returns NaN
     76 
     77 y = mgf( 0.0, 1.0, NaN );
     78 // returns NaN
     79 ```
     80 
     81 If provided `k <= 0`, the function returns `NaN`.
     82 
     83 ```javascript
     84 var y = mgf( 0.2, -1.0, 0.5 );
     85 // returns NaN
     86 
     87 y = mgf( 0.2, 0.0, 0.5 );
     88 // returns NaN
     89 ```
     90 
     91 If provided `lambda <= 0`, the function returns `NaN`.
     92 
     93 ```javascript
     94 var y = mgf( 0.2, 0.5, -1.0 );
     95 // returns NaN
     96 
     97 y = mgf( 0.2, 0.5, 0.0 );
     98 // returns NaN
     99 ```
    100 
    101 #### mgf.factory( k, lambda )
    102 
    103 Returns a function for evaluating the [moment-generating function][mgf] of a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
    104 
    105 ```javascript
    106 var myMGF = mgf.factory( 8.0, 10.0 );
    107 
    108 var y = myMGF( 0.8 );
    109 // returns ~3150.149
    110 
    111 y = myMGF( 0.08 );
    112 // returns ~2.137
    113 ```
    114 
    115 </section>
    116 
    117 <!-- /.usage -->
    118 
    119 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    120 
    121 <section class="notes">
    122 
    123 </section>
    124 
    125 <!-- /.notes -->
    126 
    127 <!-- Package usage examples. -->
    128 
    129 <section class="examples">
    130 
    131 ## Examples
    132 
    133 <!-- eslint no-undef: "error" -->
    134 
    135 ```javascript
    136 var randu = require( '@stdlib/random/base/randu' );
    137 var EPS = require( '@stdlib/constants/float64/eps' );
    138 var mgf = require( '@stdlib/stats/base/dists/weibull/mgf' );
    139 
    140 var lambda;
    141 var k;
    142 var t;
    143 var y;
    144 var i;
    145 
    146 for ( i = 0; i < 10; i++ ) {
    147     t = randu() * 5.0;
    148     lambda = ( randu() * 10.0 ) + EPS;
    149     k = ( randu() * 10.0 ) + EPS;
    150     y = mgf( t, lambda, k );
    151     console.log( 'x: %d, k: %d, λ: %d, M_X(t;k,λ): %d', t.toFixed( 4 ), k.toFixed( 4 ), lambda.toFixed( 4 ), y.toFixed( 4 ) );
    152 }
    153 ```
    154 
    155 </section>
    156 
    157 <!-- /.examples -->
    158 
    159 <!-- 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. -->
    160 
    161 <section class="references">
    162 
    163 </section>
    164 
    165 <!-- /.references -->
    166 
    167 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    168 
    169 <section class="links">
    170 
    171 [weibull-distribution]: https://en.wikipedia.org/wiki/Weibull_distribution
    172 
    173 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function
    174 
    175 [shape]: https://en.wikipedia.org/wiki/Shape_parameter
    176 
    177 [scale]: https://en.wikipedia.org/wiki/Scale_parameter
    178 
    179 </section>
    180 
    181 <!-- /.links -->