time-to-botec

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

README.md (4424B)


      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 # Cumulative Distribution Function
     22 
     23 > [Erlang][erlang-distribution] distribution [cumulative distribution function][cdf].
     24 
     25 <section class="intro">
     26 
     27 The [cumulative distribution function][cdf] for a [Erlang][erlang-distribution] random variable is
     28 
     29 <!-- <equation class="equation" label="eq:erlang_cdf" align="center" raw="F(x; k,\lambda) = 1 - \sum_{n=0}^{k-1}\frac{1}{n!}e^{-\lambda x}(\lambda x)^n" alt="Cumulative distribution function for a Erlang distribution."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="F(x; k,\lambda) = 1 - \sum_{n=0}^{k-1}\frac{1}{n!}e^{-\lambda x}(\lambda x)^n" data-equation="eq:erlang_cdf">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/erlang/cdf/docs/img/equation_erlang_cdf.svg" alt="Cumulative distribution function for a Erlang distribution.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 where `k` is the shape parameter and `lambda` is the rate parameter. The [Erlang][erlang-distribution] distribution is a special case of the gamma distribution, as `k` is constrained to the natural numbers.
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var cdf = require( '@stdlib/stats/base/dists/erlang/cdf' );
     50 ```
     51 
     52 #### cdf( x, k, lambda )
     53 
     54 Evaluates the [cumulative distribution function][cdf] (CDF) for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter).
     55 
     56 ```javascript
     57 var y = cdf( 2.0, 1, 1.0 );
     58 // returns ~0.865
     59 
     60 y = cdf( 2.0, 3, 1.0 );
     61 // returns ~0.323
     62 
     63 y = cdf( -1.0, 2, 2.0 );
     64 // returns 0.0
     65 
     66 y = cdf( -Infinity, 4, 2.0 );
     67 // returns 0.0
     68 
     69 y = cdf( +Infinity, 4, 2.0 );
     70 // returns 1.0
     71 ```
     72 
     73 If provided `NaN` as any argument, the function returns `NaN`.
     74 
     75 ```javascript
     76 var y = cdf( NaN, 1, 1.0 );
     77 // returns NaN
     78 
     79 y = cdf( 0.0, NaN, 1.0 );
     80 // returns NaN
     81 
     82 y = cdf( 0.0, 1, NaN );
     83 // returns NaN
     84 ```
     85 
     86 If not provided a nonnegative integer for `k`, the function returns `NaN`.
     87 
     88 ```javascript
     89 var y = cdf( 2.0, -2, 0.5 );
     90 // returns NaN
     91 
     92 y = cdf( 2.0, 0.5, 0.5 );
     93 // returns NaN
     94 ```
     95 
     96 If provided `k = 0`, the function evaluates the [CDF][cdf] of a [degenerate distribution][degenerate-distribution] centered at `0`.
     97 
     98 ```javascript
     99 var y = cdf( 2.0, 0.0, 2.0 );
    100 // returns 1.0
    101 
    102 y = cdf( -2.0, 0.0, 2.0 );
    103 // returns 0.0
    104 
    105 y = cdf( 0.0, 0.0, 2.0 );
    106 // returns 1.0
    107 ```
    108 
    109 If provided `lambda <= 0`, the function returns `NaN`.
    110 
    111 ```javascript
    112 var y = cdf( 2.0, 1, 0.0 );
    113 // returns NaN
    114 
    115 y = cdf( 2.0, 1, -5.0 );
    116 // returns NaN
    117 ```
    118 
    119 #### cdf.factory( k, lambda )
    120 
    121 Returns a function for evaluating the [cumulative distribution function][cdf] for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter).
    122 
    123 ```javascript
    124 var mycdf = cdf.factory( 2, 0.5 );
    125 
    126 var y = mycdf( 6.0 );
    127 // returns ~0.801
    128 
    129 y = mycdf( 2.0 );
    130 // returns ~0.264
    131 ```
    132 
    133 </section>
    134 
    135 <!-- /.usage -->
    136 
    137 <section class="examples">
    138 
    139 ## Examples
    140 
    141 <!-- eslint no-undef: "error" -->
    142 
    143 ```javascript
    144 var randu = require( '@stdlib/random/base/randu' );
    145 var round = require( '@stdlib/math/base/special/round' );
    146 var cdf = require( '@stdlib/stats/base/dists/erlang/cdf' );
    147 
    148 var lambda;
    149 var k;
    150 var x;
    151 var y;
    152 var i;
    153 
    154 for ( i = 0; i < 20; i++ ) {
    155     x = randu() * 10.0;
    156     k = round( randu() * 10.0 );
    157     lambda = randu() * 5.0;
    158     y = cdf( x, k, lambda );
    159     console.log( 'x: %d, k: %d, λ: %d, F(x;k,λ): %d', x.toFixed( 4 ), k, lambda.toFixed( 4 ), y.toFixed( 4 ) );
    160 }
    161 ```
    162 
    163 </section>
    164 
    165 <!-- /.examples -->
    166 
    167 <section class="links">
    168 
    169 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function
    170 
    171 [degenerate-distribution]: https://en.wikipedia.org/wiki/Degenerate_distribution
    172 
    173 [erlang-distribution]: https://en.wikipedia.org/wiki/Erlang_distribution
    174 
    175 </section>
    176 
    177 <!-- /.links -->