From 3e1ae00ce94dd6d8588750a0a59b8c5892aae8c1 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 12:33:44 +0530 Subject: [PATCH 1/8] Added benchmark file --- .../@stdlib/stats/incr/nanmmin/README.md | 0 .../stats/incr/nanmmin/benchmark/benchmark.js | 69 +++++++++++++++++++ .../@stdlib/stats/incr/nanmmin/package.json | 0 3 files changed, 69 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/package.json diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js new file mode 100644 index 000000000000..d394a80d5bb5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanmmin = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmin( (i%5)+1 ); + 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 = incrnanmmin( 5 ); + + 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/nanmmin/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json new file mode 100644 index 000000000000..e69de29bb2d1 From a97976b666d4b4a8e5be904267997c3370e5929c Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 12:58:04 +0530 Subject: [PATCH 2/8] added the lib --- .../@stdlib/stats/incr/mmin/lib/main.js | 161 +++++++++--------- .../@stdlib/stats/incr/nanmmin/lib/index.js | 60 +++++++ .../@stdlib/stats/incr/nanmmin/lib/main.js | 151 ++++++++++++++++ 3 files changed, 289 insertions(+), 83 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js diff --git a/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js b/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js index 4cd1a1ead424..ed6e099bc8cd 100644 --- a/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/mmin/lib/main.js @@ -58,94 +58,89 @@ var format = require( '@stdlib/string/format' ); * m = accumulator(); * // returns -5.0 */ -function incrmmin( W ) { - var buf; - var min; - var N; - var i; - if ( !isPositiveInteger( W ) ) { - throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); - } - buf = new Float64Array( W ); - min = PINF; - i = -1; - N = 0; +function incrnanmmin( W ) { + var buf; + var min; + var N; + var i; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + buf = new Float64Array( W ); + min = PINF; + i = -1; + N = 0; - return accumulator; + return accumulator; - /** - * If provided a value, the accumulator function returns an updated minimum. If not provided a value, the accumulator function returns the current minimum. - * - * @private - * @param {number} [x] - input value - * @returns {(number|null)} minimum value or null - */ - function accumulator( x ) { - var v; - var k; - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - return min; - } - // Update the index for managing the circular buffer: - i = (i+1) % W; + /** + * If provided a value, the accumulator function returns an updated minimum, ignoring NaN values. If not provided a value, the accumulator function returns the current minimum. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} minimum value or null + */ + function accumulator( x ) { + var v; + var k; + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return min; + } + if ( isnan( x ) ) { + return min; // Ignore NaN values and return current minimum + } - // Case: update initial window... - if ( N < W ) { - N += 1; - if ( - isnan( x ) || - x < min || - ( x === min && isNegativeZero( x ) ) - ) { - min = x; - } - } - // Case: incoming value is NaN or less than current minimum value... - else if ( isnan( x ) || x < min ) { - min = x; - } - // Case: outgoing value is the current minimum and the new value is greater than the minimum, and, thus, we need to find a new minimum among the current values... - else if ( ( buf[ i ] === min && x > min ) || isnan( buf[ i ] ) ) { - min = x; - for ( k = 0; k < W; k++ ) { - if ( k !== i ) { - v = buf[ k ]; - if ( isnan( v ) ) { - min = v; - break; // no need to continue searching - } - if ( v < min || ( v === min && isNegativeZero( v ) ) ) { - min = v; - } - } - } - } - // Case: outgoing value is the current minimum, which is zero, and the new value is also zero, and, thus, we need to correctly handle signed zeros... - else if ( buf[ i ] === min && x === min && x === 0.0 ) { - if ( isNegativeZero( x ) ) { - min = x; - } else if ( isNegativeZero( buf[ i ] ) ) { - // Because the outgoing and incoming are different signs (-,+), we need to search the buffer to see if it contains a negative zero. If so, the minimum value remains negative zero; otherwise, the minimum value is incoming value... - min = x; - for ( k = 0; k < W; k++ ) { - if ( k !== i && isNegativeZero( buf[ k ] ) ) { - min = buf[ k ]; - break; - } - } - } - // Case: the outgoing and incoming values are both positive zero, so nothing changes - } - // Case: updating existing window; however, the minimum value does not change so nothing to do but update our buffer... + // Update the index for managing the circular buffer: + i = (i + 1) % W; - buf[ i ] = x; - return min; - } -} + // Case: update initial window... + if ( N < W ) { + N += 1; + if ( x < min || ( x === min && isNegativeZero( x ) ) ) { + min = x; + } + } + // Case: incoming value is less than current minimum value... + else if ( x < min ) { + min = x; + } + // Case: outgoing value is the current minimum and the new value is greater than the minimum, requiring a new minimum search... + else if ( buf[ i ] === min && x > min ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i ) { + v = buf[ k ]; + if ( isnan( v ) ) { + continue; // Ignore NaN values + } + if ( v < min || ( v === min && isNegativeZero( v ) ) ) { + min = v; + } + } + } + } + // Case: handling signed zero differences... + else if ( buf[ i ] === min && x === min && x === 0.0 ) { + if ( isNegativeZero( x ) ) { + min = x; + } else if ( isNegativeZero( buf[ i ] ) ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i && isNegativeZero( buf[ k ] ) ) { + min = buf[ k ]; + break; + } + } + } + } + buf[ i ] = x; + return min; + } +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js new file mode 100644 index 000000000000..94e77e1fff9c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 moving minimum incrementally. ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmmin +* +* @example +* var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); +* +* var accumulator = incrnanmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( NaN ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js new file mode 100644 index 000000000000..bbd8edb1504b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var Float64Array = require( '@stdlib/array/float64' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving minimum value. ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( NaN ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ +function incrnanmmin( W ) { + var buf; + var min; + var N; + var i; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + buf = new Float64Array( W ); + min = PINF; + i = -1; + N = 0; + + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated minimum, ignoring NaN values. If not provided a value, the accumulator function returns the current minimum. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} minimum value or null + */ + function accumulator( x ) { + var v; + var k; + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return min; + } + if ( isnan( x ) ) { + return min; // Ignore NaN values and return current minimum + } + + // Update the index for managing the circular buffer: + i = (i + 1) % W; + + // Case: update initial window... + if ( N < W ) { + N += 1; + if ( x < min || ( x === min && isNegativeZero( x ) ) ) { + min = x; + } + } + // Case: incoming value is less than current minimum value... + else if ( x < min ) { + min = x; + } + // Case: outgoing value is the current minimum and the new value is greater than the minimum, requiring a new minimum search... + else if ( buf[ i ] === min && x > min ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i ) { + v = buf[ k ]; + if ( isnan( v ) ) { + continue; // Ignore NaN values + } + if ( v < min || ( v === min && isNegativeZero( v ) ) ) { + min = v; + } + } + } + } + // Case: handling signed zero differences... + else if ( buf[ i ] === min && x === min && x === 0.0 ) { + if ( isNegativeZero( x ) ) { + min = x; + } else if ( isNegativeZero( buf[ i ] ) ) { + min = x; + for ( k = 0; k < W; k++ ) { + if ( k !== i && isNegativeZero( buf[ k ] ) ) { + min = buf[ k ]; + break; + } + } + } + } + + buf[ i ] = x; + return min; + } +} + + +// EXPORTS // + +module.exports = incrnanmmin; From 1b8777a05b15122c95c4c405ade30be021131410 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 13:03:43 +0530 Subject: [PATCH 3/8] added the example --- .../stats/incr/nanmmin/examples/index.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js new file mode 100644 index 000000000000..af5234886ea6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); +var incrnanmmin = require( './../lib' ); + +var accumulator; +var m; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmin( 5 ); + +// For each simulated datum, update the moving minimum... +console.log( '\nValue\tMin\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; + m = accumulator( v ); + console.log( '%s\t%s', isnan( v ) ? 'NaN' : v.toFixed( 4 ), m !== null ? m.toFixed( 4 ) : 'null' ); +} From a59e05ea2b57428db7efcc37f45b69fa13f54f9c Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 13:38:03 +0530 Subject: [PATCH 4/8] added docs --- .../@stdlib/stats/incr/nanmmin/docs/repl.txt | 47 ++++++++++++ .../stats/incr/nanmmin/docs/types/index.d.ts | 72 +++++++++++++++++++ .../stats/incr/nanmmin/docs/types/test.ts | 66 +++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt new file mode 100644 index 000000000000..bbedb222f504 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/repl.txt @@ -0,0 +1,47 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + minimum value. ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving minimum. + + If provided a value, the accumulator function returns an updated moving + minimum. If not provided a value, the accumulator function returns the + current moving minimum. + + 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. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var m = accumulator() + null + > m = accumulator( 2.0 ) + 2.0 + > m = accumulator( -5.0 ) + -5.0 + > m = accumulator( NaN ) + -5.0 + > m = accumulator( 3.0 ) + -5.0 + > m = accumulator( 5.0 ) + -5.0 + > m = accumulator() + -5.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts new file mode 100644 index 000000000000..7fff1d86d8af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts @@ -0,0 +1,72 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 + +/// + +/** +* If provided a value, returns an updated minimum value; otherwise, returns the current minimum value. +* +* @param x - value +* @returns minimum value +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving minimum value. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving minimum. +* - 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. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmmin( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0 ); +* // returns 2.0 +* +* m = accumulator( -5.0 ); +* // returns -5.0 +* +* m = accumulator( NaN ); +* // returns -5.0 +* +* m = accumulator( 3.0 ); +* // returns -5.0 +* +* m = accumulator( 5.0 ); +* // returns -5.0 +* +* m = accumulator(); +* // returns -5.0 +*/ +declare function incrnanmmin( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmin; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts new file mode 100644 index 000000000000..e5f9da7557b8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 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 incrnanmmin = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmin( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + incrnanmmin( '5' ); // $ExpectError + incrnanmmin( true ); // $ExpectError + incrnanmmin( false ); // $ExpectError + incrnanmmin( null ); // $ExpectError + incrnanmmin( undefined ); // $ExpectError + incrnanmmin( [] ); // $ExpectError + incrnanmmin( {} ); // $ExpectError + incrnanmmin( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmmin(); // $ExpectError + incrnanmmin( 3, 2 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmin( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmmin( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} From 1d8dbbb27575c1afad98fa78c96cee74de2a0457 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 13:53:20 +0530 Subject: [PATCH 5/8] added readme and package --- .../@stdlib/stats/incr/nanmmin/README.md | 157 ++++++++++++++++++ .../@stdlib/stats/incr/nanmmin/package.json | 72 ++++++++ 2 files changed, 229 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md index e69de29bb2d1..05c7eb20444e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md @@ -0,0 +1,157 @@ + + +# incrnanmmin + +> Compute a moving minimum value incrementally, ignoring `NaN` values. + +
+ +## Usage + +```javascript +var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); +``` + +#### incrnanmmin( window ) + +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, ignoring `NaN` values. + +```javascript +var accumulator = incrnanmmin( 3 ); +``` + +#### accumulator( \[x] ) + +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. + +```javascript +var accumulator = incrmmin( 3 ); + +var m = accumulator(); +// returns null + +// Fill the window... +m = accumulator( 2.0 ); // [2.0] +// returns 2.0 + +m = accumulator( 1.0 ); // [2.0, 1.0] +// returns 1.0 + +m = accumulator( NaN ); +// returns 1.0 + +m = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns 1.0 + +// Window begins sliding... +m = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns -7.0 + +m = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns -7.0 + +m = accumulator(); +// returns -7.0 +``` + +
+ + + +
+ +## 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. +- 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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmmin = require( '@stdlib/stats/incr/nanmmin' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmin( 5 ); + +// For each simulated datum, update the moving minimum... +for ( i = 0; i < 100; i++ ) { + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json index e69de29bb2d1..4bb62dfc5f07 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/stats/incr/nanmmin", + "version": "0.0.0", + "description": "Compute a moving minimum 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", + "minimum", + "min", + "extreme", + "extent", + "range", + "incremental", + "accumulator", + "moving min", + "sliding window", + "sliding", + "window", + "moving" + ] + } + \ No newline at end of file From dedd615be95aae68b5fb5839673b5c615c6a5cf5 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 14:48:44 +0530 Subject: [PATCH 6/8] added tests --- .../@stdlib/stats/incr/nanmmin/test/test.js | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js new file mode 100644 index 000000000000..9f673fed3e17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js @@ -0,0 +1,225 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanmmin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + values.forEach( function( value ) { + t.throws( function() { incrnanmmin( value ); }, TypeError, 'throws an error when provided ' + value ); + }); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmmin( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving minimum incrementally, ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, 4.0, 2.0, NaN, 2.0, 2.0, 2.0, 1.0, 4.0 ]; + N = data.length; + + acc = incrnanmmin( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0, 1.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results while ignoring NaN values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current minimum value while ignoring NaN values', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, NaN, 5.0, 4.0 ]; + acc = incrnanmmin( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 4.0, 'returns expected value while ignoring NaN values' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmmin( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles signed zeros while ignoring NaNs', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmin( 3 ); + + data = [ + 0.0, // 0 + -0.0, // 0, -0 + NaN, // ignored + 0.0, // 0, -0, 0 + NaN, // ignored + -0.0, // -0, 0, -0 + 0.0, // 0, -0, 0 + NaN, // ignored + -0.0, // -0, 0, -0 + 0.0, // 0, -0, 0 + -0.0, // -0, 0, -0 + -0.0, // -0, -0, -0 + 0.0 // -0, -0, 0 + ]; + + expected = [ + 0.0, + -0.0, + -0.0, // NaN ignored + -0.0, + -0.0, // NaN ignored + -0.0, + -0.0, + -0.0, // NaN ignored + -0.0, + -0.0, + -0.0, + -0.0, + -0.0 + ]; + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( isnan( data[i] ) ) { + continue; + } + if ( isNegativeZero( expected[ i ] ) ) { + t.equal( isNegativeZero( v ), true, 'returns expected value for window ' + i ); + } else { + t.equal( isPositiveZero( v ), true, 'returns expected value for window ' + i ); + } + } + t.end(); +}); + +tape( 'if provided `NaN`, the accumulated value ignores `NaN` and computes the minimum over valid values', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmin( 3 ); + + data = [ + NaN, // ignored + 3.14, // 3.14 + 3.14, // 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + 3.14, // 3.14, 3.14, 3.14 + 3.14, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14 (NaN ignored) + NaN, // 3.14 (NaN ignored) + NaN, // (NaN ignored) + NaN, // (NaN ignored) + 3.14 // 3.14 + ]; + + expected = [ + null, // No valid numbers yet + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14, + 3.14 + ]; + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( expected[ i ] === null ) { + t.equal( v, null, 'returns expected value for window ' + i ); + } else { + t.equal( v, expected[ i ], 'returns expected value for window ' + i ); + } + } + t.end(); +}); \ No newline at end of file From 33e1412656762edda4e523d0c96a9058eed7ae67 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Fri, 7 Mar 2025 15:20:56 +0530 Subject: [PATCH 7/8] edit --- .../stats/incr/nanmmin/examples/index.js | 1 + .../@stdlib/stats/incr/nanmmin/test/test.js | 71 +++++++++---------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js index af5234886ea6..02a1ba94d78d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js @@ -20,6 +20,7 @@ var randu = require( '@stdlib/random/base/randu' ); var incrnanmmin = require( './../lib' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var accumulator; var m; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js index 9f673fed3e17..eac6627f634d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js @@ -105,58 +105,51 @@ tape( 'if data has yet to be provided, the accumulator function returns `null`', t.end(); }); -tape( 'the accumulator function correctly handles signed zeros while ignoring NaNs', function test( t ) { +tape( 'the accumulator function computes a moving minimum incrementally, ignoring NaN values', function test( t ) { var expected; + var actual; var data; var acc; - var v; + var N; var i; - acc = incrnanmmin( 3 ); + data = [ 2.0, NaN, 3.0, 2.0, NaN, 4.0, 3.0, NaN, 4.0, 2.0, 2.0, NaN, 1.0, 4.0 ]; + N = data.length; - data = [ - 0.0, // 0 - -0.0, // 0, -0 - NaN, // ignored - 0.0, // 0, -0, 0 - NaN, // ignored - -0.0, // -0, 0, -0 - 0.0, // 0, -0, 0 - NaN, // ignored - -0.0, // -0, 0, -0 - 0.0, // 0, -0, 0 - -0.0, // -0, 0, -0 - -0.0, // -0, -0, -0 - 0.0 // -0, -0, 0 - ]; + acc = incrnanmmin( 3 ); // Moving window of size 3 + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + + // Expected minimum values, ignoring NaN expected = [ - 0.0, - -0.0, - -0.0, // NaN ignored - -0.0, - -0.0, // NaN ignored - -0.0, - -0.0, - -0.0, // NaN ignored - -0.0, - -0.0, - -0.0, - -0.0, - -0.0 + 2.0, // [ 2.0 ] + 2.0, // [ 2.0 ] (NaN ignored) + 2.0, // [ 2.0, 3.0 ] + 2.0, // [ 2.0, 3.0, 2.0 ] + 2.0, // [ 2.0, 3.0, 2.0 ] (NaN ignored) + 2.0, // [ 3.0, 2.0, 4.0 ] (window moves) + 2.0, // [ 2.0, 4.0, 3.0 ] + 2.0, // [ 2.0, 4.0, 3.0 ] (NaN ignored) + 3.0, // [ 4.0, 3.0, 4.0 ] + 2.0, // [ 3.0, 4.0, 2.0 ] + 2.0, // [ 4.0, 2.0, 2.0 ] + 2.0, // [ 4.0, 2.0, 2.0 ] (NaN ignored) + 1.0, // [ 2.0, 2.0, 1.0 ] + 1.0 // [ 2.0, 1.0, 4.0 ] ]; - for ( i = 0; i < data.length; i++ ) { - v = acc( data[ i ] ); - if ( isnan( data[i] ) ) { - continue; - } - if ( isNegativeZero( expected[ i ] ) ) { - t.equal( isNegativeZero( v ), true, 'returns expected value for window ' + i ); + // Check the computed values against the expected values + for ( i = 0; i < N; i++ ) { + if ( isNaN( expected[i] ) ) { + t.equal( isNaN(actual[i]), true, 'returns NaN at index ' + i ); } else { - t.equal( isPositiveZero( v ), true, 'returns expected value for window ' + i ); + t.equal( actual[i], expected[i], 'returns expected value at index ' + i ); } } + t.end(); }); From b47bf7f0c94a6ef8984ea354461e42ca1ecdbb8c Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Fri, 2 May 2025 11:47:27 +0000 Subject: [PATCH 8/8] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanmmin/README.md | 2 +- .../@stdlib/stats/incr/nanmmin/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanmmin/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md index 05c7eb20444e..01c13e7d7a6a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js index d394a80d5bb5..c642961e9f76 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts index 7fff1d86d8af..1a39f58b29b1 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts index e5f9da7557b8..41f6e6cc72fb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js index 02a1ba94d78d..ed2d627341a2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js index 94e77e1fff9c..c4127d796f6c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js index bbd8edb1504b..c48f2a941993 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js index eac6627f634d..08f3822512a7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmin/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* 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.