From a76815fa3f70eec5fd1b6210499cdd6392e485ee Mon Sep 17 00:00:00 2001 From: Sanchay Date: Sat, 15 Mar 2025 19:57:31 +0530 Subject: [PATCH 01/10] feat(stats): add nanme package --- .../@stdlib/stats/incr/nanme/README.md | 170 ++++++++++++++++++ .../stats/incr/nanme/benchmark/benchmark.js | 69 +++++++ .../nanme/docs/img/equation_mean_error.svg | 53 ++++++ .../@stdlib/stats/incr/nanme/docs/repl.txt | 33 ++++ .../stats/incr/nanme/docs/types/index.d.ts | 63 +++++++ .../stats/incr/nanme/docs/types/test.ts | 69 +++++++ .../stats/incr/nanme/examples/index.js | 49 +++++ .../@stdlib/stats/incr/nanme/lib/index.js | 57 ++++++ .../@stdlib/stats/incr/nanme/lib/main.js | 78 ++++++++ .../@stdlib/stats/incr/nanme/package.json | 78 ++++++++ .../@stdlib/stats/incr/nanme/test/test.js | 124 +++++++++++++ 11 files changed, 843 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/docs/img/equation_mean_error.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanme/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/README.md b/lib/node_modules/@stdlib/stats/incr/nanme/README.md new file mode 100644 index 000000000000..234b33270a31 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/README.md @@ -0,0 +1,170 @@ + + +# incrnanme + +> Compute the [mean error][mean-absolute-error] (ME) incrementally, ignoring `NaN` values. + +
+ +The [mean error][mean-absolute-error] is defined as + + + +```math +\mathop{\mathrm{ME}} = \frac{1}{n} \sum_{i=0}^{n-1} (y_i - x_i) +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanme = require( '@stdlib/stats/incr/nanme' ); +``` + +#### incrnanme() + +Returns an accumulator `function` which incrementally computes the [mean error][mean-absolute-error], ignoring `NaN` values. + +```javascript +var accumulator = incrnanme(); +``` + +#### accumulator( \[x, y] ) + +If provided input values `x` and `y`, the accumulator function returns an updated [mean error][mean-absolute-error]. If not provided input values `x` and `y`, the accumulator function returns the current [mean error][mean-absolute-error]. + +```javascript +var accumulator = incrnanme(); + +var m = accumulator( 2.0, 3.0 ); +// returns 1.0 + +m = accumulator( -1.0, -4.0 ); +// returns -1.0 + +m = accumulator( -3.0, 5.0 ); +// returns 2.0 + +m = accumulator(); +// returns 2.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- Be careful when interpreting the [mean error][mean-absolute-error] as errors can cancel. This stated, that errors can cancel makes the [mean error][mean-absolute-error] suitable for measuring the bias in forecasts. +- **Warning**: the [mean error][mean-absolute-error] is scale-dependent and, thus, the measure should **not** be used to make comparisons between datasets having different scales. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanme = require( '@stdlib/stats/incr/nanme' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanme(); + +// For each simulated datum, update the mean error... +for ( i = 0; i < 100; i++ ) { + if( randu() < 0.2 ){ + v1 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + } + if( randu() < 0.2 ){ + v2 = NaN; + } else { + v2 = ( randu()*100.0 ) - 50.0; + } +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js new file mode 100644 index 000000000000..3fc2dacf2259 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/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 incrnanme = require( '@stdlib/stats/incr/nanme/lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanme(); + 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 = incrnanme(); + + 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/nanme/docs/img/equation_mean_error.svg b/lib/node_modules/@stdlib/stats/incr/nanme/docs/img/equation_mean_error.svg new file mode 100644 index 000000000000..b32b18b9d926 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/docs/img/equation_mean_error.svg @@ -0,0 +1,53 @@ + +upper M upper E equals StartFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis y Subscript i Baseline minus x Subscript i Baseline right-parenthesis Over n EndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanme/docs/repl.txt new file mode 100644 index 000000000000..78fce86e90a9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/docs/repl.txt @@ -0,0 +1,33 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes the mean error + (ME), ignoring NaN values. + + If provided input values, the accumulator function returns an updated mean + error. If not provided input values, the accumulator function returns the + current mean error. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var m = accumulator() + null + > m = accumulator( 2.0, 3.0 ) + 1.0 + > m = accumulator( -5.0, 2.0 ) + 4.0 + > m = accumulator( -3.0, NaN ) + 4.0 + > m = accumulator( NaN, 2.0 ) + 4.0 + > m = accumulator() + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/index.d.ts new file mode 100644 index 000000000000..854352b104da --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided input values, the accumulator function returns an updated mean error. If not provided input values, the accumulator function returns the current mean error. +* +* @param x - input value +* @param y - input value +* @returns mean error or null +*/ +type accumulator = ( x?: number, y?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes the mean error, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanme(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 4.0 +* +* m = accumulator( -3.0, NaN ); +* // returns 4.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 4.0 +* +* m = accumulator(); +* // returns 4.0 +*/ +declare function incrnanme(): accumulator; + + +// EXPORTS // + +export = incrnanme; diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts new file mode 100644 index 000000000000..5627f5cad18f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnanme = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanme(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanme( '5' ); // $ExpectError + incrnanme( 5 ); // $ExpectError + incrnanme( true ); // $ExpectError + incrnanme( false ); // $ExpectError + incrnanme( null ); // $ExpectError + incrnanme( undefined ); // $ExpectError + incrnanme( [] ); // $ExpectError + incrnanme( {} ); // $ExpectError + incrnanme( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanme(); + + 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 = incrnanme(); + + 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/nanme/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js new file mode 100644 index 000000000000..69933e09f73b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js @@ -0,0 +1,49 @@ +/** +* @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 incrnanme = require( './../lib' ); + +var accumulator; +var err; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanme(); + +// For each simulated datum, update the mean error... +console.log( '\nValue\tValue\tMean\n' ); +for ( i = 0; i < 100; i++ ) { + if( randu() < 0.2 ){ + v1 = NaN; + } else { + v1 = ( randu()*100.0 ) - 50.0; + } + if( randu() < 0.2 ){ + v2 = NaN; + } else { + v2 = ( randu()*100.0 ) - 50.0; + } + err = accumulator( v1, v2 ); + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), ( err === null ) ? NaN : err.toFixed( 3 ) ); +} +console.log( '\nFinal ME: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js new file mode 100644 index 000000000000..c7a773acd12c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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 mean error incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanme +* +* @example +* var incrme = require( '@stdlib/stats/incr/nanme' ); +* +* var accumulator = incrnanme(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 4.0 +* +* m = accumulator( -3.0, NaN ); +* // returns 4.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 4.0 +* +* m = accumulator(); +* // returns 4.0 +*/ + +// MODULES // + +var main = require( '@stdlib/stats/incr/nanme/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanme/lib/main.js new file mode 100644 index 000000000000..4ddb17af910a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/lib/main.js @@ -0,0 +1,78 @@ +/** +* @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 incrmean = require( '@stdlib/stats/incr/mean' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the mean error, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanme(); +* +* var m = accumulator(); +* // returns null +* +* m = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* m = accumulator( -5.0, 2.0 ); +* // returns 4.0 +* +* m = accumulator( -3.0, NaN ); +* // returns 4.0 +* +* m = accumulator( NaN, 2.0 ); +* // returns 4.0 +* +* m = accumulator(); +* // returns 4.0 +*/ +function incrnanme() { + var mean = incrmean(); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated mean error. If not provided input values, the accumulator function returns the current mean error. + * + * @private + * @param {number} [x] - input value + * @param {number} [y] - input value + * @returns {(number|null)} mean error or null + */ + function accumulator( x, y ) { + if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { + return mean(); + } + return mean( y-x ); + } +} + + +// EXPORTS // + +module.exports = incrnanme; diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/package.json b/lib/node_modules/@stdlib/stats/incr/nanme/package.json new file mode 100644 index 000000000000..da974a9b3a91 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/package.json @@ -0,0 +1,78 @@ +{ + "name": "@stdlib/stats/incr/nanme", + "version": "0.0.0", + "description": "Compute the mean error (ME) incrementally.", + "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", + "average", + "avg", + "mean", + "arithmetic mean", + "error", + "err", + "me", + "msd", + "signed", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "time series", + "timeseries", + "forecasting", + "forecast" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js new file mode 100644 index 000000000000..4f3060fe0913 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js @@ -0,0 +1,124 @@ +/** +* @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 incrnanme = require( '@stdlib/stats/incr/nanme/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 incrnanme, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanme(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanme(); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the mean error', function test( t ) { + var expected; + var actual; + var delta; + var count; + var data; + var acc; + var sum; + var tol; + var N; + var x; + var y; + var i; + + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -1.0 ], + [ 2.0, 5.0 ], + [ NaN, -4.0 ], + [ 3.0, 0.0 ], + [ -4.0, NaN ] + ]; + N = data.length; + + acc = incrnanme(); + + sum = 0; + count = 0; + for ( i = 0; i < N; i++ ) { + x = data[ i ][ 0 ]; + y = data[ i ][ 1 ]; + if ( isnan( x ) === false && isnan( y ) === false ){ + sum += ( y-x ); + count++; + } + expected = count>0 ? sum / count : null; + actual = acc( x, y ); + if ( actual === expected ) { + t.equal( actual, expected, 'returns expected value' ); + } else { + delta = abs( expected - actual ); + tol = 6.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 mean error', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 4.0, NaN ], + [ 3.0, -5.0 ], + [ NaN, -3.0 ], + [ 1.0, 10.0 ] + ]; + acc = incrnanme(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ][ 0 ], data[ i ][ 1 ] ); + } + actual = acc(); + expected = 2.0 / 3.0; + delta = abs( expected - actual ); + tol = 3.0 * EPS * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); From 72de7ac760f88b44b28f3882691cde226e9c34cb Mon Sep 17 00:00:00 2001 From: Sanchay Date: Sun, 16 Mar 2025 04:35:13 +0530 Subject: [PATCH 02/10] refractor(stats/examples): simplify conditional logic --- lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js index 69933e09f73b..cc31bc70b834 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js @@ -35,12 +35,9 @@ console.log( '\nValue\tValue\tMean\n' ); for ( i = 0; i < 100; i++ ) { if( randu() < 0.2 ){ v1 = NaN; - } else { - v1 = ( randu()*100.0 ) - 50.0; - } - if( randu() < 0.2 ){ v2 = NaN; } else { + v1 = ( randu()*100.0 ) - 50.0; v2 = ( randu()*100.0 ) - 50.0; } err = accumulator( v1, v2 ); From 0bac7a76cef97740336ea75cc33a99f491f9e3f5 Mon Sep 17 00:00:00 2001 From: Sanchay Date: Sun, 16 Mar 2025 04:47:07 +0530 Subject: [PATCH 03/10] refractor: update package description and example code --- lib/node_modules/@stdlib/stats/incr/nanme/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/package.json b/lib/node_modules/@stdlib/stats/incr/nanme/package.json index da974a9b3a91..d4f78b2f85b7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanme/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nanme", "version": "0.0.0", - "description": "Compute the mean error (ME) incrementally.", + "description": "Compute the mean error (ME) incrementally, ignoring NaN values.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -61,6 +61,7 @@ "arithmetic mean", "error", "err", + "nan", "me", "msd", "signed", From b65f4913f02244ff8976717b94e0949f0a18baf1 Mon Sep 17 00:00:00 2001 From: Sanchay Date: Sun, 16 Mar 2025 04:47:28 +0530 Subject: [PATCH 04/10] docs: improve documentation in README --- .../@stdlib/stats/incr/nanme/README.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/README.md b/lib/node_modules/@stdlib/stats/incr/nanme/README.md index 234b33270a31..c45984fdd898 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanme/README.md @@ -69,14 +69,17 @@ var accumulator = incrnanme(); var m = accumulator( 2.0, 3.0 ); // returns 1.0 -m = accumulator( -1.0, -4.0 ); -// returns -1.0 +m = accumulator( -5.0, 2.0 ); +// returns 4.0 -m = accumulator( -3.0, 5.0 ); -// returns 2.0 +m = accumulator( -3.0, NaN ); +// returns 4.0 + +m = accumulator( NaN, 2.0 ); +// returns 4.0 m = accumulator(); -// returns 2.0 +// returns 4.0 ``` @@ -117,13 +120,10 @@ accumulator = incrnanme(); for ( i = 0; i < 100; i++ ) { if( randu() < 0.2 ){ v1 = NaN; + v2 = NaN; } else { v1 = ( randu()*100.0 ) - 50.0; - } - if( randu() < 0.2 ){ - v2 = NaN; - } else { - v2 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; } } console.log( accumulator() ); From ff5b210b914977a2f58ad5374b01f8f858969d00 Mon Sep 17 00:00:00 2001 From: Sanchay Date: Sun, 16 Mar 2025 05:01:59 +0530 Subject: [PATCH 05/10] style: fix code formatting in README example --- lib/node_modules/@stdlib/stats/incr/nanme/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/README.md b/lib/node_modules/@stdlib/stats/incr/nanme/README.md index c45984fdd898..1f3e5a5267de 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanme/README.md @@ -118,13 +118,13 @@ accumulator = incrnanme(); // For each simulated datum, update the mean error... for ( i = 0; i < 100; i++ ) { - if( randu() < 0.2 ){ - v1 = NaN; + if ( randu() < 0.2 ) { + v1 = NaN; v2 = NaN; - } else { - v1 = ( randu()*100.0 ) - 50.0; + } else { + v1 = ( randu()*100.0 ) - 50.0; v2 = ( randu()*100.0 ) - 50.0; - } + } } console.log( accumulator() ); ``` From 54af4d065b16ba83e1374d5af7eb05d9acac765d Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 15 Mar 2025 23:53:45 +0000 Subject: [PATCH 06/10] fix: resolve lint errors --- .../@stdlib/stats/incr/nanme/README.md | 14 -------------- .../stats/incr/nanme/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanme/examples/index.js | 2 +- .../@stdlib/stats/incr/nanme/test/test.js | 5 ++--- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/README.md b/lib/node_modules/@stdlib/stats/incr/nanme/README.md index 1f3e5a5267de..cae562e3eb7c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanme/README.md @@ -137,14 +137,6 @@ console.log( accumulator() ); @@ -157,12 +149,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/mae]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mae - -[@stdlib/stats/incr/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mean - -[@stdlib/stats/incr/mme]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mme - diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js index 3fc2dacf2259..57bf5ba29afd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/benchmark/benchmark.js @@ -22,8 +22,8 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); -var pkg = require( './../package.json' ).name; var incrnanme = require( '@stdlib/stats/incr/nanme/lib' ); +var pkg = require( './../package.json' ).name; // MAIN // diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js index cc31bc70b834..73a73e1bb91c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/examples/index.js @@ -33,7 +33,7 @@ accumulator = incrnanme(); // For each simulated datum, update the mean error... console.log( '\nValue\tValue\tMean\n' ); for ( i = 0; i < 100; i++ ) { - if( randu() < 0.2 ){ + if ( randu() < 0.2 ) { v1 = NaN; v2 = NaN; } else { diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js index 4f3060fe0913..75a58296d19a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js @@ -60,7 +60,6 @@ tape( 'the accumulator function incrementally computes the mean error', function var y; var i; - data = [ [ 2.0, 3.0 ], [ 3.0, -1.0 ], @@ -78,10 +77,10 @@ tape( 'the accumulator function incrementally computes the mean error', function for ( i = 0; i < N; i++ ) { x = data[ i ][ 0 ]; y = data[ i ][ 1 ]; - if ( isnan( x ) === false && isnan( y ) === false ){ + if ( isnan( x ) === false && isnan( y ) === false ) { sum += ( y-x ); count++; - } + } expected = count>0 ? sum / count : null; actual = acc( x, y ); if ( actual === expected ) { From 63e8fb6884d3868f025e9e74fbe5b13d9f2948d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 18 Mar 2025 10:33:34 +0000 Subject: [PATCH 07/10] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts index 5627f5cad18f..3b4ed3caed11 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanme/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From eb160c41f302679b166f7c15ab7aeea0f4a4bcac Mon Sep 17 00:00:00 2001 From: Sanchay Date: Tue, 18 Mar 2025 16:07:30 +0530 Subject: [PATCH 08/10] refractor: correct lint error --- lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js index c7a773acd12c..2eba0a742b86 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/lib/index.js @@ -49,7 +49,7 @@ // MODULES // -var main = require( '@stdlib/stats/incr/nanme/lib/main.js' ); +var main = require( './main.js' ); // EXPORTS // From 92aa7a36b9edf0faf6716c5558e3b5ab148846d1 Mon Sep 17 00:00:00 2001 From: Sanchay Date: Tue, 18 Mar 2025 16:10:36 +0530 Subject: [PATCH 09/10] refractor: correct test lint error --- lib/node_modules/@stdlib/stats/incr/nanme/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js index 75a58296d19a..62c433b8239f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js @@ -79,7 +79,7 @@ tape( 'the accumulator function incrementally computes the mean error', function y = data[ i ][ 1 ]; if ( isnan( x ) === false && isnan( y ) === false ) { sum += ( y-x ); - count++; + count += 1; } expected = count>0 ? sum / count : null; actual = acc( x, y ); From d1ab532b28a9b52c15b9e68ad8952025e0521f35 Mon Sep 17 00:00:00 2001 From: Sanchay Date: Tue, 18 Mar 2025 16:20:15 +0530 Subject: [PATCH 10/10] refractor: correct test lint error --- lib/node_modules/@stdlib/stats/incr/nanme/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js index 62c433b8239f..51de333e97c3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanme/test/test.js @@ -81,7 +81,7 @@ tape( 'the accumulator function incrementally computes the mean error', function sum += ( y-x ); count += 1; } - expected = count>0 ? sum / count : null; + expected = ( count > 0 ) ? sum / count : null; actual = acc( x, y ); if ( actual === expected ) { t.equal( actual, expected, 'returns expected value' );