time-to-botec

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

README.md (3631B)


      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 # Median
     22 
     23 > [Geometric][geometric-distribution] distribution [median][median].
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 The [median][median] for a [geometric][geometric-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:geometric_median" align="center" raw="\operatorname{Median}\left( X \right) = \left\lceil {\frac {-1}{\log _{2}(1-p)}}\right\rceil \!-1" alt="Median for a geometric distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="\operatorname{Median}\left( X \right) = \left\lceil {\frac {-1}{\log _{2}(1-p)}}\right\rceil \!-1" data-equation="eq:geometric_median">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/geometric/median/docs/img/equation_geometric_median.svg" alt="Median for a geometric distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `p` is the success probability.
     41 
     42 </section>
     43 
     44 <!-- /.intro -->
     45 
     46 <!-- Package usage documentation. -->
     47 
     48 <section class="usage">
     49 
     50 ## Usage
     51 
     52 ```javascript
     53 var median = require( '@stdlib/stats/base/dists/geometric/median' );
     54 ```
     55 
     56 #### median( p )
     57 
     58 Returns the [median][median] of a [geometric][geometric-distribution] distribution with success probability `p`.
     59 
     60 ```javascript
     61 var v = median( 0.1 );
     62 // returns 6
     63 
     64 v = median( 0.5 );
     65 // returns 0
     66 ```
     67 
     68 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`.
     69 
     70 ```javascript
     71 var v = median( NaN );
     72 // returns NaN
     73 
     74 v = median( 1.5 );
     75 // returns NaN
     76 
     77 v = median( -1.0 );
     78 // returns NaN
     79 ```
     80 
     81 </section>
     82 
     83 <!-- /.usage -->
     84 
     85 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     86 
     87 <section class="notes">
     88 
     89 </section>
     90 
     91 <!-- /.notes -->
     92 
     93 <!-- Package usage examples. -->
     94 
     95 <section class="examples">
     96 
     97 ## Examples
     98 
     99 <!-- eslint no-undef: "error" -->
    100 
    101 ```javascript
    102 var randu = require( '@stdlib/random/base/randu' );
    103 var round = require( '@stdlib/math/base/special/round' );
    104 var median = require( '@stdlib/stats/base/dists/geometric/median' );
    105 
    106 var v;
    107 var i;
    108 var p;
    109 
    110 for ( i = 0; i < 10; i++ ) {
    111     p = randu();
    112     v = median( p );
    113     console.log( 'p: %d, Median(X;p): %d', p.toFixed( 4 ), v.toFixed( 4 ) );
    114 }
    115 ```
    116 
    117 </section>
    118 
    119 <!-- /.examples -->
    120 
    121 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    122 
    123 <section class="references">
    124 
    125 </section>
    126 
    127 <!-- /.references -->
    128 
    129 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    130 
    131 <section class="links">
    132 
    133 [geometric-distribution]: https://en.wikipedia.org/wiki/Geometric_distribution
    134 
    135 [median]: https://en.wikipedia.org/wiki/Median
    136 
    137 </section>
    138 
    139 <!-- /.links -->