time-to-botec

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

README.md (4141B)


      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 # itercugmean
     22 
     23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative [geometric mean][geometric-mean].
     24 
     25 <section class="intro">
     26 
     27 The [geometric mean][geometric-mean] is defined as the nth root of a product of _n_ numbers.
     28 
     29 <!-- <equation class="equation" label="eq:geometric_mean" align="center" raw="\biggl( \prod_{i=0}^{n-1} \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}}" alt="Equation for the geometric mean."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\biggl( \prod_{i=0}^{n-1} \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}}" data-equation="eq:geometric_mean">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@b38de7dff069561da1cb4710c85fc74433b7eaaa/lib/node_modules/@stdlib/stats/iter/cugmean/docs/img/equation_geometric_mean.svg" alt="Equation for the geometric mean.">
     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 itercugmean = require( '@stdlib/stats/iter/cugmean' );
     50 ```
     51 
     52 #### itercugmean( iterator )
     53 
     54 Returns an [iterator][mdn-iterator-protocol] which iteratively computes a cumulative [geometric mean][geometric-mean].
     55 
     56 ```javascript
     57 var array2iterator = require( '@stdlib/array/to-iterator' );
     58 
     59 var arr = array2iterator( [ 2.0, 1.0, 3.0, 7.0, 5.0 ] );
     60 var it = itercugmean( arr );
     61 
     62 var v = it.next().value;
     63 // returns 2.0
     64 
     65 v = it.next().value;
     66 // returns ~1.41
     67 
     68 v = it.next().value;
     69 // returns ~1.82
     70 
     71 v = it.next().value;
     72 // returns ~2.55
     73 
     74 v = it.next().value;
     75 // returns ~2.91
     76 ```
     77 
     78 </section>
     79 
     80 <!-- /.usage -->
     81 
     82 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     83 
     84 <section class="notes">
     85 
     86 ## Notes
     87 
     88 -   If an iterated value is non-numeric (including `NaN`) or negative, the function returns `NaN` for **all** future iterations. If non-numeric and/or negative iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles such values accordingly.
     89 
     90 </section>
     91 
     92 <!-- /.notes -->
     93 
     94 <!-- Package usage examples. -->
     95 
     96 <section class="examples">
     97 
     98 ## Examples
     99 
    100 <!-- eslint no-undef: "error" -->
    101 
    102 ```javascript
    103 var runif = require( '@stdlib/random/iter/uniform' );
    104 var itercugmean = require( '@stdlib/stats/iter/cugmean' );
    105 
    106 // Create an iterator for generating uniformly distributed pseudorandom numbers:
    107 var rand = runif( 0.0, 10.0, {
    108     'seed': 1234,
    109     'iter': 100
    110 });
    111 
    112 // Create an iterator for iteratively computing a cumulative geometric mean:
    113 var it = itercugmean( rand );
    114 
    115 // Perform manual iteration...
    116 var v;
    117 while ( true ) {
    118     v = it.next();
    119     if ( typeof v.value === 'number' ) {
    120         console.log( 'gmean: %d', v.value );
    121     }
    122     if ( v.done ) {
    123         break;
    124     }
    125 }
    126 ```
    127 
    128 </section>
    129 
    130 <!-- /.examples -->
    131 
    132 <!-- 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. -->
    133 
    134 <section class="references">
    135 
    136 </section>
    137 
    138 <!-- /.references -->
    139 
    140 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    141 
    142 <section class="links">
    143 
    144 [geometric-mean]: https://en.wikipedia.org/wiki/Geometric_mean
    145 
    146 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    147 
    148 </section>
    149 
    150 <!-- /.links -->