time-to-botec

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

README.md (4158B)


      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 > [Beta][beta-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 [beta][beta-distribution] random variable is the value for which 
     30 the regularized incomplete beta function `I(α,β)` is equal to `0.5`, i.e.
     31 
     32 <!-- <equation class="equation" label="eq:beta_median" align="center" raw="\operatorname{Median}\left[ X \right] = I_{\frac{1}{2}}^{[-1]}(\alpha,\beta)" alt="Median for a beta distribution."> -->
     33 
     34 <div class="equation" align="center" data-raw-text="\operatorname{Median}\left[ X \right] = I_{\frac{1}{2}}^{[-1]}(\alpha,\beta)" data-equation="eq:beta_median">
     35     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/beta/median/docs/img/equation_beta_median.svg" alt="Median for a beta distribution.">
     36     <br>
     37 </div>
     38 
     39 <!-- </equation> -->
     40 
     41 where `α > 0` is the first shape parameter and `β > 0` is the second shape parameter.
     42 
     43 </section>
     44 
     45 <!-- /.intro -->
     46 
     47 <!-- Package usage documentation. -->
     48 
     49 <section class="usage">
     50 
     51 ## Usage
     52 
     53 ```javascript
     54 var median = require( '@stdlib/stats/base/dists/beta/median' );
     55 ```
     56 
     57 #### median( alpha, beta )
     58 
     59 Returns the [median][median] of a [beta][beta-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter).
     60 
     61 ```javascript
     62 var v = median( 1.0, 1.0 );
     63 // returns 0.5
     64 
     65 v = median( 4.0, 12.0 );
     66 // returns ~0.239
     67 
     68 v = median( 8.0, 2.0 );
     69 // returns ~0.820
     70 ```
     71 
     72 If provided `NaN` as any argument, the function returns `NaN`.
     73 
     74 ```javascript
     75 var v = median( NaN, 2.0 );
     76 // returns NaN
     77 
     78 v = median( 2.0, NaN );
     79 // returns NaN
     80 ```
     81 
     82 If provided `alpha <= 0`, the function returns `NaN`.
     83 
     84 ```javascript
     85 var v = median( 0.0, 1.0 );
     86 // returns NaN
     87 
     88 v = median( -1.0, 1.0 );
     89 // returns NaN
     90 ```
     91 
     92 If provided `beta <= 0`, the function returns `NaN`.
     93 
     94 ```javascript
     95 var v = median( 1.0, 0.0 );
     96 // returns NaN
     97 
     98 v = median( 1.0, -1.0 );
     99 // returns NaN
    100 ```
    101 
    102 </section>
    103 
    104 <!-- /.usage -->
    105 
    106 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    107 
    108 <section class="notes">
    109 
    110 </section>
    111 
    112 <!-- /.notes -->
    113 
    114 <!-- Package usage examples. -->
    115 
    116 <section class="examples">
    117 
    118 ## Examples
    119 
    120 <!-- eslint no-undef: "error" -->
    121 
    122 ```javascript
    123 var randu = require( '@stdlib/random/base/randu' );
    124 var EPS = require( '@stdlib/constants/float64/eps' );
    125 var median = require( '@stdlib/stats/base/dists/beta/median' );
    126 
    127 var alpha;
    128 var beta;
    129 var v;
    130 var i;
    131 
    132 for ( i = 0; i < 10; i++ ) {
    133     alpha = ( randu()*10.0 ) + EPS;
    134     beta = ( randu()*10.0 ) + EPS;
    135     v = median( alpha, beta );
    136     console.log( 'α: %d, β: %d, Median(X;α,β): %d', alpha.toFixed( 4 ), beta.toFixed( 4 ), v.toFixed( 4 ) );
    137 }
    138 ```
    139 
    140 </section>
    141 
    142 <!-- /.examples -->
    143 
    144 <!-- 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. -->
    145 
    146 <section class="references">
    147 
    148 </section>
    149 
    150 <!-- /.references -->
    151 
    152 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    153 
    154 <section class="links">
    155 
    156 [beta-distribution]: https://en.wikipedia.org/wiki/Beta_distribution
    157 
    158 [median]: https://en.wikipedia.org/wiki/Median
    159 
    160 </section>
    161 
    162 <!-- /.links -->