time-to-botec

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

README.md (4053B)


      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 > [Discrete uniform][discrete-uniform-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 [discrete uniform][discrete-uniform-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:discrete_uniform_median" align="center" raw="\operatorname{Median}\left[ X \right] = 0.5 \cdot ( a + b )" alt="Median for a discrete uniform distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="\operatorname{Median}\left[ X \right] = 0.5 \cdot ( a + b )" data-equation="eq:discrete_uniform_median">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/stats/base/dists/discrete-uniform/median/docs/img/equation_discrete_uniform_median.svg" alt="Median for a discrete uniform distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `a` is the minimum support and `b` the maximum support of the distribution.
     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/discrete-uniform/median' );
     54 ```
     55 
     56 #### median( a, b )
     57 
     58 Returns the [median][median] of a [discrete uniform][discrete-uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
     59 
     60 ```javascript
     61 var v = median( 0, 1 );
     62 // returns 0.5
     63 
     64 v = median( 4, 12 );
     65 // returns 8.0
     66 
     67 v = median( 2, 8 );
     68 // returns 5.0
     69 ```
     70 
     71 If `a` or `b` is not an integer value, the function returns `NaN`.
     72 
     73 ```javascript
     74 var v = median( 0.1, 2 );
     75 // returns NaN
     76 
     77 v = median( 0, 2.2 );
     78 // returns NaN
     79 
     80 v = median( NaN, 2 );
     81 // returns NaN
     82 
     83 v = median( 2, NaN );
     84 // returns NaN
     85 ```
     86 
     87 If provided `a > b`, the function returns `NaN`.
     88 
     89 ```javascript
     90 var y = median( 3, 2 );
     91 // returns NaN
     92 
     93 y = median( -1, -2 );
     94 // returns NaN
     95 ```
     96 
     97 </section>
     98 
     99 <!-- /.usage -->
    100 
    101 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    102 
    103 <section class="notes">
    104 
    105 </section>
    106 
    107 <!-- /.notes -->
    108 
    109 <!-- Package usage examples. -->
    110 
    111 <section class="examples">
    112 
    113 ## Examples
    114 
    115 <!-- eslint no-undef: "error" -->
    116 
    117 ```javascript
    118 var randu = require( '@stdlib/random/base/randu' );
    119 var round = require( '@stdlib/math/base/special/round' );
    120 var median = require( '@stdlib/stats/base/dists/discrete-uniform/median' );
    121 
    122 var a;
    123 var b;
    124 var v;
    125 var i;
    126 
    127 for ( i = 0; i < 10; i++ ) {
    128     a = round( randu()*10.0 );
    129     b = round( ( randu()*10.0 ) + a );
    130     v = median( a, b );
    131     console.log( 'a: %d, b: %d, Median(X;a,b): %d', a.toFixed( 4 ), b.toFixed( 4 ), v.toFixed( 4 ) );
    132 }
    133 ```
    134 
    135 </section>
    136 
    137 <!-- /.examples -->
    138 
    139 <!-- 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. -->
    140 
    141 <section class="references">
    142 
    143 </section>
    144 
    145 <!-- /.references -->
    146 
    147 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    148 
    149 <section class="links">
    150 
    151 [discrete-uniform-distribution]: https://en.wikipedia.org/wiki/Discrete_uniform_distribution
    152 
    153 [median]: https://en.wikipedia.org/wiki/Median
    154 
    155 </section>
    156 
    157 <!-- /.links -->