From bc80ce2cf67aa298f2b850503546d1a3514b0693 Mon Sep 17 00:00:00 2001 From: Anshu Date: Sat, 15 Mar 2025 16:09:11 +0530 Subject: [PATCH 1/7] feat(stats): add nanmeanabs package --- .../@stdlib/stats/incr/nanmeanabs/README.md | 133 ++++++++++++++++++ .../incr/nanmeanabs/benchmark/benchmark.js | 68 +++++++++ ...uation_arithmetic_mean_absolute_values.svg | 45 ++++++ .../stats/incr/nanmeanabs/docs/repl.txt | 30 ++++ .../incr/nanmeanabs/docs/types/index.d.ts | 62 ++++++++ .../stats/incr/nanmeanabs/docs/types/test.ts | 61 ++++++++ .../stats/incr/nanmeanabs/examples/index.js | 38 +++++ .../stats/incr/nanmeanabs/lib/index.js | 54 +++++++ .../@stdlib/stats/incr/nanmeanabs/lib/main.js | 74 ++++++++++ .../stats/incr/nanmeanabs/package.json | 71 ++++++++++ .../stats/incr/nanmeanabs/test/test.js | 95 +++++++++++++ 11 files changed, 731 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/img/equation_arithmetic_mean_absolute_values.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md new file mode 100644 index 000000000000..cf711f2ab612 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md @@ -0,0 +1,133 @@ + + +# incrnanmeanabs + +> Compute an [arithmetic mean][arithmetic-mean] of absolute values incrementally, ignoring `NaN` values. + +
+ +The [arithmetic mean][arithmetic-mean] of absolute values is defined as + + + +```math +\mu = \frac{1}{n} \sum_{i=0}^{n-1} |x_i| +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmeanabs = require( '@stdlib/stats/incr/nanmeanabs' ); +``` + +#### incrnanmeanabs() + +Returns an accumulator `function` which incrementally computes an [arithmetic mean][arithmetic-mean] of absolute values, ignoring `NaN` values. + +```javascript +var accumulator = incrnanmeanabs(); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated mean. If not provided an input value `x`, the accumulator function returns the current mean. + +```javascript +var accumulator = incrnanmeanabs(); + +var mu = accumulator( 2.0 ); +// returns 2.0 + +mu = accumulator( NaN ); +// returns 2.0 + +mu = accumulator( -1.0 ); +// returns 1.5 + +mu = accumulator( -3.0 ); +// returns 2.0 + +mu = 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. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanmeanabs = require( '@stdlib/stats/incr/nanmeanabs' ); + +// Initialize an accumulator: +var accumulator = incrnanmeanabs(); + +// For each simulated datum, update the mean... +var v; +var i; + +for ( i = 0; i < 100; i++ ) { + accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js new file mode 100644 index 000000000000..56b1d2f48e7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js @@ -0,0 +1,68 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var incrnanmeanabs = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmeanabs(); + 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 = incrnanmeanabs(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( i ); + 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/nanmeanabs/docs/img/equation_arithmetic_mean_absolute_values.svg b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/img/equation_arithmetic_mean_absolute_values.svg new file mode 100644 index 000000000000..257657a0f016 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/img/equation_arithmetic_mean_absolute_values.svg @@ -0,0 +1,45 @@ + +mu equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts StartAbsoluteValue x Subscript i Baseline EndAbsoluteValue + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/repl.txt new file mode 100644 index 000000000000..eed62415b149 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes an arithmetic + mean of absolute values, ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated mean. If + not provided a value, the accumulator function returns the current mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var mu = accumulator() + null + > mu = accumulator( 2.0 ) + 2.0 + > mu = accumulator( NaN ) + 2.0 + > mu = accumulator( -5.0 ) + 3.5 + > mu = accumulator() + 3.5 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts new file mode 100644 index 000000000000..a821ac57c092 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts @@ -0,0 +1,62 @@ +/* +* @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 a value, returns an updated arithmetic mean; otherwise, returns the current arithmetic mean. +* +* @param x - value +* @returns arithmetic mean of absolute values +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes an arithmetic mean of absolute values, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanmeanabs(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0 ); +* // returns 2.0 +* +* mu = accumulator( NaN ); +* // returns 2.0 +* +* mu = accumulator( -3.0 ); +* // returns 2.5 +* +* mu = accumulator( -4.0 ); +* // returns 3.0 +* +* mu = accumulator(); +* // returns 3.0 +*/ +declare function incrnanmeanabs(): accumulator; + + +// EXPORTS // + +export = incrnanmeanabs; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/test.ts new file mode 100644 index 000000000000..f127ba3950a6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @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 incrnanmeanabs = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmeanabs(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanmeanabs( '5' ); // $ExpectError + incrnanmeanabs( 5 ); // $ExpectError + incrnanmeanabs( true ); // $ExpectError + incrnanmeanabs( false ); // $ExpectError + incrnanmeanabs( null ); // $ExpectError + incrnanmeanabs( undefined ); // $ExpectError + incrnanmeanabs( [] ); // $ExpectError + incrnanmeanabs( {} ); // $ExpectError + incrnanmeanabs( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmeanabs(); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmeanabs(); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/examples/index.js new file mode 100644 index 000000000000..835617e1b915 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanmeanabs = require( './../lib' ); + +// Initialize an accumulator: +var accumulator = incrnanmeanabs(); + +// For each simulated datum, update the mean... +console.log( '\nValue\tMean\n' ); +var mu; +var v; +var i; +for ( i = 0; i < 100; i++ ) { + v = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -100.0, 100.0 ); + mu = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 3 ), ( mu === null ) ? NaN : mu.toFixed( 3 ) ); +} +console.log( '\nFinal mean: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/index.js new file mode 100644 index 000000000000..7f3da39488b7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/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 an arithmetic mean of absolute values incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmeanabs +* +* @example +* var incrnanmeanabs = require( '@stdlib/stats/incr/nanmeanabs' ); +* +* var accumulator = incrnanmeanabs(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0 ); +* // returns 2.0 +* +* mu = accumulator( NaN ); +* // returns 2.0 +* +* mu = accumulator( -5.0 ); +* // returns 3.5 +* +* mu = accumulator(); +* // returns 3.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/main.js new file mode 100644 index 000000000000..85e23c72b8bf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmeanabs = require( '@stdlib/stats/incr/meanabs' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes an arithmetic mean of absolute values, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmeanabs(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0 ); +* // returns 2.0 +* +* mu = accumulator( NaN ); +* // returns 2.0 +* +* mu = accumulator( -5.0 ); +* // returns 3.5 +* +* mu = accumulator(); +* // returns 3.5 +*/ +function incrnanmeanabs() { + var meanabs = incrmeanabs(); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated mean. If not provided a value, the accumulator function returns the current mean. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} mean value or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return meanabs(); + } + return meanabs( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmeanabs; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/package.json b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/package.json new file mode 100644 index 000000000000..b4d0f75662f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/incr/nanmeanabs", + "version": "0.0.0", + "description": "Compute an arithmetic mean of absolute values 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", + "average", + "avg", + "mean", + "arithmetic mean", + "central tendency", + "incremental", + "accumulator", + "absolute", + "value", + "abs", + "magnitude", + "math.abs" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js new file mode 100644 index 000000000000..277e813ffd04 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js @@ -0,0 +1,95 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var incrnanmeanabs = require( './../lib' ); +var tape = require( 'tape' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmeanabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmeanabs(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanmeanabs(); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes an arithmetic mean of absolute values', function test( t ) { + var expected; + var actual; + var count; + var data; + var sum; + var acc; + var i; + var d; + var N; + + data = [ 2.0, -3.0, 2.0, NaN, -4.0, NaN, 3.0, -4.0 ]; + N = data.length; + count = 0; + sum = 0; + + expected = []; + actual = []; + + acc = incrnanmeanabs(); + + for ( i = 0; i < N; i++ ) { + d = data[ i ]; + if ( isnan( d ) === false ) { + sum += abs( d ); + count += 1; + } + expected.push( ( count === 0 ) ? null : sum / count ); + actual.push( acc( d ) ); + } + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current mean', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, -3.0, NaN, -1.0 ]; + acc = incrnanmeanabs(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 2.0, 'returns expected value' ); + t.end(); +}); From 3aca5121f542ec51d149a440e2628aa2c5fee553 Mon Sep 17 00:00:00 2001 From: Anshu Date: Sat, 15 Mar 2025 16:23:41 +0530 Subject: [PATCH 2/7] style: fix style related lint errors --- .../@stdlib/stats/incr/nanmeanabs/README.md | 10 ++++++++++ .../@stdlib/stats/incr/nanmeanabs/test/test.js | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md index cf711f2ab612..52f42f27fa27 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md @@ -130,4 +130,14 @@ console.log( accumulator() ); + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js index 277e813ffd04..b3f0f629443f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js @@ -20,11 +20,10 @@ // MODULES // - var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); -var incrnanmeanabs = require( './../lib' ); var tape = require( 'tape' ); +var incrnanmeanabs = require( './../lib' ); // TESTS // From 8071e5d96cf92280d3d8b4e110695ef7f034f07b Mon Sep 17 00:00:00 2001 From: Anshu Date: Sat, 15 Mar 2025 16:27:22 +0530 Subject: [PATCH 3/7] style: fix test.js lint error --- lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js index b3f0f629443f..1252eb13e12c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/test/test.js @@ -20,9 +20,9 @@ // MODULES // +var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); -var tape = require( 'tape' ); var incrnanmeanabs = require( './../lib' ); From 81fb8112556002dadaf855dfb9be00fbd780906f Mon Sep 17 00:00:00 2001 From: Anshu Kumar Date: Tue, 18 Mar 2025 12:55:02 +0530 Subject: [PATCH 4/7] chore: update benchmark.js Signed-off-by: Anshu Kumar --- .../@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js index 56b1d2f48e7d..8ce0714c4e40 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); var pkg = require( './../package.json' ).name; var incrnanmeanabs = require( './../lib' ); @@ -54,7 +55,7 @@ bench( pkg+'::accumulator', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = acc( i ); + v = acc( randu()-0.5 ); if ( v !== v ) { b.fail( 'should not return NaN' ); } From d6ca37408e052135303a329497c607fdf579b37c Mon Sep 17 00:00:00 2001 From: Anshu Kumar Date: Tue, 18 Mar 2025 12:59:57 +0530 Subject: [PATCH 5/7] style: fix lint error in benchmark.js Signed-off-by: Anshu Kumar --- .../@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js index 8ce0714c4e40..9e67b90ecb26 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/benchmark/benchmark.js @@ -55,7 +55,7 @@ bench( pkg+'::accumulator', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = acc( randu()-0.5 ); + v = acc( randu()-0.5 ); if ( v !== v ) { b.fail( 'should not return NaN' ); } From 620386cabc2a023a262d234055de4c76092649aa Mon Sep 17 00:00:00 2001 From: Anshu Kumar Date: Tue, 18 Mar 2025 13:56:00 +0530 Subject: [PATCH 6/7] docs: update README.md Signed-off-by: Anshu Kumar --- lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md index 52f42f27fa27..3c90a384c3e4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md @@ -111,11 +111,10 @@ var incrnanmeanabs = require( '@stdlib/stats/incr/nanmeanabs' ); var accumulator = incrnanmeanabs(); // For each simulated datum, update the mean... -var v; var i; for ( i = 0; i < 100; i++ ) { - accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) ); + accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -100.0, 100.0 ) ); } console.log( accumulator() ); ``` From 09cd1c68699b1c463a72bdf7e7e6e6ee8ce3c80c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 18 Mar 2025 01:33:47 -0700 Subject: [PATCH 7/7] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md | 3 +-- .../@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md index 3c90a384c3e4..dbef25bded83 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/README.md @@ -53,7 +53,7 @@ var incrnanmeanabs = require( '@stdlib/stats/incr/nanmeanabs' ); #### incrnanmeanabs() -Returns an accumulator `function` which incrementally computes an [arithmetic mean][arithmetic-mean] of absolute values, ignoring `NaN` values. +Returns an accumulator function which incrementally computes an [arithmetic mean][arithmetic-mean] of absolute values, ignoring `NaN` values. ```javascript var accumulator = incrnanmeanabs(); @@ -112,7 +112,6 @@ var accumulator = incrnanmeanabs(); // For each simulated datum, update the mean... var i; - for ( i = 0; i < 100; i++ ) { accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( -100.0, 100.0 ) ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts index a821ac57c092..89a6ecaaf3d6 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmeanabs/docs/types/index.d.ts @@ -18,8 +18,6 @@ // TypeScript Version: 4.1 -/// - /** * If provided a value, returns an updated arithmetic mean; otherwise, returns the current arithmetic mean. *