diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/README.md b/lib/node_modules/@stdlib/stats/incr/nanmidrange/README.md new file mode 100644 index 000000000000..d9393a29f81c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/README.md @@ -0,0 +1,161 @@ +<!-- + +@license Apache-2.0 + +Copyright (c) 2025 The Stdlib Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> + +# incrnanmidrange + +> Compute a [mid-range][mid-range] incrementally, ignoring `NaN` values. + +<section class="intro"> + +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. + +</section> + +<!-- /.intro --> + +<section class="usage"> + +## Usage + +```javascript +var incrnanmidrange = require( '@stdlib/stats/incr/nanmidrange' ); +``` + +#### incrnanmidrange() + +Returns an accumulator `function` which incrementally computes a [mid-range][mid-range], ignoring `NaN` values. + +```javascript +var accumulator = incrnanmidrange(); +``` + +#### accumulator( \[x] ) + +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]. + +```javascript +var accumulator = incrnanmidrange(); + +var midrange = accumulator(); +// returns null + +midrange = accumulator( -2.0 ); +// returns -2.0 + +midrange = accumulator( NaN ); +// returns -2.0 + +midrange = accumulator( 1.0 ); +// returns -0.5 + +midrange = accumulator( 3.0 ); +// returns 0.5 + +midrange = accumulator(); +// returns 0.5 +``` + +</section> + +<!-- /.usage --> + +<section class="notes"> + +## Notes + +- 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. + +</section> + +<!-- /.notes --> + +<section class="examples"> + +## Examples + +<!-- eslint no-undef: "error" --> + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanmidrange = require( '@stdlib/stats/incr/nanmidrange' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmidrange(); + +// For each simulated datum, update the mid-range... +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + accumulator( v ); +} +console.log( accumulator() ); +``` + +</section> + +<!-- /.examples --> + +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> + +<section class="related"> + +* * * + +## See Also + +- <span class="package-name">[`@stdlib/stats/incr/mean`][@stdlib/stats/incr/mean]</span><span class="delimiter">: </span><span class="description">compute an arithmetic mean incrementally.</span> +- <span class="package-name">[`@stdlib/stats/incr/max`][@stdlib/stats/incr/max]</span><span class="delimiter">: </span><span class="description">compute a maximum value incrementally.</span> +- <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> +- <span class="package-name">[`@stdlib/stats/incr/range`][@stdlib/stats/incr/range]</span><span class="delimiter">: </span><span class="description">compute a range incrementally.</span> +- <span class="package-name">[`@stdlib/stats/incr/summary`][@stdlib/stats/incr/summary]</span><span class="delimiter">: </span><span class="description">compute a statistical summary incrementally.</span> + +</section> + +<!-- /.related --> + +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> + +<section class="links"> + +[range]: https://en.wikipedia.org/wiki/Range_%28statistics%29 + +[mid-range]: https://en.wikipedia.org/wiki/Mid-range + +<!-- <related-links> --> + +[@stdlib/stats/incr/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mean + +[@stdlib/stats/incr/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/max + +[@stdlib/stats/incr/min]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/min + +[@stdlib/stats/incr/range]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/range + +[@stdlib/stats/incr/summary]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/summary + +<!-- </related-links> --> + +</section> + +<!-- /.links --> diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmidrange/benchmark/benchmark.js new file mode 100644 index 000000000000..97671f982eb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmidrange = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmidrange(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmidrange(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/repl.txt new file mode 100644 index 000000000000..1e575b964272 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/repl.txt @@ -0,0 +1,37 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a mid-range, + ignoring `NaN` values. + + The mid-range is the arithmetic mean of maximum and minimum values. + Accordingly, the mid-range is the midpoint of the range and a measure of + central tendency. + + If provided a value, the accumulator function returns an updated mid-range. + If not provided a value, the accumulator function returns the current mid- + range. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var v = accumulator() + null + > v = accumulator( 3.14 ) + 3.14 + > v = accumulator( NaN ) + 3.14 + > v = accumulator( -5.0 ) + ~-0.93 + > v = accumulator( 10.1 ) + 2.55 + > v = accumulator() + 2.55 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/Test.ts b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/Test.ts new file mode 100644 index 000000000000..a03167d45fa3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/Test.ts @@ -0,0 +1,63 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanmidrange = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmidrange(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanmidrange( '5' ); // $ExpectError + incrnanmidrange( 5 ); // $ExpectError + incrnanmidrange( true ); // $ExpectError + incrnanmidrange( false ); // $ExpectError + incrnanmidrange( null ); // $ExpectError + incrnanmidrange( undefined ); // $ExpectError + incrnanmidrange( [] ); // $ExpectError + incrnanmidrange( {} ); // $ExpectError + incrnanmidrange( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmidrange(); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null + acc( 5 ); // $ExpectType number | null + acc( -2 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmidrange(); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/index.d.ts new file mode 100644 index 000000000000..71f14eefcc2c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// <reference types="@stdlib/types"/> + +/** +* If provided a value, returns an updated mid-range; otherwise, returns the current mid-range. +* +* ## Notes +* +* - The mid-range is the arithmetic mean of maximum and minimum values. Accordingly, the mid-range is the midpoint of the range and a measure of central tendency. +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* +* @param x - value +* @returns mid-range +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a mid-range, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanmidrange(); +* +* var midrange = accumulator(); +* // returns null +* +* midrange = accumulator( 3.14 ); +* // returns 3.14 +* +* midrange = accumulator( -5.0 ); +* // returns ~-0.93 +* +* midrange = accumulator( 10.1 ); +* // returns 2.55 +* +* midrange = accumulator(); +* // returns 2.55 +*/ +declare function incrnanmidrange(): accumulator; + + +// EXPORTS // + +export = incrnanmidrange; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmidrange/examples/index.js new file mode 100644 index 000000000000..56a03abd8016 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmidrange = require( './../lib' ); + +var accumulator; +var midrange; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmidrange(); + +// For each simulated datum, update the mid-range... +console.log( '\nValue\tMid-range\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + midrange = accumulator( v ); + if ( midrange === null ) { + console.log( '%d\t%s', v.toFixed( 4 ), midrange ); + } else { + console.log( '%d\t%d', ( isnan( v ) ) ? NaN : v.toFixed( 4 ), midrange.toFixed( 4 ) ); + } +} +console.log( '\nFinal mid-range: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/index.js new file mode 100644 index 000000000000..bbeb443d5df0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a mid-range incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmidrange +* +* @example +* var incrnanmidrange = require( '@stdlib/stats/incr/nanmidrange' ); +* +* var accumulator = incrnanmidrange(); +* +* var midrange = accumulator(); +* // returns null +* +* midrange = accumulator( 3.14 ); +* // returns 3.14 +* +* midrange = accumulator( NaN ); +* // returns 3.14 +* +* midrange = accumulator( -5.0 ); +* // returns ~-0.93 +* +* midrange = accumulator( 10.1 ); +* // returns 2.55 +* +* midrange = accumulator(); +* // returns 2.55 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/main.js new file mode 100644 index 000000000000..007776633549 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/lib/main.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmidrange = require( '@stdlib/stats/incr/midrange' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a mid-range, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmidrange(); +* +* var midrange = accumulator(); +* // returns null +* +* midrange = accumulator( 3.14 ); +* // returns 3.14 +* +* midrange = accumulator( NaN ); +* // returns 3.14 +* +* midrange = accumulator( -5.0 ); +* // returns ~-0.93 +* +* midrange = accumulator( 10.1 ); +* // returns 2.55 +* +* midrange = accumulator(); +* // returns 2.55 +*/ +function incrnanmidrange() { + var midrange = incrmidrange(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated mid-range. If not provided a value, the accumulator function returns the current mid-range. + * + * @private + * @param {number} [x] - new value + * @returns {number} mid-range + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return midrange(); + } + return midrange( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmidrange; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/package.json b/lib/node_modules/@stdlib/stats/incr/nanmidrange/package.json new file mode 100644 index 000000000000..e087aa31594f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/incr/nanmidrange", + "version": "0.0.0", + "description": "Compute a mid-range incrementally, ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "maximum", + "max", + "minimum", + "min", + "mid", + "range", + "mid-range", + "mid-extreme", + "mean", + "central tendency", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmidrange/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmidrange/test/test.js new file mode 100644 index 000000000000..c0c177de28d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmidrange/test/test.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmidrange = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmidrange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmidrange(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'if not provided any values, the initial returned mid-range is `null`', function test( t ) { + var acc = incrnanmidrange(); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a mid-range', function test( t ) { + var expected; + var actual; + var data; + var acc; + var max; + var min; + var N; + var d; + var i; + + data = [ 2.0, NaN, 3.0, -2.0, NaN, 4.0, -3.0, 4.0 ]; + N = data.length; + + expected = []; + actual = []; + + acc = incrnanmidrange(); + + max = null; + min = null; + + for ( i = 0; i < N; i++ ) { + d = data[ i ]; + + if ( !isnan( d ) ) { + if ( max === null || d > max ) { + max = d; + } + if ( min === null || d < min ) { + min = d; + } + } + + if ( max !== null && min !== null ) { + expected.push( ( max + min ) / 2.0 ); + } else { + expected.push( null ); + } + + actual.push( acc( d ) ); + } + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current mid-range', function test( t ) { + var data; + var acc; + var i; + + data = [ -2.0, 3.0, NaN, 1.0 ]; + acc = incrnanmidrange(); + + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + + t.equal( acc(), 0.5, 'returns the current accumulated mid-range' ); + t.end(); +});