time-to-botec

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

README.md (3944B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2019 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 # itervariance
     22 
     23 > Compute the [unbiased sample variance][sample-variance] over all [iterated][mdn-iterator-protocol] values.
     24 
     25 <section class="intro">
     26 
     27 The [unbiased sample variance][sample-variance] is defined as
     28 
     29 <!-- <equation class="equation" label="eq:unbiased_sample_variance" align="center" raw="s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2" alt="Equation for the unbiased sample variance."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2" data-equation="eq:unbiased_sample_variance">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@e7ac225deb396ee6d2b4d5fc1a2faa645582349f/lib/node_modules/@stdlib/stats/iter/variance/docs/img/equation_unbiased_sample_variance.svg" alt="Equation for the unbiased sample variance.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 </section>
     39 
     40 <!-- /.intro -->
     41 
     42 <!-- Package usage documentation. -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var itervariance = require( '@stdlib/stats/iter/variance' );
     50 ```
     51 
     52 #### itervariance( iterator\[, mean] )
     53 
     54 Computes the [unbiased sample variance][sample-variance] over all [iterated][mdn-iterator-protocol] values.
     55 
     56 ```javascript
     57 var array2iterator = require( '@stdlib/array/to-iterator' );
     58 
     59 var arr = array2iterator( [ 2.0, 1.0, 3.0 ] );
     60 
     61 var s2 = itervariance( arr );
     62 // returns 1.0
     63 ```
     64 
     65 If the mean is already known, provide a `mean` argument.
     66 
     67 ```javascript
     68 var array2iterator = require( '@stdlib/array/to-iterator' );
     69 
     70 var arr = array2iterator( [ 2.0, 1.0, 3.0 ] );
     71 
     72 var s2 = itervariance( arr, 2.0 );
     73 // returns ~0.67
     74 ```
     75 
     76 </section>
     77 
     78 <!-- /.usage -->
     79 
     80 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     81 
     82 <section class="notes">
     83 
     84 ## Notes
     85 
     86 -   If an iterated value is non-numeric (including `NaN`), the returned [`iterator`][mdn-iterator-protocol] returns `NaN`. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly.
     87 
     88 </section>
     89 
     90 <!-- /.notes -->
     91 
     92 <!-- Package usage examples. -->
     93 
     94 <section class="examples">
     95 
     96 ## Examples
     97 
     98 <!-- eslint no-undef: "error" -->
     99 
    100 ```javascript
    101 var runif = require( '@stdlib/random/iter/uniform' );
    102 var itervariance = require( '@stdlib/stats/iter/variance' );
    103 
    104 // Create an iterator for generating uniformly distributed pseudorandom numbers:
    105 var rand = runif( -10.0, 10.0, {
    106     'seed': 1234,
    107     'iter': 100
    108 });
    109 
    110 // Compute the unbiased sample variance:
    111 var s2 = itervariance( rand );
    112 // returns <number>
    113 
    114 console.log( 'Variance: %d.', s2 );
    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 [sample-variance]: https://en.wikipedia.org/wiki/Variance
    134 
    135 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    136 
    137 </section>
    138 
    139 <!-- /.links -->