time-to-botec

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

README.md (3916B)


      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 > [Lognormal][lognormal-distribution] distribution [cumulative distribution function][cdf].
     24 
     25 <section class="intro">
     26 
     27 The [cumulative distribution function][cdf] for a [lognormal][lognormal-distribution] random variable is
     28 
     29 <!-- <equation class="equation" label="eq:cdf" align="center" raw="F(x;\mu,\sigma)=\frac12 + \frac12\,\operatorname{erf}\left[\frac{\ln x-\mu}{\sqrt{2}\sigma}\right]" alt="Cumulative distribution function for a lognormal distribution."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="F(x;\mu,\sigma)=\frac12 + \frac12\,\operatorname{erf}\left[\frac{\ln x-\mu}{\sqrt{2}\sigma}\right]" data-equation="eq:cdf">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/lognormal/cdf/docs/img/equation_cdf.svg" alt="Cumulative distribution function for a lognormal distribution.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 where `mu` is the location parameter and `sigma > 0` is the scale parameter. According to the definition, the _natural logarithm_ of a random variable from a
     39 [lognormal distribution][lognormal-distribution] follows a [normal distribution][normal-distribution].
     40 
     41 </section>
     42 
     43 <!-- /.intro -->
     44 
     45 <section class="usage">
     46 
     47 ## Usage
     48 
     49 ```javascript
     50 var cdf = require( '@stdlib/stats/base/dists/lognormal/cdf' );
     51 ```
     52 
     53 #### cdf( x, mu, sigma )
     54 
     55 Evaluates the [cumulative distribution function][cdf] (CDF) for a [lognormal][lognormal-distribution] distribution with parameters `mu` (location parameter) and `sigma` (scale parameter).
     56 
     57 ```javascript
     58 var y = cdf( 2.0, 0.0, 1.0 );
     59 // returns ~0.756
     60 
     61 y = cdf( 5.0, 10.0, 3.0 );
     62 // returns ~0.003
     63 ```
     64 
     65 If provided `NaN` as any argument, the function returns `NaN`.
     66 
     67 ```javascript
     68 var y = cdf( NaN, 0.0, 1.0 );
     69 // returns NaN
     70 
     71 y = cdf( 0.0, NaN, 1.0 );
     72 // returns NaN
     73 
     74 y = cdf( 0.0, 0.0, NaN );
     75 // returns NaN
     76 ```
     77 
     78 If provided `sigma <= 0`, the function returns `NaN`.
     79 
     80 ```javascript
     81 var y = cdf( 2.0, 0.0, -1.0 );
     82 // returns NaN
     83 
     84 y = cdf( 2.0, 0.0, 0.0 );
     85 // returns NaN
     86 ```
     87 
     88 #### cdf.factory( mu, sigma )
     89 
     90 Returns a function for evaluating the [cumulative distribution function][cdf] of a [lognormal][lognormal-distribution] distribution with parameters `mu` (location parameter) and `sigma` (scale parameter).
     91 
     92 ```javascript
     93 var mycdf = cdf.factory( 3.0, 1.5 );
     94 
     95 var y = mycdf( 1.0 );
     96 // returns ~0.023
     97 
     98 y = mycdf( 4.0 );
     99 // returns ~0.141
    100 ```
    101 
    102 </section>
    103 
    104 <!-- /.usage -->
    105 
    106 <section class="examples">
    107 
    108 ## Examples
    109 
    110 <!-- eslint no-undef: "error" -->
    111 
    112 ```javascript
    113 var randu = require( '@stdlib/random/base/randu' );
    114 var cdf = require( '@stdlib/stats/base/dists/lognormal/cdf' );
    115 
    116 var sigma;
    117 var mu;
    118 var x;
    119 var y;
    120 var i;
    121 
    122 for ( i = 0; i < 10; i++ ) {
    123     x = randu() * 10.0;
    124     mu = (randu() * 10.0) - 5.0;
    125     sigma = randu() * 20.0;
    126     y = cdf( x, mu, sigma );
    127     console.log( 'x: %d, µ: %d, σ: %d, F(x;µ,σ): %d', x.toFixed( 4 ), mu.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) );
    128 }
    129 ```
    130 
    131 </section>
    132 
    133 <!-- /.examples -->
    134 
    135 <section class="links">
    136 
    137 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function
    138 
    139 [lognormal-distribution]: https://en.wikipedia.org/wiki/Lognormal_distribution
    140 
    141 [normal-distribution]: https://en.wikipedia.org/wiki/Normal_distribution
    142 
    143 </section>
    144 
    145 <!-- /.links -->