From 4648b771bd34ad3d60178b6c7405e921d7febcdc Mon Sep 17 00:00:00 2001 From: sanchay Date: Wed, 19 Mar 2025 09:15:08 +0000 Subject: [PATCH 1/3] feat: adding stats/incr/nanmmse --- 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 status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmmse/README.md | 181 ++++++++++++++++++ .../stats/incr/nanmmse/benchmark/benchmark.js | 69 +++++++ .../docs/img/equation_mean_squared_error.svg | 60 ++++++ .../@stdlib/stats/incr/nanmmse/docs/repl.txt | 49 +++++ .../stats/incr/nanmmse/docs/types/index.d.ts | 76 ++++++++ .../stats/incr/nanmmse/docs/types/test.ts | 74 +++++++ .../stats/incr/nanmmse/examples/index.js | 45 +++++ .../@stdlib/stats/incr/nanmmse/lib/index.js | 63 ++++++ .../@stdlib/stats/incr/nanmmse/lib/main.js | 94 +++++++++ .../@stdlib/stats/incr/nanmmse/package.json | 84 ++++++++ .../@stdlib/stats/incr/nanmmse/test/test.js | 133 +++++++++++++ 11 files changed, 928 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/docs/img/equation_mean_squared_error.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmse/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmse/README.md new file mode 100644 index 000000000000..708267f9b673 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/README.md @@ -0,0 +1,181 @@ + + +# incrnanmmse + +> Compute a moving [mean squared error][mean-squared-error] (MSE) incrementally, ignoring `NaN` values. + +
+ +For a window of size `W`, the [mean squared error][mean-squared-error] is defined as + + + +```math +\mathop{\mathrm{MSE}} = \frac{1}{W} \sum_{i=0}^{W-1} (y_i - x_i)^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmmse = require( '@stdlib/stats/incr/nanmmse' ); +``` + +#### incrnanmmse( window ) + +Returns an accumulator `function` which incrementally computes a moving [mean squared error][mean-squared-error]. The `window` parameter defines the number of values over which to compute the moving [mean squared error][mean-squared-error]. + +```javascript +var accumulator = incrnanmmse( 3 ); +``` + +#### accumulator( \[x, y] ) + +If provided input values `x` and `y`, the accumulator function returns an updated [mean squared error][mean-squared-error]. If not provided input values `x` and `y`, the accumulator function returns the current [mean squared error][mean-squared-error]. + +```javascript +var accumulator = incrnanmmse( 3 ); + +var m = accumulator(); +// returns null + +// Fill the window... +m = accumulator( 2.0, 3.0 ); // [(2.0,3.0)] +// returns 1.0 + +m = accumulator( -1.0, 4.0 ); // [(2.0,3.0), (-1.0,4.0)] +// returns 13.0 + +m = accumulator( 3.0, 9.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] +// returns ~20.67 + +// Window begins sliding... +m = accumulator( -7.0, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] +// returns ~53.67 + +m = accumulator( NaN, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] +// returns ~53.67 + +m = accumulator( -5.0, -3.0 ); // [(3.0,9.0), (-7.0,3.0), (-5.0,-3.0)] +// returns ~46.67 + +m = accumulator(); +// returns ~46.67 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- As `W` (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 incrnanmmse = require( '@stdlib/stats/incr/nanmmse' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmse( 5 ); + +// For each simulated datum, update the moving mean squared error... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v1 = NaN; + v2 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + } + accumulator( v1, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/benchmark/benchmark.js new file mode 100644 index 000000000000..5980a019aa20 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmmse = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmse( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmmse( 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(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/img/equation_mean_squared_error.svg b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/img/equation_mean_squared_error.svg new file mode 100644 index 000000000000..e2a699216122 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/img/equation_mean_squared_error.svg @@ -0,0 +1,60 @@ + +upper M upper S upper E equals StartFraction 1 Over upper W EndFraction sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts left-parenthesis y Subscript i Baseline minus x Subscript i Baseline right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/repl.txt new file mode 100644 index 000000000000..5012117fc6db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving mean + squared error (MSE), ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving mean squared error. + + If provided a value, the accumulator function returns an updated moving mean + squared error. If not provided a value, the accumulator function returns the + current moving 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 m = accumulator() + null + > m = accumulator( 2.0, 3.0 ) + 1.0 + > m = accumulator( -5.0, 2.0 ) + 25.0 + > m = accumulator( NaN, 2.0 ) + 25.0 + > m = accumulator( 3.0, 2.0 ) + 17.0 + > m = accumulator( 3.0, NaN ) + 17.0 + > m = accumulator( 5.0, -2.0 ) + 33.0 + > m = accumulator() + 33.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/index.d.ts new file mode 100644 index 000000000000..f5fbe4c0fbfe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/index.d.ts @@ -0,0 +1,76 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided input values, the accumulator function returns an updated mean squared error. If not provided input values, the accumulator function returns the current mean squared error. +* +* @param x - input value +* @param y - input value +* @returns mean squared error or null +*/ +type accumulator = ( x?: number, y?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving mean squared error, ignoring `NaN` values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving 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 = incrnanmmse( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 25.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 25.0 +* +* m = accumulator( 3.0, 2.0 ); +* // returns 17.0 +* +* m = accumulator( 3.0, NaN ); +* // returns 17.0 +* +* m = accumulator( 5.0, -2.0 ); +* // returns 33.0 +* +* m = accumulator(); +* // returns 33.0 +*/ +declare function incrnanmmse( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/test.ts new file mode 100644 index 000000000000..e1b9ee9d2d1d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/docs/types/test.ts @@ -0,0 +1,74 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanmmse = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmse( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument which is not a number... +{ + incrnanmmse( '5' ); // $ExpectError + incrnanmmse( true ); // $ExpectError + incrnanmmse( false ); // $ExpectError + incrnanmmse( null ); // $ExpectError + incrnanmmse( undefined ); // $ExpectError + incrnanmmse( [] ); // $ExpectError + incrnanmmse( {} ); // $ExpectError + incrnanmmse( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmmse(); // $ExpectError + incrnanmmse( 2, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmse( 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 = incrnanmmse( 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 +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/examples/index.js new file mode 100644 index 000000000000..894ee8f191ae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmmse = require( './../lib' ); + +var accumulator; +var mse; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmmse( 5 ); + +// For each simulated datum, update the moving mean squared error... +console.log( '\nValue\tValue\tMSE\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v1 = NaN; + v2 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + } + mse = accumulator( v1, v2 ); + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), ( mse === null ) ? NaN : mse.toFixed( 3 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/index.js new file mode 100644 index 000000000000..029bb580b5dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/index.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a moving mean squared error (MSE) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmmse +* +* @example +* var incrnanmmse = require( '@stdlib/stats/incr/nanmmse' ); +* +* var accumulator = incrnanmmse( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 25.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 25.0 +* +* m = accumulator( 3.0, 2.0 ); +* // returns 17.0 +* +* m = accumulator( 3.0, NaN ); +* // returns 17.0 +* +* m = accumulator( 5.0, -2.0 ); +* // returns 33.0 +* +* m = accumulator(); +* // returns 33.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js new file mode 100644 index 000000000000..adceff3ec0fa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var incrmmean = require( '@stdlib/stats/incr/mmean' ); +var format = require( '@stdlib/string/format' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving 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 = incrnanmmse( 3 ); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 25.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 25.0 +* +* m = accumulator( 3.0, 2.0 ); +* // returns 17.0 +* +* m = accumulator( 3.0, NaN ); +* // returns 17.0 +* +* m = accumulator( 5.0, -2.0 ); +* // returns 33.0 +* +* m = accumulator(); +* // returns 33.0 +*/ +function incrnanmmse( W ) { + var mean; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + mean = incrmmean( W ); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated mean squared error. If not provided input values, the accumulator function returns the current mean squared error. + * + * @private + * @param {number} [x] - input value + * @param {number} [y] - input value + * @returns {(number|null)} mean squared error or null + */ + function accumulator( x, y ) { + var r; + if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { + return mean(); + } + r = y - x; + return mean( r*r ); + } +} + + +// EXPORTS // + +module.exports = incrnanmmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmse/package.json new file mode 100644 index 000000000000..879f1ff35b12 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/package.json @@ -0,0 +1,84 @@ +{ + "name": "@stdlib/stats/incr/nanmmse", + "version": "0.0.0", + "description": "Compute a moving mean squared error (MSE) 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", + "mse", + "msd", + "nan", + "residuals", + "squares", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving", + "time series", + "timeseries", + "forecasting", + "forecast", + "model", + "selection", + "evaluation", + "prediction" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/test/test.js new file mode 100644 index 000000000000..ff984bf72223 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/test/test.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanmmse = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmse, '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() { + incrnanmmse( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmmse( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving 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 ], + [ NaN, 5.0 ], + [ 4.0, -4.0 ], + [ 3.0, 0.0 ], + [ 3.0, NaN ], + [ -4.0, 5.0 ] + ]; + N = data.length; + + acc = incrnanmmse( 3 ); + + expected = [ 1.0, 17.0/2.0, 26.0/3.0, 26.0/3.0, 89.0/3.0, 82.0/3.0, 82.0/3.0, 154.0/3.0 ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[i][0], data[i][1] ); + if ( actual === expected[i] ) { + t.equal( actual, expected[i], 'returns expected value' ); + } else { + delta = abs( expected[i] - actual ); + tol = 1.0 * EPS * abs( expected[i] ); + t.equal( 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 mean squared error', function test( t ) { + var data; + var acc; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -5.0 ], + [ 3.0, NaN ], + [ 1.0, 10.0 ] + ]; + acc = incrnanmmse( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[i][0], data[i][1] ); + } + t.equal( acc(), 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 = incrnanmmse( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); From 694e89c213ee2b389dde8cdfffb2ef0180ae1ea3 Mon Sep 17 00:00:00 2001 From: sanchay Date: Thu, 20 Mar 2025 18:23:57 +0000 Subject: [PATCH 2/3] style: as suggested by the reviewer --- 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 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmmse/lib/main.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js index adceff3ec0fa..c265f4df7e66 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; -var incrmmean = require( '@stdlib/stats/incr/mmean' ); +var incrmmse = require( '@stdlib/stats/incr/mmse' ); var format = require( '@stdlib/string/format' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -63,11 +63,11 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * // returns 33.0 */ function incrnanmmse( W ) { - var mean; + var mmse; if ( !isPositiveInteger( W ) ) { throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); } - mean = incrmmean( W ); + mmse = incrmmse( W ); return accumulator; /** @@ -79,12 +79,10 @@ function incrnanmmse( W ) { * @returns {(number|null)} mean squared error or null */ function accumulator( x, y ) { - var r; if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { - return mean(); + return mmse(); } - r = y - x; - return mean( r*r ); + return mmse( x, y ); } } From 86ff247698f722cc65bd69f1e21e07693e328d36 Mon Sep 17 00:00:00 2001 From: sanchay Date: Thu, 20 Mar 2025 20:12:53 +0000 Subject: [PATCH 3/3] style: as suggested by the reviewer --- 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 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js index c265f4df7e66..9632ac17bd15 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmse/lib/main.js @@ -20,9 +20,7 @@ // MODULES // -var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; var incrmmse = require( '@stdlib/stats/incr/mmse' ); -var format = require( '@stdlib/string/format' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -64,9 +62,6 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); */ function incrnanmmse( W ) { var mmse; - if ( !isPositiveInteger( W ) ) { - throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); - } mmse = incrmmse( W ); return accumulator;