time-to-botec

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

README.md (4523B)


      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 # itermsumabs2
     22 
     23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum of squared absolute values.
     24 
     25 <section class="intro">
     26 
     27 For a window of size `W`, the moving sum of squared absolute values is defined as
     28 
     29 <!-- <equation class="equation" label="eq:moving_sum_squared_absolute_values" align="center" raw="s = \sum_{i=0}^{W-1} x_i^2" alt="Equation for the moving sum of squared absolute values."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="s = \sum_{i=0}^{W-1} x_i^2" data-equation="eq:moving_sum_squared_absolute_values">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@601912bba7cacd1e1ffed3583e9b86e6383b4202/lib/node_modules/@stdlib/stats/iter/msumabs2/docs/img/equation_moving_sum_squared_absolute_values.svg" alt="Equation for the moving sum of squared absolute values.">
     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 itermsumabs2 = require( '@stdlib/stats/iter/msumabs2' );
     50 ```
     51 
     52 #### itermsumabs2( iterator, W )
     53 
     54 Returns an [iterator][mdn-iterator-protocol] which iteratively computes a moving sum of squared absolute values. The `W` parameter defines the number of iterated values over which to compute the moving sum.
     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 = itermsumabs2( arr, 3 );
     61 
     62 // Fill the window...
     63 var s = it.next().value; // [2.0]
     64 // returns 4.0
     65 
     66 s = it.next().value; // [2.0, 1.0]
     67 // returns 5.0
     68 
     69 s = it.next().value; // [2.0, 1.0, 3.0]
     70 // returns 14.0
     71 
     72 // Window begins sliding...
     73 s = it.next().value; // [1.0, 3.0, -7.0]
     74 // returns 59.0
     75 
     76 s = it.next().value; // [3.0, -7.0, -5.0]
     77 // returns 83.0
     78 ```
     79 
     80 </section>
     81 
     82 <!-- /.usage -->
     83 
     84 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     85 
     86 <section class="notes">
     87 
     88 ## Notes
     89 
     90 -   If an iterated value is non-numeric (including `NaN`), the function returns `NaN` for **at least** `W-1` future invocations. 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.
     91 -   As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all previously iterated values.
     92 
     93 </section>
     94 
     95 <!-- /.notes -->
     96 
     97 <!-- Package usage examples. -->
     98 
     99 <section class="examples">
    100 
    101 ## Examples
    102 
    103 <!-- eslint no-undef: "error" -->
    104 
    105 ```javascript
    106 var runif = require( '@stdlib/random/iter/uniform' );
    107 var itermsumabs2 = require( '@stdlib/stats/iter/msumabs2' );
    108 
    109 // Create an iterator for generating uniformly distributed pseudorandom numbers:
    110 var rand = runif( -10.0, 10.0, {
    111     'seed': 1234,
    112     'iter': 100
    113 });
    114 
    115 // Create an iterator for iteratively computing a moving sum of squared absolute values:
    116 var it = itermsumabs2( rand, 3 );
    117 
    118 // Perform manual iteration...
    119 var v;
    120 while ( true ) {
    121     v = it.next();
    122     if ( typeof v.value === 'number' ) {
    123         console.log( 'sumabs2: %d', v.value );
    124     }
    125     if ( v.done ) {
    126         break;
    127     }
    128 }
    129 ```
    130 
    131 </section>
    132 
    133 <!-- /.examples -->
    134 
    135 <!-- 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. -->
    136 
    137 <section class="references">
    138 
    139 </section>
    140 
    141 <!-- /.references -->
    142 
    143 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    144 
    145 <section class="links">
    146 
    147 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
    148 
    149 </section>
    150 
    151 <!-- /.links -->