README.md (2226B)
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 # incrmax 22 23 > Compute a maximum value incrementally. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var incrmax = require( '@stdlib/stats/incr/max' ); 31 ``` 32 33 #### incrmax() 34 35 Returns an accumulator `function` which incrementally computes a maximum value. 36 37 ```javascript 38 var accumulator = incrmax(); 39 ``` 40 41 #### accumulator( \[x] ) 42 43 If provided an input value `x`, the accumulator function returns an updated maximum value. If not provided an input value `x`, the accumulator function returns the current maximum value. 44 45 ```javascript 46 var accumulator = incrmax(); 47 48 var max = accumulator( 2.0 ); 49 // returns 2.0 50 51 max = accumulator( 1.0 ); 52 // returns 2.0 53 54 max = accumulator( 3.0 ); 55 // returns 3.0 56 57 max = accumulator(); 58 // returns 3.0 59 ``` 60 61 </section> 62 63 <!-- /.usage --> 64 65 <section class="notes"> 66 67 ## Notes 68 69 - Input values are **not** type checked. If provided `NaN`, the accumulated value is `NaN` for **all** 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. 70 71 </section> 72 73 <!-- /.notes --> 74 75 <section class="examples"> 76 77 ## Examples 78 79 <!-- eslint no-undef: "error" --> 80 81 ```javascript 82 var randu = require( '@stdlib/random/base/randu' ); 83 var incrmax = require( '@stdlib/stats/incr/max' ); 84 85 var accumulator; 86 var v; 87 var i; 88 89 // Initialize an accumulator: 90 accumulator = incrmax(); 91 92 // For each simulated datum, update the max... 93 for ( i = 0; i < 100; i++ ) { 94 v = randu() * 100.0; 95 accumulator( v ); 96 } 97 console.log( accumulator() ); 98 ``` 99 100 </section> 101 102 <!-- /.examples --> 103 104 <section class="links"> 105 106 </section> 107 108 <!-- /.links -->