README.md (2771B)
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 # incrmidrange 22 23 > Compute a [mid-range][mid-range] incrementally. 24 25 <section class="intro"> 26 27 The [**mid-range**][mid-range], or **mid-extreme**, is the arithmetic mean of maximum and minimum values. Accordingly, the [mid-range][mid-range] is the midpoint of the [range][range] and a measure of central tendency. 28 29 </section> 30 31 <!-- /.intro --> 32 33 <section class="usage"> 34 35 ## Usage 36 37 ```javascript 38 var incrmidrange = require( '@stdlib/stats/incr/midrange' ); 39 ``` 40 41 #### incrmidrange() 42 43 Returns an accumulator `function` which incrementally computes a [mid-range][mid-range]. 44 45 ```javascript 46 var accumulator = incrmidrange(); 47 ``` 48 49 #### accumulator( \[x] ) 50 51 If provided an input value `x`, the accumulator function returns an updated [mid-range][mid-range]. If not provided an input value `x`, the accumulator function returns the current [mid-range][mid-range]. 52 53 ```javascript 54 var accumulator = incrmidrange(); 55 56 var midrange = accumulator(); 57 // returns null 58 59 midrange = accumulator( -2.0 ); 60 // returns -2.0 61 62 midrange = accumulator( 1.0 ); 63 // returns -0.5 64 65 midrange = accumulator( 3.0 ); 66 // returns 0.5 67 68 midrange = accumulator(); 69 // returns 0.5 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 **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. 81 82 </section> 83 84 <!-- /.notes --> 85 86 <section class="examples"> 87 88 ## Examples 89 90 <!-- eslint no-undef: "error" --> 91 92 ```javascript 93 var randu = require( '@stdlib/random/base/randu' ); 94 var incrmidrange = require( '@stdlib/stats/incr/midrange' ); 95 96 var accumulator; 97 var v; 98 var i; 99 100 // Initialize an accumulator: 101 accumulator = incrmidrange(); 102 103 // For each simulated datum, update the mid-range... 104 for ( i = 0; i < 100; i++ ) { 105 v = randu() * 100.0; 106 accumulator( v ); 107 } 108 console.log( accumulator() ); 109 ``` 110 111 </section> 112 113 <!-- /.examples --> 114 115 <section class="links"> 116 117 [range]: https://en.wikipedia.org/wiki/Range_%28statistics%29 118 119 [mid-range]: https://en.wikipedia.org/wiki/Mid-range 120 121 </section> 122 123 <!-- /.links -->