|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# incrnanmminmax |
| 22 | + |
| 23 | +> Compute a moving minimum and maximum incrementally ignoring `NaN` values. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var incrnanmminmax = require( '@stdlib/stats/incr/nanmminmax' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### incrnanmminmax( \[out,] window ) |
| 34 | + |
| 35 | +Returns an accumulator `function` which incrementally computes a moving minimum and maximum, ignoring `NaN` values. The `window` parameter defines the number of values over which to compute the moving minimum and maximum. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var accumulator = incrnanmminmax( 3 ); |
| 39 | +``` |
| 40 | + |
| 41 | +By default, the returned accumulator `function` returns the minimum and maximum as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 45 | + |
| 46 | +var accumulator = incrnanmminmax( new Float64Array( 2 ), 3 ); |
| 47 | +``` |
| 48 | + |
| 49 | +#### accumulator( \[x] ) |
| 50 | + |
| 51 | +If provided an input value `x`, the accumulator function returns updated minimum and maximum values. If not provided an input value `x`, the accumulator function returns the current minimum and maximum values. |
| 52 | + |
| 53 | +```javascript |
| 54 | +var accumulator = incrnanmminmax( 3 ); |
| 55 | + |
| 56 | +var mm = accumulator(); |
| 57 | +// returns null |
| 58 | + |
| 59 | +// Fill the window... |
| 60 | +mm = accumulator( 2.0 ); // [2.0] |
| 61 | +// returns [ 2.0, 2.0 ] |
| 62 | + |
| 63 | +mm = accumulator( 1.0 ); // [2.0, 1.0] |
| 64 | +// returns [ 1.0, 2.0 ] |
| 65 | + |
| 66 | +mm = accumulator( 3.0 ); // [2.0, 1.0, 3.0] |
| 67 | +// returns [ 1.0, 3.0 ] |
| 68 | + |
| 69 | +// Window begins sliding... |
| 70 | +mm = accumulator( -7.0 ); // [1.0, 3.0, -7.0] |
| 71 | +// returns [ -7.0, 3.0 ] |
| 72 | + |
| 73 | +mm = accumulator( NaN ); // [1.0, 3.0, -7.0] |
| 74 | +// returns [ -7.0, 3.0 ] |
| 75 | + |
| 76 | +mm = accumulator( -5.0 ); // [3.0, -7.0, -5.0] |
| 77 | +// returns [ -7.0, 3.0 ] |
| 78 | + |
| 79 | +mm = accumulator(); |
| 80 | +// returns [ -7.0, 3.0 ] |
| 81 | +``` |
| 82 | + |
| 83 | +</section> |
| 84 | + |
| 85 | +<!-- /.usage --> |
| 86 | + |
| 87 | +<section class="notes"> |
| 88 | + |
| 89 | +## Notes |
| 90 | + |
| 91 | +- Input values are **not** type checked. If provided `NaN`, the accumulated minimum and maximum values are `NaN` for **at least** `W-1` future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. |
| 92 | +- As `W` values are needed to fill the window buffer, the first `W-1` returned minimum and maximum values are calculated from smaller sample sizes. Until the window is full, each returned minimum and maximum is calculated from all provided values. |
| 93 | + |
| 94 | +</section> |
| 95 | + |
| 96 | +<!-- /.notes --> |
| 97 | + |
| 98 | +<section class="examples"> |
| 99 | + |
| 100 | +## Examples |
| 101 | + |
| 102 | +<!-- eslint no-undef: "error" --> |
| 103 | + |
| 104 | +```javascript |
| 105 | +var randu = require( '@stdlib/random/base/randu' ); |
| 106 | +var incrnanmminmax = require( '@stdlib/stats/incr/nanmminmax' ); |
| 107 | + |
| 108 | +var accumulator; |
| 109 | +var v; |
| 110 | +var i; |
| 111 | + |
| 112 | +// Initialize an accumulator: |
| 113 | +accumulator = incrnanmminmax( 5 ); |
| 114 | + |
| 115 | +// For each simulated datum, update the moving minimum and maximum... |
| 116 | +for ( i = 0; i < 100; i++ ) { |
| 117 | + if ( randu() < 0.2 ) { |
| 118 | + v = NaN; |
| 119 | + } else { |
| 120 | + v = randu() * 100.0; |
| 121 | + } |
| 122 | + accumulator( v ); |
| 123 | +} |
| 124 | +console.log( accumulator() ); |
| 125 | +``` |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.examples --> |
| 130 | + |
| 131 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 132 | + |
| 133 | +<section class="related"> |
| 134 | + |
| 135 | +* * * |
| 136 | + |
| 137 | +## See Also |
| 138 | + |
| 139 | +- <span class="package-name">[`@stdlib/stats/incr/max`][@stdlib/stats/incr/max]</span><span class="delimiter">: </span><span class="description">compute a maximum value incrementally.</span> |
| 140 | +- <span class="package-name">[`@stdlib/stats/incr/min`][@stdlib/stats/incr/min]</span><span class="delimiter">: </span><span class="description">compute a minimum value incrementally.</span> |
| 141 | +- <span class="package-name">[`@stdlib/stats/incr/mmax`][@stdlib/stats/incr/mmax]</span><span class="delimiter">: </span><span class="description">compute a moving maximum incrementally.</span> |
| 142 | +- <span class="package-name">[`@stdlib/stats/incr/minmax`][@stdlib/stats/incr/minmax]</span><span class="delimiter">: </span><span class="description">compute a minimum and maximum incrementally.</span> |
| 143 | +- <span class="package-name">[`@stdlib/stats/incr/mmin`][@stdlib/stats/incr/mmin]</span><span class="delimiter">: </span><span class="description">compute a moving minimum incrementally.</span> |
| 144 | +- <span class="package-name">[`@stdlib/stats/incr/mrange`][@stdlib/stats/incr/mrange]</span><span class="delimiter">: </span><span class="description">compute a moving range incrementally.</span> |
| 145 | + |
| 146 | +</section> |
| 147 | + |
| 148 | +<!-- /.related --> |
| 149 | + |
| 150 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 151 | + |
| 152 | +<section class="links"> |
| 153 | + |
| 154 | +<!-- <related-links> --> |
| 155 | + |
| 156 | +[@stdlib/stats/incr/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/max |
| 157 | + |
| 158 | +[@stdlib/stats/incr/min]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/min |
| 159 | + |
| 160 | +[@stdlib/stats/incr/mmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmax |
| 161 | + |
| 162 | +[@stdlib/stats/incr/minmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/minmax |
| 163 | + |
| 164 | +[@stdlib/stats/incr/mmin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmin |
| 165 | + |
| 166 | +[@stdlib/stats/incr/mrange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mrange |
| 167 | + |
| 168 | +<!-- </related-links> --> |
| 169 | + |
| 170 | +</section> |
| 171 | + |
| 172 | +<!-- /.links --> |
0 commit comments