|
| 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 | +# incrnanmin |
| 22 | + |
| 23 | +> Compute a minimum value incrementally, ignoring `NaN` values. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var incrnanmin = require( '@stdlib/stats/incr/nanmin' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### incrnanmin() |
| 34 | + |
| 35 | +Returns an accumulator `function` which incrementally computes a minimum value, ignoring `NaN` values. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var accumulator = incrnanmin(); |
| 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 = incrnanmin(); |
| 47 | + |
| 48 | +var min = accumulator( 2.0 ); |
| 49 | +// returns 2.0 |
| 50 | + |
| 51 | +min = accumulator( 1.0 ); |
| 52 | +// returns 1.0 |
| 53 | + |
| 54 | +min = accumulator( NaN ); |
| 55 | +// returns 1.0 |
| 56 | + |
| 57 | +min = accumulator( 3.0 ); |
| 58 | +// returns 1.0 |
| 59 | + |
| 60 | +min = accumulator(); |
| 61 | +// returns 1.0 |
| 62 | +``` |
| 63 | + |
| 64 | +</section> |
| 65 | + |
| 66 | +<!-- /.usage --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +## Notes |
| 71 | + |
| 72 | +- 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. |
| 73 | +- If all provided values are `NaN`, the accumulator returns `null`. |
| 74 | + |
| 75 | +</section> |
| 76 | + |
| 77 | +<!-- /.notes --> |
| 78 | + |
| 79 | +<section class="examples"> |
| 80 | + |
| 81 | +## Examples |
| 82 | + |
| 83 | +```javascript |
| 84 | +var bernoulli = require( '@stdlib/random/base/bernoulli' ); |
| 85 | +var uniform = require( '@stdlib/random/base/uniform' ); |
| 86 | +var incrnanmin = require( '@stdlib/stats/incr/nanmin' ); |
| 87 | + |
| 88 | +var accumulator; |
| 89 | +var v; |
| 90 | +var i; |
| 91 | + |
| 92 | +// Initialize an accumulator: |
| 93 | +accumulator = incrnanmin(); |
| 94 | + |
| 95 | +// For each simulated datum, update the min... |
| 96 | +for ( i = 0; i < 100; i++ ) { |
| 97 | + if ( bernoulli( 0.2 ) ) { |
| 98 | + v = NaN; |
| 99 | + } else { |
| 100 | + v = uniform( 0.0, 100.0 ); |
| 101 | + } |
| 102 | + accumulator( v ); |
| 103 | +} |
| 104 | +console.log( accumulator() ); |
| 105 | +``` |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.examples --> |
| 110 | + |
| 111 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 112 | + |
| 113 | +<section class="related"> |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.related --> |
| 118 | + |
| 119 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 120 | + |
| 121 | +<section class="links"> |
| 122 | + |
| 123 | +<!-- <related-links> --> |
| 124 | + |
| 125 | +<!-- </related-links> --> |
| 126 | + |
| 127 | +</section> |
| 128 | + |
| 129 | +<!-- /.links --> |
0 commit comments