From cbce54477e092786444037379265fa2c0ac1668d Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 14:52:09 +0530 Subject: [PATCH 01/11] feat: setup `stats/incr/nanmrmse` --- 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 --- --- .../@stdlib/stats/incr/nanmrmse/lib/index.js | 63 +++++++++++++ .../@stdlib/stats/incr/nanmrmse/lib/main.js | 91 +++++++++++++++++++ .../@stdlib/stats/incr/nanmrmse/package.json | 87 ++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js new file mode 100644 index 000000000000..9e56c893729d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js @@ -0,0 +1,63 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* Compute a moving root mean squared error (RMSE) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmrmse +* +* @example +* var incrnanmrmse = require( '@stdlib/stats/incr/nanmrmse' ); +* +* var accumulator = incrnanmrmse( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator( NaN ); +* // returns 5.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns ~4.12 +* +* r = accumulator( 5.0, -2.0 ); +* // returns ~5.74 +* +* r = accumulator( 5.0 ); +* // returns ~5.74 +* +* r = accumulator(); +* // returns ~5.74 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js new file mode 100644 index 000000000000..414c2cf814fd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmrmse = require( '@stdlib/stats/incr/mrmse' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving root mean squared error, ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmrmse( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator( NaN ); +* // returns 5.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns ~4.12 +* +* r = accumulator( 5.0, -2.0 ); +* // returns ~5.74 +* +* r = accumulator( 5.0 ); +* // returns ~5.74 +* +* r = accumulator(); +* // returns ~5.74 +*/ +function incrnanmrmse( W ) { + var acc = incrmrmse( W ); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated root mean squared error. If not provided input values, the accumulator function returns the current root mean squared error. + * + * @private + * @param {number} [x] - input value + * @param {number} [y] - input value + * @returns {(number|null)} root mean squared error or null + */ + function accumulator( x, y ) { + if ( arguments.length === 0 ) { + return acc(); + } + + if ( arguments.length < 2 || isnan( x ) || isnan( y ) ) { + return acc(); + } + + return acc( x, y ); + } +} + + +// EXPORTS // + +module.exports = incrnanmrmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json b/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json new file mode 100644 index 000000000000..6f6ef1234e7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json @@ -0,0 +1,87 @@ +{ + "name": "@stdlib/stats/incr/nanmrmse", + "version": "0.0.0", + "description": "Compute a moving root mean squared error (RMSE) 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", + "error", + "err", + "rmse", + "rmsd", + "mse", + "msd", + "residuals", + "squares", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving", + "time series", + "timeseries", + "forecasting", + "forecast", + "model", + "selection", + "evaluation", + "prediction", + "ignore", + "nan" + ] +} From c541ec9a9e51f0869188c37055c21c705ca9518a Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:01:59 +0530 Subject: [PATCH 02/11] 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/nanmrmse/README.md | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md new file mode 100644 index 000000000000..63f3c8e8d391 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md @@ -0,0 +1,181 @@ + + +# incrnanmrmse + +> Compute a moving [root mean squared error][root-mean-squared-error] (RMSE) incrementally, ignoring `NaN` values. + +
+ +For a window of size `W`, the [**root mean squared error**][root-mean-squared-error] (also known as the **root mean square error** (RMSE) and **root mean square deviation** (RMSD)) is defined as + + + +```math +\mathop{\mathrm{RMSE}} = \sqrt{ \frac{1}{W} \sum_{i=0}^{W-1} (y_i - x_i)^2 } +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmrmse = require( '@stdlib/stats/incr/nanmrmse' ); +``` + +#### incrnanmrmse( window ) + +Returns an accumulator `function` which incrementally computes a moving [root mean squared error][root-mean-squared-error]. The `window` parameter defines the number of values over which to compute the moving [root mean squared error][root-mean-squared-error]. + +```javascript +var accumulator = incrnanmrmse( 3 ); +``` + +#### accumulator( \[x, y] ) + +If provided input values `x` and `y`, the accumulator function returns an updated [root mean squared error][root-mean-squared-error]. If not provided input values `x` and `y`, the accumulator function returns the current [root mean squared error][root-mean-squared-error]. + +```javascript +var accumulator = incrnanmrmse( 3 ); + +var r = accumulator(); +// returns null + +// Fill the window... +r = accumulator( 2.0, 3.0 ); // [(2.0,3.0)] +// returns 1.0 + +r = accumulator( -1.0, 4.0 ); // [(2.0,3.0), (-1.0,4.0)] +// returns ~3.61 + +r = accumulator( 3.0, 9.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] +// returns ~4.55 + +// Ignore 'NaN' +r = accumulator( NaN ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] +// returns ~4.55 + +// Window begins sliding... +r = accumulator( -7.0, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] +// returns ~7.33 + +// Ignore `undefined` begin passed +r = accumulator( -7.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] +// returns ~7.33 + +r = accumulator( -5.0, -3.0 ); // [(3.0,9.0), (-7.0,3.0), (-5.0,-3.0)] +// returns ~6.83 + +r = accumulator(); +// returns ~6.83 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, returns the currently accumulated value. 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` (x,y) pairs 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 incrnanmrmse = require( '@stdlib/stats/incr/nanmrmse' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmrmse( 5 ); + +// For each simulated datum, update the moving root mean squared error... +for ( i = 0; i < 100; i++ ) { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + accumulator( v1, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + From 918df18ca7b11915c196fe72ca5d02a508d4e73c Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:08:45 +0530 Subject: [PATCH 03/11] docs: add ts 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: 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 --- --- .../stats/incr/nanmrmse/docs/types/index.d.ts | 80 +++++++++++++++++++ .../stats/incr/nanmrmse/docs/types/test.ts | 74 +++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts new file mode 100644 index 000000000000..6518a2b04abb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts @@ -0,0 +1,80 @@ +/* +* @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 input values, the accumulator function returns an updated root mean squared error. If not provided input values, the accumulator function returns the current root mean squared error. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the currently accumulated value returned. +* +* @param x - input value +* @param y - input value +* @returns root mean squared error or null +*/ +type accumulator = ( x?: number, y?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving root mean squared error, ignoring `NaN` values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving root mean squared error. +* - 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 = incrnanmrmse( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator( NaN ); +* // returns 5.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns ~4.12 +* +* r = accumulator( 5.0, -2.0 ); +* // returns ~5.74 +* +* r = accumulator( 5.0 ); +* // returns ~5.74 +* +* r = accumulator(); +* // returns ~5.74 +*/ +declare function incrnanmrmse( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmrmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/test.ts new file mode 100644 index 000000000000..cb1126089b83 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/test.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +import incrnanmrmse = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmrmse( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + incrnanmrmse( '5' ); // $ExpectError + incrnanmrmse( true ); // $ExpectError + incrnanmrmse( false ); // $ExpectError + incrnanmrmse( null ); // $ExpectError + incrnanmrmse( undefined ); // $ExpectError + incrnanmrmse( [] ); // $ExpectError + incrnanmrmse( {} ); // $ExpectError + incrnanmrmse( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmrmse(); // $ExpectError + incrnanmrmse( 2, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmrmse( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14, 2.0 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmrmse( 3 ); + + acc( '5', 2.0 ); // $ExpectError + acc( true, 2.0 ); // $ExpectError + acc( false, 2.0 ); // $ExpectError + acc( null, 2.0 ); // $ExpectError + acc( [], 2.0 ); // $ExpectError + acc( {}, 2.0 ); // $ExpectError + acc( ( x: number ): number => x, 2.0 ); // $ExpectError + + acc( 3.14, '5' ); // $ExpectError + acc( 3.14, true ); // $ExpectError + acc( 3.14, false ); // $ExpectError + acc( 3.14, null ); // $ExpectError + acc( 3.14, [] ); // $ExpectError + acc( 3.14, {} ); // $ExpectError + acc( 3.14, ( x: number ): number => x ); // $ExpectError +} From 6399cc77fb8cab08549306929f1990ca70448fab Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:13:53 +0530 Subject: [PATCH 04/11] docs: 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/nanmrmse/examples/index.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js new file mode 100644 index 000000000000..13fa95f15fd1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmrmse = require( './../lib' ); + +var accumulator; +var rmse; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmrmse( 5 ); + +// For each simulated datum, update the moving root mean squared error... +console.log( '\nValue\tValue\tRMSE\n' ); +for ( i = 0; i < 100; i++ ) { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + rmse = accumulator( v1, v2 ); + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), rmse.toFixed( 3 ) ); +} From 75c25b44f15cc7d27edef1cc15350573abc5e63a Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:16:21 +0530 Subject: [PATCH 05/11] bench: add benchmark --- 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/nanmrmse/benchmark/benchmark.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/benchmark/benchmark.js new file mode 100644 index 000000000000..c317c295cc1d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @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. +*/ + +'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 incrnanmrmse = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmrmse( (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 = incrnanmrmse( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()-0.5, randu()-0.5 ); + 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 2f6d5067fb11a638683116cf401d50a3f88412a3 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:35:20 +0530 Subject: [PATCH 06/11] test: add tests for `NaN`, `undefined` args --- 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 --- --- .../@stdlib/stats/incr/nanmrmse/test/test.js | 276 ++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js new file mode 100644 index 000000000000..b9874023008d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js @@ -0,0 +1,276 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanmrmse = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmrmse, '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; + 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() { + incrnanmrmse( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanmrmse( 3 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving root mean squared error incrementally', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var N; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -1.0 ], + [ 2.0, 5.0 ], + [ 4.0, -4.0 ], + [ 3.0, 0.0 ], + [ -4.0, 5.0 ] + ]; + N = data.length; + + acc = incrnanmrmse( 3 ); + + expected = [ + 1.0, + sqrt( 17.0/2.0 ), + sqrt( 26.0/3.0 ), + sqrt( 89.0/3.0 ), + sqrt( 82.0/3.0 ), + sqrt( 154.0/3.0 ) + ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[i][0], data[i][1] ); + if ( actual === expected[i] ) { + t.strictEqual( actual, expected[i], 'returns expected value' ); + } else { + delta = abs( expected[i] - actual ); + tol = 1.0 * EPS * abs( expected[i] ); + t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected[i]+'. Delta: '+delta+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current root mean squared error', function test( t ) { + var data; + var acc; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -5.0 ], + [ 1.0, 10.0 ] + ]; + acc = incrnanmrmse( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[i][0], data[i][1] ); + } + t.strictEqual( acc(), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an input value that results in `NaN`, the accumulator function returns the current root mean squared error', function test( t ) { + var data; + var acc; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -5.0 ], + [ 1.0, 10.0 ] + ]; + acc = incrnanmrmse( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[i][0], data[i][1] ); + } + t.strictEqual( acc( NaN ), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.strictEqual( acc( 10.0 ), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmrmse( 3 ); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invocations', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + 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 + ]; + + 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 ], + [ NaN, 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 ], + [ NaN, 3.14 ], + [ NaN, 3.14 ], + [ NaN, 3.14 ], + [ NaN, 3.14 ], + [ 3.14, 3.14 ] + ]; + + acc = incrnanmrmse( 3 ); + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[i][0], data[i][1] ); + t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); + t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); + } + + 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 + ]; + + data = [ + [ 3.14, 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, NaN ], + [ 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, NaN ], + [ 3.14, NaN ], + [ 3.14, NaN ], + [ 3.14, NaN ], + [ 3.14, 3.14 ] + ]; + + acc = incrnanmrmse( 3 ); + + for ( i = 0; i < data.length; i++ ) { + v = acc( data[i][0], data[i][1] ); + if ( isnan( expected[ i ] ) ) { + t.strictEqual( isnan( v ), true, 'returns expected value for window '+i ); + t.strictEqual( isnan( acc() ), true, 'returns expected value for window '+i ); + } else { + 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 f83732db040c339ef570851a0103ace2dce46589 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 29 Jul 2026 15:37:50 +0530 Subject: [PATCH 07/11] 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 --- --- .../@stdlib/stats/incr/nanmrmse/docs/repl.txt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt new file mode 100644 index 000000000000..3af8fd0fa813 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving root + mean squared error (RMSE), ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving root mean squared error. + + If provided a value, the accumulator function returns an updated moving root + mean squared error. If not provided a value, the accumulator function + returns the current moving root mean squared error. + + 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 r = accumulator() + null + > r = accumulator( 2.0, 3.0 ) + 1.0 + > r = accumulator( -5.0, 2.0 ) + 5.0 + > r = accumulator( NaN ) + 5.0 + > r = accumulator( 3.0, 2.0 ) + ~4.12 + > r = accumulator( 5.0, -2.0 ) + ~5.74 + > r = accumulator( 5.0 ) + ~5.74 + > r = accumulator() + ~5.74 + + See Also + -------- + From d49a8a5226029ff7ad505e9057d552eacd55363f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 00:42:59 -0500 Subject: [PATCH 08/11] chore: leave related packages empty Co-authored-by: Philipp Burckhardt Signed-off-by: Philipp Burckhardt --- .../@stdlib/stats/incr/nanmrmse/README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md index 63f3c8e8d391..0a9c8e7abf78 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md @@ -148,13 +148,6 @@ console.log( accumulator() ); @@ -168,12 +161,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/mmse]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmse - -[@stdlib/stats/incr/mrss]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mrss - -[@stdlib/stats/incr/rmse]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/rmse - From 1654d982426e97522412b7440ab3d81f2cbfd601 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 00:43:23 -0500 Subject: [PATCH 09/11] chore: remove empty line Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md index 0a9c8e7abf78..1d7ff59600d2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md @@ -147,8 +147,6 @@ console.log( accumulator() ); From 14f1c1f00698414b51495cf0a260b9f2c848f1da Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 01:28:44 -0500 Subject: [PATCH 10/11] chore: add empty line Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md index 1d7ff59600d2..727a9d3d27d3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md @@ -147,6 +147,7 @@ console.log( accumulator() ); From fcc5ba68056eef21f01dc67b5730238ed72fb498 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 4 Aug 2026 01:35:28 -0500 Subject: [PATCH 11/11] fix: align NaN semantics and conventions with sibling nan* packages - Remove non-conventional single-argument special-casing in main.js; use the standard combined guard and rename inner var to 'mrmse' - Replace single-argument NaN examples with two-argument NaN pairs in JSDoc, repl.txt, index.d.ts, and README - Rewrite test suite to correct NaN-ignoring expectations and cover (NaN,y), (x,NaN), (NaN,NaN), and only-NaN cases - Inject NaN values in examples/index.js and README examples with guarded printing - Fix Notes wording in README - Remove non-standard 'ignore' keyword from package.json --- .../@stdlib/stats/incr/nanmrmse/README.md | 20 ++- .../@stdlib/stats/incr/nanmrmse/docs/repl.txt | 6 +- .../stats/incr/nanmrmse/docs/types/index.d.ts | 12 +- .../stats/incr/nanmrmse/examples/index.js | 10 +- .../@stdlib/stats/incr/nanmrmse/lib/index.js | 8 +- .../@stdlib/stats/incr/nanmrmse/lib/main.js | 21 ++- .../@stdlib/stats/incr/nanmrmse/package.json | 5 +- .../@stdlib/stats/incr/nanmrmse/test/test.js | 134 +++--------------- 8 files changed, 51 insertions(+), 165 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md index 727a9d3d27d3..7f836d2e1a40 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/README.md @@ -53,7 +53,7 @@ var incrnanmrmse = require( '@stdlib/stats/incr/nanmrmse' ); #### incrnanmrmse( window ) -Returns an accumulator `function` which incrementally computes a moving [root mean squared error][root-mean-squared-error]. The `window` parameter defines the number of values over which to compute the moving [root mean squared error][root-mean-squared-error]. +Returns an accumulator `function` which incrementally computes a moving [root mean squared error][root-mean-squared-error]. The `window` parameter defines the number of values over which to compute the moving [root mean squared error][root-mean-squared-error], ignoring `NaN` values. ```javascript var accumulator = incrnanmrmse( 3 ); @@ -79,18 +79,13 @@ r = accumulator( -1.0, 4.0 ); // [(2.0,3.0), (-1.0,4.0)] r = accumulator( 3.0, 9.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] // returns ~4.55 -// Ignore 'NaN' -r = accumulator( NaN ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] +r = accumulator( NaN, 5.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] (NaN pair ignored) // returns ~4.55 // Window begins sliding... r = accumulator( -7.0, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] // returns ~7.33 -// Ignore `undefined` begin passed -r = accumulator( -7.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] -// returns ~7.33 - r = accumulator( -5.0, -3.0 ); // [(3.0,9.0), (-7.0,3.0), (-5.0,-3.0)] // returns ~6.83 @@ -106,8 +101,8 @@ r = accumulator(); ## Notes -- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, returns the currently accumulated value. 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` (x,y) pairs 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. +- Input values are **not** type checked. If provided `NaN` for either value, the pair is ignored and the accumulator function returns the current [root mean squared error][root-mean-squared-error] without updating the window. 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` (x,y) pairs 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 (excluding NaN values). @@ -120,7 +115,8 @@ r = accumulator(); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var incrnanmrmse = require( '@stdlib/stats/incr/nanmrmse' ); var accumulator; @@ -133,8 +129,8 @@ accumulator = incrnanmrmse( 5 ); // For each simulated datum, update the moving root mean squared error... for ( i = 0; i < 100; i++ ) { - v1 = ( randu()*100.0 ) - 50.0; - v2 = ( randu()*100.0 ) - 50.0; + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ); + v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ); accumulator( v1, v2 ); } console.log( accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt index 3af8fd0fa813..5c512e364e44 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/repl.txt @@ -33,14 +33,14 @@ 1.0 > r = accumulator( -5.0, 2.0 ) 5.0 - > r = accumulator( NaN ) + > r = accumulator( NaN, 2.0 ) 5.0 > r = accumulator( 3.0, 2.0 ) ~4.12 + > r = accumulator( 3.0, NaN ) + ~4.12 > r = accumulator( 5.0, -2.0 ) ~5.74 - > r = accumulator( 5.0 ) - ~5.74 > r = accumulator() ~5.74 diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts index 6518a2b04abb..d67a02508c04 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/docs/types/index.d.ts @@ -23,10 +23,6 @@ /** * If provided input values, the accumulator function returns an updated root mean squared error. If not provided input values, the accumulator function returns the current root mean squared error. * -* ## Notes -* -* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the currently accumulated value returned. -* * @param x - input value * @param y - input value * @returns root mean squared error or null @@ -57,16 +53,16 @@ type accumulator = ( x?: number, y?: number ) => number | null; * r = accumulator( -5.0, 2.0 ); * // returns 5.0 * -* r = accumulator( NaN ); +* r = accumulator( NaN, 2.0 ); * // returns 5.0 * * r = accumulator( 3.0, 2.0 ); * // returns ~4.12 * -* r = accumulator( 5.0, -2.0 ); -* // returns ~5.74 +* r = accumulator( 3.0, NaN ); +* // returns ~4.12 * -* r = accumulator( 5.0 ); +* r = accumulator( 5.0, -2.0 ); * // returns ~5.74 * * r = accumulator(); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js index 13fa95f15fd1..1f95910fcc2b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/examples/index.js @@ -18,7 +18,9 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanmrmse = require( './../lib' ); var accumulator; @@ -33,8 +35,8 @@ accumulator = incrnanmrmse( 5 ); // For each simulated datum, update the moving root mean squared error... console.log( '\nValue\tValue\tRMSE\n' ); for ( i = 0; i < 100; i++ ) { - v1 = ( randu()*100.0 ) - 50.0; - v2 = ( randu()*100.0 ) - 50.0; + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ); + v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -50.0, 50.0 ); rmse = accumulator( v1, v2 ); - console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), rmse.toFixed( 3 ) ); + console.log( '%s\t%s\t%s', ( isnan( v1 ) ) ? 'NaN' : v1.toFixed( 3 ), ( isnan( v2 ) ) ? 'NaN' : v2.toFixed( 3 ), ( rmse === null ) ? 'null' : rmse.toFixed( 3 ) ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js index 9e56c893729d..97dc57cc36e2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/index.js @@ -37,16 +37,16 @@ * r = accumulator( -5.0, 2.0 ); * // returns 5.0 * -* r = accumulator( NaN ); +* r = accumulator( NaN, 2.0 ); * // returns 5.0 * * r = accumulator( 3.0, 2.0 ); * // returns ~4.12 * -* r = accumulator( 5.0, -2.0 ); -* // returns ~5.74 +* r = accumulator( 3.0, NaN ); +* // returns ~4.12 * -* r = accumulator( 5.0 ); +* r = accumulator( 5.0, -2.0 ); * // returns ~5.74 * * r = accumulator(); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js index 414c2cf814fd..ca31dcd41a4b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/lib/main.js @@ -45,23 +45,23 @@ var incrmrmse = require( '@stdlib/stats/incr/mrmse' ); * r = accumulator( -5.0, 2.0 ); * // returns 5.0 * -* r = accumulator( NaN ); +* r = accumulator( NaN, 2.0 ); * // returns 5.0 * * r = accumulator( 3.0, 2.0 ); * // returns ~4.12 * -* r = accumulator( 5.0, -2.0 ); -* // returns ~5.74 +* r = accumulator( 3.0, NaN ); +* // returns ~4.12 * -* r = accumulator( 5.0 ); +* r = accumulator( 5.0, -2.0 ); * // returns ~5.74 * * r = accumulator(); * // returns ~5.74 */ function incrnanmrmse( W ) { - var acc = incrmrmse( W ); + var mrmse = incrmrmse( W ); return accumulator; /** @@ -73,15 +73,10 @@ function incrnanmrmse( W ) { * @returns {(number|null)} root mean squared error or null */ function accumulator( x, y ) { - if ( arguments.length === 0 ) { - return acc(); + if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { + return mrmse(); } - - if ( arguments.length < 2 || isnan( x ) || isnan( y ) ) { - return acc(); - } - - return acc( x, y ); + return mrmse( x, y ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json b/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json index 6f6ef1234e7f..5e86656aa98c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/package.json @@ -61,6 +61,7 @@ "rmsd", "mse", "msd", + "nan", "residuals", "squares", "deviation", @@ -80,8 +81,6 @@ "model", "selection", "evaluation", - "prediction", - "ignore", - "nan" + "prediction" ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js index b9874023008d..e27b7ece3d82 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrmse/test/test.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -71,7 +70,7 @@ tape( 'the function returns an accumulator function', function test( t ) { t.end(); }); -tape( 'the accumulator function computes a moving root mean squared error incrementally', function test( t ) { +tape( 'the accumulator function computes a moving root mean squared error incrementally, ignoring `NaN` values', function test( t ) { var expected; var actual; var delta; @@ -85,8 +84,10 @@ tape( 'the accumulator function computes a moving root mean squared error increm [ 2.0, 3.0 ], [ 3.0, -1.0 ], [ 2.0, 5.0 ], + [ NaN, 5.0 ], [ 4.0, -4.0 ], [ 3.0, 0.0 ], + [ 3.0, NaN ], [ -4.0, 5.0 ] ]; N = data.length; @@ -97,8 +98,10 @@ tape( 'the accumulator function computes a moving root mean squared error increm 1.0, sqrt( 17.0/2.0 ), sqrt( 26.0/3.0 ), + sqrt( 26.0/3.0 ), sqrt( 89.0/3.0 ), sqrt( 82.0/3.0 ), + sqrt( 82.0/3.0 ), sqrt( 154.0/3.0 ) ]; for ( i = 0; i < N; i++ ) { @@ -122,6 +125,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr data = [ [ 2.0, 3.0 ], [ 3.0, -5.0 ], + [ 3.0, NaN ], [ 1.0, 10.0 ] ]; acc = incrnanmrmse( 2 ); @@ -132,7 +136,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr t.end(); }); -tape( 'if provided an input value that results in `NaN`, the accumulator function returns the current root mean squared error', function test( t ) { +tape( 'if provided `NaN`, the accumulator function ignores the input value pair and returns the current root mean squared error', function test( t ) { var data; var acc; var i; @@ -146,8 +150,9 @@ tape( 'if provided an input value that results in `NaN`, the accumulator functio for ( i = 0; i < data.length; i++ ) { acc( data[i][0], data[i][1] ); } - t.strictEqual( acc( NaN ), sqrt( 145.0/2.0 ), 'returns expected value' ); - t.strictEqual( acc( 10.0 ), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.strictEqual( acc( NaN, 2.0 ), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.strictEqual( acc( 2.0, NaN ), sqrt( 145.0/2.0 ), 'returns expected value' ); + t.strictEqual( acc( NaN, NaN ), sqrt( 145.0/2.0 ), 'returns expected value' ); t.end(); }); @@ -157,120 +162,13 @@ tape( 'if data has yet to be provided, the accumulator function returns `null`', t.end(); }); -tape( 'if provided `NaN`, the accumulated value is `NaN` for at least `W` invocations', function test( t ) { - var expected; - var data; - var acc; - var v; - var i; - - 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 - ]; - - 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 ], - [ NaN, 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 ], - [ NaN, 3.14 ], - [ NaN, 3.14 ], - [ NaN, 3.14 ], - [ NaN, 3.14 ], - [ 3.14, 3.14 ] - ]; - - acc = incrnanmrmse( 3 ); - - for ( i = 0; i < data.length; i++ ) { - v = acc( data[i][0], data[i][1] ); - t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); - t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); - } - - 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 - ]; - - data = [ - [ 3.14, 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, NaN ], - [ 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, NaN ], - [ 3.14, NaN ], - [ 3.14, NaN ], - [ 3.14, NaN ], - [ 3.14, 3.14 ] - ]; +tape( 'if only `NaN` values have been provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmrmse( 3 ); - acc = incrnanmrmse( 3 ); + acc( NaN, 3.14 ); + acc( 3.14, NaN ); + acc( NaN, NaN ); - for ( i = 0; i < data.length; i++ ) { - v = acc( data[i][0], data[i][1] ); - if ( isnan( expected[ i ] ) ) { - t.strictEqual( isnan( v ), true, 'returns expected value for window '+i ); - t.strictEqual( isnan( acc() ), true, 'returns expected value for window '+i ); - } else { - t.strictEqual( v, expected[ i ], 'returns expected value for window '+i ); - t.strictEqual( acc(), expected[ i ], 'returns expected value for window '+i ); - } - } + t.strictEqual( acc(), null, 'returns expected value' ); t.end(); });