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