README.md (3353B)
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 > [Exponential][exponential-distribution] distribution [cumulative distribution function][cdf]. 24 25 <section class="intro"> 26 27 The [cumulative distribution function][cdf] for an [exponential][exponential-distribution] random variable is 28 29 <!-- <equation class="equation" label="eq:exponential_cdf" align="center" raw="F(x;\lambda) = \begin{cases} 1-e^{-\lambda x} & x \ge 0 \\ 0 & x < 0 \end{cases}" alt="Cumulative distribution function for an exponential distribution."> --> 30 31 <div class="equation" align="center" data-raw-text="F(x;\lambda) = \begin{cases} 1-e^{-\lambda x} & x \ge 0 \\ 0 & x < 0 \end{cases}" data-equation="eq:exponential_cdf"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/exponential/cdf/docs/img/equation_exponential_cdf.svg" alt="Cumulative distribution function for an exponential distribution."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `λ` is the rate parameter. 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/exponential/cdf' ); 50 ``` 51 52 #### cdf( x, lambda ) 53 54 Evaluates the [cumulative distribution function][cdf] for an [exponential][exponential-distribution] distribution with rate parameter `lambda`. 55 56 ```javascript 57 var y = cdf( 2.0, 0.3 ); 58 // returns ~0.451 59 60 y = cdf( 10.0, 0.3 ); 61 // returns ~0.95 62 ``` 63 64 If provided `NaN` as any argument, the function returns `NaN`. 65 66 ```javascript 67 var y = cdf( NaN, 0.0 ); 68 // returns NaN 69 70 y = cdf( 0.0, NaN ); 71 // returns NaN 72 ``` 73 74 If provided `lambda < 0`, the function returns `NaN`. 75 76 ```javascript 77 var y = cdf( 2.0, -1.0 ); 78 // returns NaN 79 ``` 80 81 #### cdf.factory( lambda ) 82 83 Returns a function for evaluating the [cumulative distribution function (CDF)][cdf] for an exponential distribution with rate parameter `lambda`. 84 85 ```javascript 86 var mycdf = cdf.factory( 0.1 ); 87 88 var y = mycdf( 8.0 ); 89 // returns ~0.551 90 91 y = mycdf( 2.0 ); 92 // returns ~0.181 93 94 y = mycdf( 0.0 ); 95 // returns 0.0 96 ``` 97 98 </section> 99 100 <!-- /.usage --> 101 102 <section class="examples"> 103 104 ## Examples 105 106 <!-- eslint no-undef: "error" --> 107 108 ```javascript 109 var randu = require( '@stdlib/random/base/randu' ); 110 var cdf = require( '@stdlib/stats/base/dists/exponential/cdf' ); 111 112 var lambda; 113 var x; 114 var y; 115 var i; 116 117 for ( i = 0; i < 10; i++ ) { 118 x = randu() * 10.0; 119 lambda = randu() * 10.0; 120 y = cdf( x, lambda ); 121 console.log( 'x: %d, λ: %d, F(x;λ): %d', x, lambda, y ); 122 } 123 ``` 124 125 </section> 126 127 <!-- /.examples --> 128 129 <section class="links"> 130 131 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 132 133 [exponential-distribution]: https://en.wikipedia.org/wiki/Exponential_distribution 134 135 </section> 136 137 <!-- /.links -->