README.md (2844B)
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 # incrmmin 22 23 > Compute a moving minimum value incrementally. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var incrmmin = require( '@stdlib/stats/incr/mmin' ); 31 ``` 32 33 #### incrmmin( 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. 36 37 ```javascript 38 var accumulator = incrmmin( 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( 3.0 ); // [2.0, 1.0, 3.0] 59 // returns 1.0 60 61 // Window begins sliding... 62 m = accumulator( -7.0 ); // [1.0, 3.0, -7.0] 63 // returns -7.0 64 65 m = accumulator( -5.0 ); // [3.0, -7.0, -5.0] 66 // returns -7.0 67 68 m = accumulator(); 69 // returns -7.0 70 ``` 71 72 </section> 73 74 <!-- /.usage --> 75 76 <section class="notes"> 77 78 ## Notes 79 80 - Input values are **not** type checked. If provided `NaN`, the accumulated value is `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. 81 - 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. 82 83 </section> 84 85 <!-- /.notes --> 86 87 <section class="examples"> 88 89 ## Examples 90 91 <!-- eslint no-undef: "error" --> 92 93 ```javascript 94 var randu = require( '@stdlib/random/base/randu' ); 95 var incrmmin = require( '@stdlib/stats/incr/mmin' ); 96 97 var accumulator; 98 var v; 99 var i; 100 101 // Initialize an accumulator: 102 accumulator = incrmmin( 5 ); 103 104 // For each simulated datum, update the moving minimum... 105 for ( i = 0; i < 100; i++ ) { 106 v = randu() * 100.0; 107 accumulator( v ); 108 } 109 console.log( accumulator() ); 110 ``` 111 112 </section> 113 114 <!-- /.examples --> 115 116 <section class="links"> 117 118 </section> 119 120 <!-- /.links -->