From 3009d30ed1cb30ace601d5581c786a9849746ec6 Mon Sep 17 00:00:00 2001 From: hrshya Date: Tue, 11 Mar 2025 22:41:05 +0530 Subject: [PATCH 1/3] feat: add stats/incr/nanrmse --- .../@stdlib/stats/incr/nanrmse/README.md | 169 ++++++++++++++++++ .../stats/incr/nanrmse/benchmark/benchmark.js | 69 +++++++ .../img/equation_root_mean_squared_error.svg | 75 ++++++++ .../@stdlib/stats/incr/nanrmse/docs/repl.txt | 31 ++++ .../stats/incr/nanrmse/docs/types/index.d.ts | 60 +++++++ .../stats/incr/nanrmse/docs/types/test.ts | 69 +++++++ .../stats/incr/nanrmse/examples/index.js | 46 +++++ .../@stdlib/stats/incr/nanrmse/lib/index.js | 54 ++++++ .../@stdlib/stats/incr/nanrmse/lib/main.js | 75 ++++++++ .../@stdlib/stats/incr/nanrmse/package.json | 80 +++++++++ .../@stdlib/stats/incr/nanrmse/test/test.js | 125 +++++++++++++ 11 files changed, 853 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/docs/img/equation_root_mean_squared_error.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md new file mode 100644 index 000000000000..e49e756d6815 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md @@ -0,0 +1,169 @@ + + +# incrnanrmse + +> Compute the [root mean squared error][root-mean-squared-error] (RMSE) incrementally, ignoring `NaN` values. + +
+ +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}{n} \sum_{i=0}^{n-1} (y_i - x_i)^2 } +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanrmse = require( '@stdlib/stats/incr/nanrmse' ); +``` + +#### incrnanrmse() + +Returns an accumulator `function` which incrementally computes the [root mean squared error][root-mean-squared-error], ignoring `NaN` values. + +```javascript +var accumulator = incrnanrmse(); +``` + +#### 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 = incrnanrmse(); + +var r = accumulator( 2.0, 3.0 ); +// returns 1.0 + +r = accumulator( 2.0, NaN ); +// returns 1.0 + +r = accumulator( -1.0, -4.0 ); +// returns ~2.24 + +r = accumulator( -3.0, 5.0 ); +// returns ~4.97 + +r = accumulator(); +// returns ~4.97 +``` + +
+ + + +
+ +## 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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanrmse = require( '@stdlib/stats/incr/nanrmse' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanrmse(); + +// For each simulated datum, update the root 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/nanrmse/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/benchmark/benchmark.js new file mode 100644 index 000000000000..966abf22badd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/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 incrnanrmse = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanrmse(); + 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 = incrnanrmse(); + + 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/nanrmse/docs/img/equation_root_mean_squared_error.svg b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/img/equation_root_mean_squared_error.svg new file mode 100644 index 000000000000..16f610f484d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/img/equation_root_mean_squared_error.svg @@ -0,0 +1,75 @@ + +upper R upper M upper S upper E equals StartRoot StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis y Subscript i Baseline minus x Subscript i Baseline right-parenthesis squared EndRoot + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/repl.txt new file mode 100644 index 000000000000..2c32d13455d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes the root mean + squared error (RMSE), ignoring `NaN` values. + + 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. + + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var r = accumulator() + null + > r = accumulator( 2.0, 3.0 ) + 1.0 + > r = accumulator( 2.0, NaN ) + 1.0 + > r = accumulator( -5.0, 2.0 ) + 5.0 + > r = accumulator() + 5.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/index.d.ts new file mode 100644 index 000000000000..fe14ad74d9dd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/index.d.ts @@ -0,0 +1,60 @@ +/* +* @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 root mean squared error. If not provided input values, the accumulator function returns the current root mean squared error. +* +* @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 the root mean squared error, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanrmse(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator(); +* // returns 5.0 +*/ +declare function incrnanrmse(): accumulator; + + +// EXPORTS // + +export = incrnanrmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/test.ts new file mode 100644 index 000000000000..81fb02d3f30f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/docs/types/test.ts @@ -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. +*/ + +import incrnanrmse from './index'; + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanrmse(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanrmse( '5' ); // $ExpectError + incrnanrmse( 5 ); // $ExpectError + incrnanrmse( true ); // $ExpectError + incrnanrmse( false ); // $ExpectError + incrnanrmse( null ); // $ExpectError + incrnanrmse( undefined ); // $ExpectError + incrnanrmse( [] ); // $ExpectError + incrnanrmse( {} ); // $ExpectError + incrnanrmse( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanrmse(); + + 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 = incrnanrmse(); + + 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/nanrmse/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/examples/index.js new file mode 100644 index 000000000000..42246d4d75b0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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 incrnanrmse = require( './../lib' ); + +var accumulator; +var rmse; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanrmse(); + +// For each simulated datum, update the root mean squared error... +console.log( '\nValue\tValue\tRMSE\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; + } + rmse = accumulator( v1, v2 ); + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), ( rmse === null ) ? NaN : rmse.toFixed( 3 ) ); +} +console.log( '\nFinal RMSE: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/index.js new file mode 100644 index 000000000000..9032e9b240c1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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 the root mean squared error (RMSE) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanrmse +* +* @example +* var incrnanrmse = require( '@stdlib/stats/incr/nanrmse' ); +* +* var accumulator = incrnanrmse(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator(); +* // returns 5.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/main.js new file mode 100644 index 000000000000..b38588fbcb8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/lib/main.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrrmse = require( '@stdlib/stats/incr/rmse' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the root mean squared error, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanrmse(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 5.0 +* +* r = accumulator(); +* // returns 5.0 +*/ +function incrnanrmse() { + var rmse = incrrmse(); + 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 || isnan( x ) || isnan( y ) ) { + return rmse(); + } + return rmse( x, y ); + } +} + + +// EXPORTS // + +module.exports = incrnanrmse; diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/package.json b/lib/node_modules/@stdlib/stats/incr/nanrmse/package.json new file mode 100644 index 000000000000..fec54e02797b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/stats/incr/nanrmse", + "version": "0.0.0", + "description": "Compute the 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", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "time series", + "timeseries", + "forecasting", + "forecast", + "model", + "selection", + "evaluation", + "prediction" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js new file mode 100644 index 000000000000..518657573ad2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js @@ -0,0 +1,125 @@ +/** +* @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 sqrt = require( '@stdlib/math/base/special/sqrt' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanrmse = require( './../lib' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanrmse, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanrmse(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanrmse(); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the root mean squared error', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var sum; + var tol; + var N; + var r; + var x; + var y; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -1.0 ], + [ 2.0, 5.0 ], + [ NaN, 2.0 ], + [ 4.0, -4.0 ], + [ 1.0, NaN ], + [ 3.0, 0.0 ], + [ -4.0, 5.0 ] + ]; + N = data.length; + + acc = incrnanrmse(); + + sum = 0; + for ( i = 0; i < N; i++ ) { + x = data[ i ][ 0 ]; + y = data[ i ][ 1 ]; + if ( isnan( d ) === false ) { + r = y - x; + sum += r * r; + } + expected = sqrt( sum/(i+1) ); + actual = acc( x, y ); + if ( actual === expected ) { + t.equal( actual, expected, 'returns expected value' ); + } else { + delta = abs( expected - actual ); + tol = 1.0 * EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. 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 expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ + [ 2.0, 3.0 ], + [ NaN, NaN ], + [ 3.0, -5.0 ], + [ 1.0, NaN ], + [ 1.0, 10.0 ] + ]; + acc = incrnanrmse(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ][ 0 ], data[ i ][ 1 ] ); + } + actual = acc(); + expected = sqrt( ( 1.0+64.0+81.0 ) / 3.0 ); + delta = abs( expected - actual ); + tol = 1.0 * EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); From d7e7a10a96a4872f47f0db359da6c9f91eeda01c Mon Sep 17 00:00:00 2001 From: hrshya Date: Tue, 11 Mar 2025 23:49:59 +0530 Subject: [PATCH 2/3] feat: add stats/incr/nanrmse --- .../@stdlib/stats/incr/nanrmse/test/test.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js index 518657573ad2..8389878112d2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js @@ -60,14 +60,15 @@ tape( 'the accumulator function incrementally computes the root mean squared err var x; var y; var i; + var c; data = [ [ 2.0, 3.0 ], [ 3.0, -1.0 ], [ 2.0, 5.0 ], - [ NaN, 2.0 ], - [ 4.0, -4.0 ], [ 1.0, NaN ], + [ 4.0, -4.0 ], + [ NaN, 2.0 ], [ 3.0, 0.0 ], [ -4.0, 5.0 ] ]; @@ -76,14 +77,18 @@ tape( 'the accumulator function incrementally computes the root mean squared err acc = incrnanrmse(); sum = 0; + c = 0; for ( i = 0; i < N; i++ ) { x = data[ i ][ 0 ]; y = data[ i ][ 1 ]; - if ( isnan( d ) === false ) { + if ( isnan( x ) === false && isnan( y ) === false ) { r = y - x; sum += r * r; + c += 1; + expected = sqrt( sum/c ); + } else { + expected = sqrt( sum/c ); } - expected = sqrt( sum/(i+1) ); actual = acc( x, y ); if ( actual === expected ) { t.equal( actual, expected, 'returns expected value' ); From c2ebb198328cf7832f040333278cc95e67495f1d Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 11 Mar 2025 18:43:16 +0000 Subject: [PATCH 3/3] fix: resolve lint errors --- .../@stdlib/stats/incr/nanrmse/README.md | 14 -------------- .../@stdlib/stats/incr/nanrmse/test/test.js | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md b/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md index e49e756d6815..1c10db0f01e4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/README.md @@ -136,14 +136,6 @@ console.log( accumulator() ); @@ -156,12 +148,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/mrmse]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mrmse - -[@stdlib/stats/incr/mse]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mse - -[@stdlib/stats/incr/rss]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/rss - diff --git a/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js index 8389878112d2..e6986fe7b33a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrmse/test/test.js @@ -24,8 +24,8 @@ var tape = require( 'tape' ); var abs = require( '@stdlib/math/base/special/abs' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var EPS = require( '@stdlib/constants/float64/eps' ); -var incrnanrmse = require( './../lib' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanrmse = require( './../lib' ); // TESTS //