From 247d316ca9ca4122faae7c47781a39fea6c83172 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 07:47:17 +0530 Subject: [PATCH 1/9] feat: package setup --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanmvariance/lib/index.js | 57 ++++++++++++ .../stats/incr/nanmvariance/lib/main.js | 90 +++++++++++++++++++ .../stats/incr/nanmvariance/package.json | 76 ++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/package.json diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js new file mode 100644 index 000000000000..bc1da1b65fc4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 unbiased sample variance incrementally. +* +* @module @stdlib/stats/incr/nanmvariance +* +* @example +* var incrnanmvariance = require( '@stdlib/stats/incr/nanmvariance' ); +* +* var accumulator = incrnanmvariance( 3 ); +* +* var s2 = accumulator(); +* // returns null +* +* s2 = accumulator( 2.0 ); +* // returns 0.0 +* +* s2 = accumulator( -5.0 ); +* // returns 24.5 +* +* s2 = accumulator( 3.0 ); +* // returns 19.0 +* +* s2 = accumulator( 5.0 ); +* // returns 28.0 +* +* s2 = accumulator(); +* // returns 28.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js new file mode 100644 index 000000000000..ed6bb2fe8efa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js @@ -0,0 +1,90 @@ +/** +* @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 incrmvariance = require( '@stdlib/stats/incr/mvariance' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving unbiased sample variance, ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @param {number} [mean] - mean value +* @throws {TypeError} first argument must be a positive integer +* @throws {TypeError} second argument must be a number +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmvariance( 3 ); +* +* var s2 = accumulator(); +* // returns null +* +* s2 = accumulator( 2.0 ); +* // returns 0.0 +* +* s2 = accumulator( -5.0 ); +* // returns 24.5 +* +* s2 = accumulator( 3.0 ); +* // returns 19.0 +* +* s2 = accumulator( 5.0 ); +* // returns 28.0 +* +* s2 = accumulator(); +* // returns 28.0 +* +* @example +* var accumulator = incrnanmvariance( 3, -2.0 ); +*/ +function incrnanmvariance( W, mean ) { + var acc; + + if ( arguments.length > 1 ) { + acc = incrmvariance( W, mean ); + } else { + acc = incrmvariance( W ); + } + return accumulator; + + /** + * If provided a value, returns an updated unbiased sample variance. If not provided a value or provided a `NaN` value, returns the current unbiased sample variance. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} unbiased sample variance or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return acc(); + } + return acc( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmvariance; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/package.json b/lib/node_modules/@stdlib/stats/incr/nanmvariance/package.json new file mode 100644 index 000000000000..4ec4f178a2e1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/incr/nanmvariance", + "version": "0.0.0", + "description": "Compute a moving unbiased sample variance 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", + "variance", + "sample", + "sample variance", + "unbiased", + "stdev", + "standard", + "deviation", + "dispersion", + "incremental", + "accumulator", + "moving variance", + "sliding window", + "sliding", + "window", + "moving", + "nan", + "ignore" + ] +} From 7b16e6c5b34f4a28921eab5164c0cf04fd4222c7 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 10:26:27 +0530 Subject: [PATCH 2/9] feat: setup base tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../incr/nanmvariance/docs/types/index.d.ts | 77 +++++ .../stats/incr/nanmvariance/test/test.js | 293 ++++++++++++++++++ 2 files changed, 370 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/index.d.ts new file mode 100644 index 000000000000..e64caadc8529 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/index.d.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 unbiased sample variance; otherwise, returns the current unbiased sample variance. +* +* ## Notes +* +* - If provided `NaN` value which, when used in computations, results in `NaN`, the accumulator returns the current unbiased variance. +* +* @param x - value +* @returns unbiased sample variance +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving unbiased sample variance, ignoring `NaN` values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving unbiased sample variance. +* - 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 +* @param mean - mean value +* @throws first argument must be a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrnanmvariance( 3 ); +* +* var s2 = accumulator(); +* // returns null +* +* s2 = accumulator( 2.0 ); +* // returns 0.0 +* +* s2 = accumulator( -5.0 ); +* // returns 24.5 +* +* s2 = accumulator( 3.0 ); +* // returns 19.0 +* +* s2 = accumulator( 5.0 ); +* // returns 28.0 +* +* s2 = accumulator(); +* // returns 28.0 +* +* @example +* var accumulator = incrnanmvariance( 3, -2.0 ); +*/ +declare function incrnanmvariance( W: number, mean?: number ): accumulator; + + +// EXPORTS // + +export = incrnanmvariance; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js new file mode 100644 index 000000000000..193ee6a5863a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js @@ -0,0 +1,293 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrnanmvariance = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmvariance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer for the window size', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmvariance( value ); + }; + } +}); + +tape( 'the function throws an error if not provided a positive integer for the window size (known mean)', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmvariance( value, 3.0 ); + }; + } +}); + +tape( 'the function throws an error if not provided a number as the mean value', function test( t ) { + var values; + var i; + + values = [ + '5', + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmvariance( 3, value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanmvariance( 3 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (known mean)', function test( t ) { + t.strictEqual( typeof incrnanmvariance( 3, 3.0 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving unbiased sample variance incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 4.0, -1.0, 3.0, 1.0 ]; + N = data.length; + + acc = incrnanmvariance( 3 ); + + actual = zeros( N ); + for ( i = 0; i < N; i++ ) { + actual[ i ] = acc( data[ i ] ); + } + expected = [ 0.0, 0.5, 1.0, 7.0, 7.0, 4.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving unbiased sample variance incrementally (known mean)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 4.0, -1.0, 3.0, 1.0 ]; + N = data.length; + + acc = incrnanmvariance( 3, 2.0 ); + + actual = zeros( N ); + for ( i = 0; i < N; i++ ) { + actual[ i ] = acc( data[ i ] ); + } + expected = [ + 0.0, + 0.5, + 1.6666666666666667, + 4.666666666666667, + 4.666666666666667, + 3.6666666666666665 + ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 2.0, 3.0, 10.0 ]; + acc = incrnanmvariance( 3 ); + for ( i = 0; i < data.length-1; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc(), 0.5, 'returns current unbiased sample variance' ); + + acc( data[ data.length-1 ] ); + + expected = 19.0; + actual = acc(); + delta = abs( actual - expected ); + tol = EPS * expected; + + t.strictEqual( delta < tol, true, 'expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance (known mean)', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 2.0, 3.0, 10.0 ]; + acc = incrnanmvariance( 3, 5.0 ); + for ( i = 0; i < data.length-1; i++ ) { + acc( data[ i ] ); + } + t.strictEqual( acc(), 6.5, 'returns current unbiased sample variance' ); + + acc( data[ data.length-1 ] ); + + expected = 12.666666666666666; + actual = acc(); + delta = abs( actual - expected ); + tol = EPS * expected; + + t.strictEqual( delta < tol, true, 'expected: '+expected+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmvariance( 3 ); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null` (known mean)', function test( t ) { + var acc = incrnanmvariance( 3, 3.0 ); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'if only one datum has been provided and the mean is unknown, the accumulator function returns `0`', function test( t ) { + var acc = incrnanmvariance( 3 ); + acc( 2.0 ); + t.strictEqual( acc(), 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if only one datum has been provided and the mean is known, the accumulator function may not return `0`', function test( t ) { + var acc = incrnanmvariance( 3, 30 ); + acc( 2.0 ); + t.notEqual( acc(), 0.0, 'does not return 0' ); + t.end(); +}); + +tape( 'if the window size is `1` and the mean is unknown, the accumulator function always returns `0`', function test( t ) { + var acc; + var s2; + var i; + + acc = incrnanmvariance( 1 ); + for ( i = 0; i < 100; i++ ) { + s2 = acc( randu() * 100.0 ); + t.strictEqual( s2, 0.0, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if the window size is `1` and the mean is known, the accumulator function may not always return `0`', function test( t ) { + var acc; + var s2; + var i; + + acc = incrnanmvariance( 1, 500.0 ); // mean is outside the range of simulated values so the variance should never be zero + for ( i = 0; i < 100; i++ ) { + s2 = acc( randu() * 100.0 ); + t.notEqual( s2, 0.0, 'does not return 0' ); + } + t.end(); +}); From 94525b10c833fe66a27ad3075dedae774495b12d Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:11:22 +0530 Subject: [PATCH 3/9] fix: add `NaN` behaviour tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanmvariance/test/test.js | 238 ++++++++++++++++++ 1 file changed, 238 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js index 193ee6a5863a..57ebd2104575 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/test/test.js @@ -291,3 +291,241 @@ tape( 'if the window size is `1` and the mean is known, the accumulator function } t.end(); }); + +tape( 'if provided `NaN`, the currently accumulated value is returned (unknown mean)', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmvariance( 3 ); + + data = [ + NaN, + 3.14, // 3.14 + 3.14, // 3.14, 3.14 + NaN, // 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 + NaN, // 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 + NaN, // 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, 3.14 + NaN, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14, 3.14 + 3.14 // 3.14, 3.14, 3.14 + ]; + expected = [ + null, + 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.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); + t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); + } + t.end(); +}); + +tape( 'if provided `NaN`, the currently accumulated value is returned (known mean)', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmvariance( 3, 3.14 ); + + data = [ + NaN, + 3.14, // 3.14 + 3.14, // 3.14, 3.14 + NaN, // 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 + NaN, // 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 + NaN, // 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, 3.14 + NaN, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14, 3.14 + NaN, // 3.14, 3.14, 3.14 + 3.14 // 3.14, 3.14, 3.14 + ]; + expected = [ + null, + 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.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); + t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); + } + t.end(); +}); + +tape( 'if provided `NaN`, the currently accumulated value returned (unknown mean, W=1)', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmvariance( 1 ); + + data = [ + NaN, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 + ]; + expected = [ + null, + 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.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); + t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); + } + t.end(); +}); + +tape( 'if provided `NaN`, the currently accumulated value returned (known mean)', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmvariance( 1, 3.14 ); + + data = [ + NaN, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 + ]; + expected = [ + null, + 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.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); + t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); + } + t.end(); +}); From 0d87283b8ee113c1a917f09d207cb13f65c90cbd Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:16:13 +0530 Subject: [PATCH 4/9] feat: add benchmark.js --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../incr/nanmvariance/benchmark/benchmark.js | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/benchmark/benchmark.js new file mode 100644 index 000000000000..5d6350a81788 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/benchmark/benchmark.js @@ -0,0 +1,92 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var incrnanmvariance = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmvariance( (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( format( '%s::accumulator', pkg ), function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmvariance( 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(); +}); + +bench( format( '%s::accumulator,known_mean', pkg ), function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmvariance( 5, 0.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(); +}); From 3aa7c8b587f2cdcb6d6c0cf45228238fd1894424 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:19:36 +0530 Subject: [PATCH 5/9] feat: add examples --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanmvariance/examples/index.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/examples/index.js new file mode 100644 index 000000000000..77aa13bbb096 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/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 incrnanmvariance = require( './../lib' ); + +var accumulator; +var s2; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmvariance( 5 ); + +// For each simulated datum, update the moving unbiased sample variance ignoring `NaN` values... +console.log( '\nValue\tSample Variance\n' ); +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + s2 = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), s2.toFixed( 4 ) ); +} From a0f9bb2ea762246a37bf613963fcb46790418070 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:25:51 +0530 Subject: [PATCH 6/9] feat: add docs/types/test.ts --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../incr/nanmvariance/docs/types/test.ts | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/test.ts new file mode 100644 index 000000000000..ff12831b1236 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/types/test.ts @@ -0,0 +1,77 @@ +/* +* @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 incrnanmvariance = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmvariance( 3 ); // $ExpectType accumulator + incrnanmvariance( 3, 0.0 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + incrnanmvariance( '5' ); // $ExpectError + incrnanmvariance( true ); // $ExpectError + incrnanmvariance( false ); // $ExpectError + incrnanmvariance( null ); // $ExpectError + incrnanmvariance( [] ); // $ExpectError + incrnanmvariance( {} ); // $ExpectError + incrnanmvariance( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + incrnanmvariance( 3, '5' ); // $ExpectError + incrmvariance( 3, true ); // $ExpectError + incrnanmvariance( 3, false ); // $ExpectError + incrnanmvariance( 3, null ); // $ExpectError + incrnanmvariance( 3, [] ); // $ExpectError + incrnanmvariance( 3, {} ); // $ExpectError + incrnanmvariance( 3, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmvariance(); // $ExpectError + incrnanmvariance( 3, 2.5, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmvariance( 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 = incrnanmvariance( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} From 2166d0412c02226d1030a45bb1c4128523f7d730 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:50:01 +0530 Subject: [PATCH 7/9] docs: add README.md --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmvariance/README.md | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/README.md diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/README.md b/lib/node_modules/@stdlib/stats/incr/nanmvariance/README.md new file mode 100644 index 000000000000..6a5f7404c455 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/README.md @@ -0,0 +1,183 @@ + + +# incrnanmvariance + +> Compute a moving [unbiased sample variance][sample-variance] incrementally, ignoring `NaN` values. + +
+ +For a window of size `W`, the [unbiased sample variance][sample-variance] is defined as + + + +```math +s^2 = \frac{1}{W-1} \sum_{i=0}^{W-1} ( x_i - \bar{x} )^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmvariance = require( '@stdlib/stats/incr/nanmvariance' ); +``` + +#### incrnanmvariance( window\[, mean] ) + +Returns an accumulator `function` which incrementally computes a moving [unbiased sample variance][sample-variance]. The `window` parameter defines the number of values over which to compute the moving [unbiased sample variance][sample-variance], ignoring `NaN` values. + +```javascript +var accumulator = incrnanmvariance( 3 ); +``` + +If the mean is already known, provide a `mean` argument. + +```javascript +var accumulator = incrnanmvariance( 3, 5.0 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [unbiased sample variance][sample-variance]. If not provided an input value `x` or provided a `NaN` value, the accumulator function returns the current [unbiased sample variance][sample-variance]. + +```javascript +var accumulator = incrnanmvariance( 3 ); + +var s2 = accumulator(); +// returns null + +// Fill the window... +s2 = accumulator( 2.0 ); // [2.0] +// returns 0.0 + +s2 = accumulator( 1.0 ); // [2.0, 1.0] +// returns 0.5 + +s2 = accumulator( NaN ); // [2.0, 1.0] +// returns 0.5 + +s2 = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns 1.0 + +// Window begins sliding... +s2 = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns 28.0 + +s2 = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns 28.0 + +s2 = accumulator(); +// returns 28.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `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. +- 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 incrnanmvariance = require( '@stdlib/stats/incr/nanmvariance' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmvariance( 5 ); + +// For each simulated datum, update the moving unbiased sample variance... +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + From 6a0129da8d2f540f920af1a6acc697bd0a2bf5d2 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 13:54:38 +0530 Subject: [PATCH 8/9] docs: add repl.txt --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanmvariance/docs/repl.txt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/repl.txt diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/repl.txt new file mode 100644 index 000000000000..2d2f711b5729 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( W[, mean] ) + Returns an accumulator function which incrementally computes a moving + unbiased sample variance, ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving unbiased sample variance. + + If provided a value, the accumulator function returns an updated moving + unbiased sample variance. If not provided a value or provided a `NaN` + value, the accumulator function returns the current moving unbiased + sample variance. + + 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. + + mean: number (optional) + Known mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var s2 = accumulator() + null + > s2 = accumulator( 2.0 ) + 0.0 + > s2 = accumulator( -5.0 ) + 24.5 + > s2 = accumulator( NaN ) + 24.5 + > s2 = accumulator( 3.0 ) + 19.0 + > s2 = accumulator( 5.0 ) + 28.0 + > s2 = accumulator() + 28.0 + + See Also + -------- + From 1c94f6c539abe88d51e55c8e09b3d61f0660491f Mon Sep 17 00:00:00 2001 From: Arjan Date: Sat, 25 Jul 2026 05:45:37 +0530 Subject: [PATCH 9/9] docs: update JSDocs in /lib files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmvariance/lib/index.js | 5 ++++- lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js index bc1da1b65fc4..000f371854f0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute a moving unbiased sample variance incrementally. +* Compute a moving unbiased sample variance incrementally, ignoring `NaN` values. * * @module @stdlib/stats/incr/nanmvariance * @@ -37,6 +37,9 @@ * s2 = accumulator( -5.0 ); * // returns 24.5 * +* s2 = accumulator( NaN ); +* // returns 24.5 +* * s2 = accumulator( 3.0 ); * // returns 19.0 * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js index ed6bb2fe8efa..028d6f93f957 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmvariance/lib/main.js @@ -47,6 +47,9 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * s2 = accumulator( -5.0 ); * // returns 24.5 * +* s2 = accumulator( NaN ); +* // returns 24.5 +* * s2 = accumulator( 3.0 ); * // returns 19.0 *