|
| 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 | +# incrnanminmaxabs |
| 22 | + |
| 23 | +> Compute minimum and maximum absolute values incrementally, ignoring `NaN` values. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var incrnanminmaxabs = require( '@stdlib/stats/incr/nanminmaxabs' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### incrnanminmaxabs( \[out] ) |
| 34 | + |
| 35 | +Returns an accumulator `function` which incrementally computes minimum and maximum absolute values while ignoring `NaN` values. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var accumulator = incrnanminmaxabs(); |
| 39 | +``` |
| 40 | + |
| 41 | +By default, the returned accumulator `function` returns the minimum and maximum absolute values 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 = incrnanminmaxabs( new Float64Array( 2 ) ); |
| 47 | +``` |
| 48 | + |
| 49 | +#### accumulator( \[x] ) |
| 50 | + |
| 51 | +If provided an input value `x`, the accumulator function returns updated minimum and maximum absolute values, ignoring `NaN`. If not provided an input value `x`, the accumulator function returns the current minimum and maximum absolute values. |
| 52 | + |
| 53 | +```javascript |
| 54 | +var accumulator = incrnanminmaxabs(); |
| 55 | + |
| 56 | +var mm = accumulator(); |
| 57 | +// returns null |
| 58 | + |
| 59 | +mm = accumulator( 2.0 ); |
| 60 | +// returns [ 2.0, 2.0 ] |
| 61 | + |
| 62 | +mm = accumulator( NaN ); |
| 63 | +// returns [ 2.0, 2.0 ] (ignores NaN) |
| 64 | + |
| 65 | +mm = accumulator( 1.0 ); |
| 66 | +// returns [ 1.0, 2.0 ] |
| 67 | + |
| 68 | +mm = accumulator( 3.0 ); |
| 69 | +// returns [ 1.0, 3.0 ] |
| 70 | + |
| 71 | +mm = accumulator( -7.0 ); |
| 72 | +// returns [ 1.0, 7.0 ] |
| 73 | + |
| 74 | +mm = accumulator(); |
| 75 | +// returns [ 1.0, 7.0 ] |
| 76 | +``` |
| 77 | + |
| 78 | +</section> |
| 79 | + |
| 80 | +<!-- /.usage --> |
| 81 | + |
| 82 | +<section class="notes"> |
| 83 | + |
| 84 | +## Notes |
| 85 | + |
| 86 | +- `NaN` values are ignored in calculations. This ensures `NaN` does not contaminate future results. |
| 87 | +- If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. |
| 88 | + |
| 89 | +</section> |
| 90 | + |
| 91 | +<!-- /.notes --> |
| 92 | + |
| 93 | +<section class="examples"> |
| 94 | + |
| 95 | +## Examples |
| 96 | + |
| 97 | +<!-- eslint no-undef: "error" --> |
| 98 | + |
| 99 | +```javascript |
| 100 | +var randu = require( '@stdlib/random/base/randu' ); |
| 101 | +var incrnanminmaxabs = require( '@stdlib/stats/incr/nanminmaxabs' ); |
| 102 | + |
| 103 | +var accumulator; |
| 104 | +var v; |
| 105 | +var i; |
| 106 | + |
| 107 | +// Initialize an accumulator: |
| 108 | +accumulator = incrnanminmaxabs(); |
| 109 | + |
| 110 | +// For each simulated datum, update the minimum and maximum absolute values... |
| 111 | +for ( i = 0; i < 100; i++ ) { |
| 112 | + v = ( randu()*100.0 ) - 50.0; |
| 113 | + if ( randu() < 0.1 ) { |
| 114 | + v = NaN; |
| 115 | + } |
| 116 | + accumulator( v ); |
| 117 | +} |
| 118 | +console.log( accumulator() ); |
| 119 | +``` |
| 120 | + |
| 121 | +</section> |
| 122 | + |
| 123 | +<!-- /.examples --> |
| 124 | + |
| 125 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 126 | + |
| 127 | +<section class="related"> |
| 128 | + |
| 129 | +* * * |
| 130 | + |
| 131 | +## See Also |
| 132 | + |
| 133 | +- <span class="package-name">[`@stdlib/stats/incr/maxabs`][@stdlib/stats/incr/maxabs]</span><span class="delimiter">: </span><span class="description">compute a maximum absolute value incrementally.</span> |
| 134 | +- <span class="package-name">[`@stdlib/stats/incr/minabs`][@stdlib/stats/incr/minabs]</span><span class="delimiter">: </span><span class="description">compute a minimum absolute value incrementally.</span> |
| 135 | +- <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> |
| 136 | +- <span class="package-name">[`@stdlib/stats/incr/mminmaxabs`][@stdlib/stats/incr/mminmaxabs]</span><span class="delimiter">: </span><span class="description">compute moving minimum and maximum absolute values incrementally.</span> |
| 137 | + |
| 138 | +</section> |
| 139 | + |
| 140 | +<!-- /.related --> |
| 141 | + |
| 142 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 143 | + |
| 144 | +<section class="links"> |
| 145 | + |
| 146 | +<!-- <related-links> --> |
| 147 | + |
| 148 | +[@stdlib/stats/incr/maxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/maxabs |
| 149 | + |
| 150 | +[@stdlib/stats/incr/minabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/minabs |
| 151 | + |
| 152 | +[@stdlib/stats/incr/minmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/minmax |
| 153 | + |
| 154 | +[@stdlib/stats/incr/mminmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mminmaxabs |
| 155 | + |
| 156 | +<!-- </related-links> --> |
| 157 | + |
| 158 | +</section> |
| 159 | + |
| 160 | +<!-- /.links --> |
0 commit comments