time-to-botec

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

README.md (4366B)


      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 # Logarithm of Cumulative Distribution Function
     22 
     23 > [Weibull][weibull-distribution] distribution logarithm of [cumulative distribution function][cdf].
     24 
     25 <section class="intro">
     26 
     27 The [cumulative distribution function][cdf] for a [Weibull][weibull-distribution] random variable is
     28 
     29 <!-- <equation class="equation" label="eq:weibull_cdf" align="center" raw="F(x;\lambda, k) =\begin{cases}1- e^{-(x/\lambda)^k} & x\geq0\\ 0 & x<0\end{cases}" alt="Cumulative distribution function for a Weibull distribution."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="F(x;\lambda, k) =\begin{cases}1- e^{-(x/\lambda)^k} &amp; x\geq0\\ 0 &amp; x&lt;0\end{cases}" data-equation="eq:weibull_cdf">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e2f64e6ec3d2c31743d067b73ccd26699c52be67/lib/node_modules/@stdlib/stats/base/dists/weibull/logcdf/docs/img/equation_weibull_cdf.svg" alt="Cumulative distribution function for a Weibull distribution.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 where `lambda > 0` is the [shape parameter][shape] and `k > 0` is the [scale parameter][scale].
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var logcdf = require( '@stdlib/stats/base/dists/weibull/logcdf' );
     50 ```
     51 
     52 #### logcdf( x, k, lambda )
     53 
     54 Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
     55 
     56 ```javascript
     57 var y = logcdf( 2.0, 1.0, 0.5 );
     58 // returns ~-0.018
     59 
     60 y = logcdf( 0.0, 0.5, 1.0 );
     61 // returns -Infinity
     62 
     63 y = logcdf( -Infinity, 4.0, 2.0 );
     64 // returns -Infinity
     65 
     66 y = logcdf( +Infinity, 4.0, 2.0 );
     67 // returns 0.0
     68 ```
     69 
     70 If provided `NaN` as any argument, the function returns `NaN`.
     71 
     72 ```javascript
     73 var y = logcdf( NaN, 1.0, 1.0 );
     74 // returns NaN
     75 
     76 y = logcdf( 0.0, NaN, 1.0 );
     77 // returns NaN
     78 
     79 y = logcdf( 0.0, 1.0, NaN );
     80 // returns NaN
     81 ```
     82 
     83 If provided `k <= 0`, the function returns `NaN`.
     84 
     85 ```javascript
     86 var y = logcdf( 2.0, -1.0, 0.5 );
     87 // returns NaN
     88 
     89 y = logcdf( 2.0, 0.0, 0.5 );
     90 // returns NaN
     91 ```
     92 
     93 If provided `lambda <= 0`, the function returns `NaN`.
     94 
     95 ```javascript
     96 var y = logcdf( 2.0, 0.5, -1.0 );
     97 // returns NaN
     98 
     99 y = logcdf( 2.0, 0.5, 0.0 );
    100 // returns NaN
    101 ```
    102 
    103 #### logcdf.factory( k, lambda )
    104 
    105 Returns a function for evaluating the [cumulative distribution function][cdf] of a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`. 
    106 
    107 ```javascript
    108 var mylogcdf = logcdf.factory( 2.0, 10.0 );
    109 
    110 var y = mylogcdf( 10.0 );
    111 // returns ~-0.459
    112 
    113 y = mylogcdf( 8.0 );
    114 // returns ~-0.749
    115 ```
    116 
    117 </section>
    118 
    119 <!-- /.usage -->
    120 
    121 <section class="notes">
    122 
    123 ## Notes
    124 
    125 -   In virtually all cases, using the `logpdf` or `logcdf` functions is preferable to manually computing the logarithm of the `pdf` or `cdf`, respectively, since the latter is prone to overflow and underflow.
    126 
    127 </section>
    128 
    129 <!-- /.notes -->
    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 logcdf = require( '@stdlib/stats/base/dists/weibull/logcdf' );
    140 
    141 var lambda;
    142 var k;
    143 var x;
    144 var y;
    145 var i;
    146 
    147 for ( i = 0; i < 10; i++ ) {
    148     x = randu() * 10.0;
    149     lambda = randu() * 10.0;
    150     k = randu() * 10.0;
    151     y = logcdf( x, lambda, k );
    152     console.log( 'x: %d, k: %d, λ: %d, ln(F(x;k,λ)): %d', x, k, lambda, y );
    153 }
    154 ```
    155 
    156 </section>
    157 
    158 <!-- /.examples -->
    159 
    160 <section class="links">
    161 
    162 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function
    163 
    164 [weibull-distribution]: https://en.wikipedia.org/wiki/Weibull_distribution
    165 
    166 [shape]: https://en.wikipedia.org/wiki/Shape_parameter
    167 
    168 [scale]: https://en.wikipedia.org/wiki/Scale_parameter
    169 
    170 </section>
    171 
    172 <!-- /.links -->