time-to-botec

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

README.md (4075B)


      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 # Mode
     22 
     23 > [Binomial][binomial-distribution] distribution [mode][mode].
     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 [mode][mode] for a [binomial][binomial-distribution] random variable is
     30 
     31 <!-- <equation class="equation" label="eq:binomial_mode" align="center" raw="\operatorname{mode}\left( X \right) = \lfloor (n+1)p \rfloor" alt="Mode for a binomial distribution."> -->
     32 
     33 <div class="equation" align="center" data-raw-text="\operatorname{mode}\left( X \right) = \lfloor (n+1)p \rfloor" data-equation="eq:binomial_mode">
     34     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/binomial/mode/docs/img/equation_binomial_mode.svg" alt="Mode for a binomial distribution.">
     35     <br>
     36 </div>
     37 
     38 <!-- </equation> -->
     39 
     40 where `n` is the number of trials, `p` is the success probability, and `⌊x⌋` is the [floor][floor] function.
     41 
     42 </section>
     43 
     44 <!-- /.intro -->
     45 
     46 <!-- Package usage documentation. -->
     47 
     48 <section class="usage">
     49 
     50 ## Usage
     51 
     52 ```javascript
     53 var mode = require( '@stdlib/stats/base/dists/binomial/mode' );
     54 ```
     55 
     56 #### mode( n, p )
     57 
     58 Returns the [mode][mode] of a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`.
     59 
     60 ```javascript
     61 var v = mode( 20, 0.1 );
     62 // returns 2
     63 
     64 v = mode( 50, 0.5 );
     65 // returns 25
     66 ```
     67 
     68 If provided `NaN` as any argument, the function returns `NaN`.
     69 
     70 ```javascript
     71 var v = mode( NaN, 0.5 );
     72 // returns NaN
     73 
     74 v = mode( 20, NaN );
     75 // returns NaN
     76 ```
     77 
     78 If provided a number of trials `n` which is not a nonnegative integer, the function returns `NaN`.
     79 
     80 ```javascript
     81 var v = mode( 1.5, 0.5 );
     82 // returns NaN
     83 
     84 v = mode( -2.0, 0.5 );
     85 // returns NaN
     86 ```
     87 
     88 If provided a success probability `p` outside of `[0,1]`, the function returns `NaN`.
     89 
     90 ```javascript
     91 var v = mode( 20, -1.0 );
     92 // returns NaN
     93 
     94 v = mode( 20, 1.5 );
     95 // returns NaN
     96 ```
     97 
     98 </section>
     99 
    100 <!-- /.usage -->
    101 
    102 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    103 
    104 <section class="notes">
    105 
    106 </section>
    107 
    108 <!-- /.notes -->
    109 
    110 <!-- Package usage examples. -->
    111 
    112 <section class="examples">
    113 
    114 ## Examples
    115 
    116 <!-- eslint no-undef: "error" -->
    117 
    118 ```javascript
    119 var randu = require( '@stdlib/random/base/randu' );
    120 var round = require( '@stdlib/math/base/special/round' );
    121 var mode = require( '@stdlib/stats/base/dists/binomial/mode' );
    122 
    123 var v;
    124 var i;
    125 var n;
    126 var p;
    127 
    128 for ( i = 0; i < 10; i++ ) {
    129     n = round( randu() * 100.0 );
    130     p = randu();
    131     v = mode( n, p );
    132     console.log( 'n: %d, p: %d, mode(X;n,p): %d', n, p.toFixed( 4 ), v.toFixed( 4 ) );
    133 }
    134 ```
    135 
    136 </section>
    137 
    138 <!-- /.examples -->
    139 
    140 <!-- 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. -->
    141 
    142 <section class="references">
    143 
    144 </section>
    145 
    146 <!-- /.references -->
    147 
    148 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    149 
    150 <section class="links">
    151 
    152 [binomial-distribution]: https://en.wikipedia.org/wiki/Binomial_distribution
    153 
    154 [floor]: https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
    155 
    156 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29
    157 
    158 </section>
    159 
    160 <!-- /.links -->