time-to-botec

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

README.md (3700B)


      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 # Quantile Function
     22 
     23 > [Geometric][geometric-distribution] distribution [quantile function][quantile-function].
     24 
     25 <section class="intro">
     26 
     27 The [quantile function][quantile-function] for a [geometric][geometric-distribution] random variable is
     28 
     29 <!-- <equation class="equation" label="eq:geometric_quantile_function" align="center" raw="Q(r;p)=\left\lceil \frac{\ln(1-r)}{\ln(1-p)} \right\rceil" alt="Quantile function for a geometric distribution."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="Q(r;p)=\left\lceil \frac{\ln(1-r)}{\ln(1-p)} \right\rceil" data-equation="eq:geometric_quantile_function">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/quantile/docs/img/equation_geometric_quantile_function.svg" alt="Quantile function for a geometric distribution.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 for `0 < r < 1`, where `p` is the success probability.
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var quantile = require( '@stdlib/stats/base/dists/geometric/quantile' );
     50 ```
     51 
     52 #### quantile( r, p )
     53 
     54 Evaluates the [quantile function][quantile-function] for a [geometric][geometric-distribution] distribution with success probability `p` at a value `r`.
     55 
     56 ```javascript
     57 var y = quantile( 0.8, 0.4 );
     58 // returns 3
     59 
     60 y = quantile( 0.5, 0.4 );
     61 // returns 1
     62 
     63 y = quantile( 0.9, 0.1 );
     64 // returns 21
     65 ```
     66 
     67 If provided an input probability `r` outside the interval `[0,1]`, the function returns `NaN`.
     68 
     69 ```javascript
     70 var y = quantile( 1.9, 0.5 );
     71 // returns NaN
     72 
     73 y = quantile( -0.1, 0.5 );
     74 // returns NaN
     75 ```
     76 
     77 If provided `NaN` as any argument, the function returns `NaN`.
     78 
     79 ```javascript
     80 var y = quantile( NaN, 1.0 );
     81 // returns NaN
     82 
     83 y = quantile( 0.0, NaN );
     84 // returns NaN
     85 ```
     86 
     87 If provided a success probability `p` outside the interval `[0,1]`, the function returns `NaN`.
     88 
     89 ```javascript
     90 var y = quantile( 0.4, -1.0 );
     91 // returns NaN
     92 
     93 y = quantile( 0.4, 1.5 );
     94 // returns NaN
     95 ```
     96 
     97 #### quantile.factory( p )
     98 
     99 Returns a function for evaluating the [quantile function][quantile-function] for a [geometric][geometric-distribution] distribution with success probability `p`.
    100 
    101 ```javascript
    102 var myquantile = quantile.factory( 0.4 );
    103 var y = myquantile( 0.4 );
    104 // returns 0
    105 
    106 y = myquantile( 0.8 );
    107 // returns 3
    108 
    109 y = myquantile( 1.0 );
    110 // returns Infinity
    111 ```
    112 
    113 </section>
    114 
    115 <!-- /.usage -->
    116 
    117 <section class="examples">
    118 
    119 ## Examples
    120 
    121 <!-- eslint no-undef: "error" -->
    122 
    123 ```javascript
    124 var randu = require( '@stdlib/random/base/randu' );
    125 var quantile = require( '@stdlib/stats/base/dists/geometric/quantile' );
    126 
    127 var p;
    128 var r;
    129 var y;
    130 var i;
    131 
    132 for ( i = 0; i < 10; i++ ) {
    133     r = randu();
    134     p = randu();
    135     y = quantile( r, p );
    136     console.log( 'r: %d, p: %d, Q(r;p): %d', r.toFixed( 4 ), p.toFixed( 4 ), y.toFixed( 4 ) );
    137 }
    138 ```
    139 
    140 </section>
    141 
    142 <!-- /.examples -->
    143 
    144 <section class="links">
    145 
    146 [geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution
    147 
    148 [quantile-function]: https://en.wikipedia.org/wiki/Quantile_function
    149 
    150 </section>
    151 
    152 <!-- /.links -->