README.md (3789B)
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 # itermminabs 22 23 > Create an [iterator][mdn-iterator-protocol] which iteratively computes a moving minimum absolute value. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <!-- Package usage documentation. --> 32 33 <section class="usage"> 34 35 ## Usage 36 37 ```javascript 38 var itermminabs = require( '@stdlib/stats/iter/mminabs' ); 39 ``` 40 41 #### itermminabs( iterator, W ) 42 43 Returns an [iterator][mdn-iterator-protocol] which iteratively computes a moving minimum absolute value. The `W` parameter defines the number of iterated values over which to compute the moving minimum absolute value. 44 45 ```javascript 46 var array2iterator = require( '@stdlib/array/to-iterator' ); 47 48 var arr = array2iterator( [ 2.0, 1.0, 3.0, -7.0, -5.0 ] ); 49 var it = itermminabs( arr, 3 ); 50 51 // Fill the window... 52 var m = it.next().value; // [2.0] 53 // returns 2.0 54 55 m = it.next().value; // [2.0, 1.0] 56 // returns 1.0 57 58 m = it.next().value; // [2.0, 1.0, 3.0] 59 // returns 1.0 60 61 // Window begins sliding... 62 m = it.next().value; // [1.0, 3.0, -7.0] 63 // returns 1.0 64 65 m = it.next().value; // [3.0, -7.0, -5.0] 66 // returns 3.0 67 ``` 68 69 </section> 70 71 <!-- /.usage --> 72 73 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 74 75 <section class="notes"> 76 77 ## Notes 78 79 - 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. 80 - 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. 81 82 </section> 83 84 <!-- /.notes --> 85 86 <!-- Package usage examples. --> 87 88 <section class="examples"> 89 90 ## Examples 91 92 <!-- eslint no-undef: "error" --> 93 94 ```javascript 95 var runif = require( '@stdlib/random/iter/uniform' ); 96 var itermminabs = require( '@stdlib/stats/iter/mminabs' ); 97 98 // Create an iterator for generating uniformly distributed pseudorandom numbers: 99 var rand = runif( -10.0, 10.0, { 100 'seed': 1234, 101 'iter': 100 102 }); 103 104 // Create an iterator for iteratively computing a moving minimum absolute value: 105 var it = itermminabs( rand, 3 ); 106 107 // Perform manual iteration... 108 var v; 109 while ( true ) { 110 v = it.next(); 111 if ( typeof v.value === 'number' ) { 112 console.log( 'minabs: %d', v.value ); 113 } 114 if ( v.done ) { 115 break; 116 } 117 } 118 ``` 119 120 </section> 121 122 <!-- /.examples --> 123 124 <!-- 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. --> 125 126 <section class="references"> 127 128 </section> 129 130 <!-- /.references --> 131 132 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 133 134 <section class="links"> 135 136 [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol 137 138 </section> 139 140 <!-- /.links -->