From da4435008d31775d4295abbf2c5fe02dc48a2581 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 10:29:25 +0530 Subject: [PATCH 1/7] feat: add stats/incr/nanewmean --- .../@stdlib/stats/incr/nanewmean/README.md | 172 ++++++++++++++++++ .../incr/nanewmean/benchmark/benchmark.js | 69 +++++++ .../equation_exponentially_weighted_mean.svg | 74 ++++++++ .../stats/incr/nanewmean/docs/repl.txt | 36 ++++ .../incr/nanewmean/docs/types/index.d.ts | 61 +++++++ .../stats/incr/nanewmean/docs/types/test.ts | 60 ++++++ .../stats/incr/nanewmean/examples/index.js | 43 +++++ .../@stdlib/stats/incr/nanewmean/lib/index.js | 54 ++++++ .../@stdlib/stats/incr/nanewmean/lib/main.js | 76 ++++++++ .../@stdlib/stats/incr/nanewmean/package.json | 69 +++++++ .../@stdlib/stats/incr/nanewmean/test/test.js | 133 ++++++++++++++ 11 files changed, 847 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/docs/img/equation_exponentially_weighted_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md new file mode 100644 index 000000000000..1f25dead68d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md @@ -0,0 +1,172 @@ + + +# incrnanewmean + +> Compute an [exponentially weighted mean][moving-average] incrementally, ignoring `NaN` values. + +
+ +An [exponentially weighted mean][moving-average] can be defined recursively as + + + +```math +\mu_t = \begin{cases} x_0 & \textrm{if}\ t = 0 \\ \alpha x_t + (1-\alpha) \mu_{t-1} & \textrm{if}\ t > 0 \end{cases} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanewmean = require( '@stdlib/stats/incr/nanewmean' ); +``` + +#### incrnanewmean( alpha ) + +Returns an accumulator `function` which incrementally computes an [exponentially weighted mean][moving-average], where `alpha` is a smoothing factor between `0` and `1`, ignoring `NaN` values. + +```javascript +var accumulator = incrnanewmean( 0.5 ); +``` + +#### 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 = incrnanewmean( 0.5 ); + +var v = accumulator(); +// returns null + +v = accumulator( 2.0 ); +// returns 2.0 + +v = accumulator( 1.0 ); +// returns 1.5 + +v = accumulator( NaN ); +// returns 1.5 + +v = accumulator( 3.0 ); +// returns 2.25 + +v = accumulator(); +// returns 2.25 +``` + +
+ + + +
+ +## 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 incrnanewmean = require( '@stdlib/stats/incr/nanewmean' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanewmean( 0.5 ); + +// For each simulated datum, update the exponentially weighted mean... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js new file mode 100644 index 000000000000..e3935495004f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/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 incrnanewmean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanewmean( 0.5 ); + 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 = incrnanewmean( 0.5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + 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/nanewmean/docs/img/equation_exponentially_weighted_mean.svg b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/img/equation_exponentially_weighted_mean.svg new file mode 100644 index 000000000000..b89cfc9aaae1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/img/equation_exponentially_weighted_mean.svg @@ -0,0 +1,74 @@ + +mu Subscript t Baseline equals StartLayout Enlarged left-brace 1st Row 1st Column x 0 2nd Column if t equals 0 2nd Row 1st Column alpha x Subscript t Baseline plus left-parenthesis 1 minus alpha right-parenthesis mu Subscript t minus 1 Baseline 2nd Column if t greater-than 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt new file mode 100644 index 000000000000..69d4b15617ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( α ) + Returns an accumulator function which incrementally computes an + exponentially weighted mean, where α is a smoothing factor between 0 and 1, 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. + + Parameters + ---------- + α: number + Smoothing factor (value between 0 and 1). + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 0.5 ); + > var v = accumulator() + null + > v = accumulator( 2.0 ) + 2.0 + > v = accumulator( NaN ) + 2.0 + > v = accumulator( -5.0 ) + -1.5 + > v = accumulator() + -1.5 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts new file mode 100644 index 000000000000..e2fcbe6ccfd1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, the accumulator function returns an updated mean. If not provided a value, the accumulator function returns the current mean. +* +* @param x - value +* @returns mean value +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes an exponentially weighted mean, ignoring `NaN` values. +* +* @param alpha - smoothing factor +* @throws alpha must be on the interval `[0,1]` +* @returns accumulator function +* +* @example +* var accumulator = increwmean( 0.5 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( -5.0 ); +* // returns -1.5 +* +* v = accumulator(); +* // returns -1.5 +*/ +declare function incrnanewmean( alpha: number ): accumulator; + + +// EXPORTS // + +export = incrnanewmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts new file mode 100644 index 000000000000..127716eedbb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.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. +*/ + +import incrnanewmean = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanewmean( 0.5 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanewmean( '5' ); // $ExpectError + incrnanewmean( true ); // $ExpectError + incrnanewmean( false ); // $ExpectError + incrnanewmean( null ); // $ExpectError + incrnanewmean( undefined ); // $ExpectError + incrnanewmean( [] ); // $ExpectError + incrnanewmean( {} ); // $ExpectError + incrnanewmean( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanewmean( 0.5 ); + + 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 = incrnanewmean( 0.5 ); + + 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/nanewmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js new file mode 100644 index 000000000000..31958f146fbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 incrnanewmean = require( './../lib' ); + +var accumulator; +var mu; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanewmean( 0.5 ); + +// For each simulated datum, update the exponentially weighted mean... +console.log( '\nValue\tMean\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + mu = accumulator( v ); + console.log( '%d\t%d', (v === null ) ? v : v.toFixed( 4 ), (mu === null ) ? mu : mu.toFixed( 4 ) ); +} +console.log( '\nFinal mean: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js new file mode 100644 index 000000000000..7bef983614f9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/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 exponentially weighted mean incrementally. +* +* @module @stdlib/stats/incr/nanewmean +* +* @example +* var incrnanewmean = require( '@stdlib/stats/incr/nanewmean' ); +* +* var accumulator = incrnanewmean(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( -5.0 ); +* // returns -1.5 +* +* v = accumulator(); +* // returns -1.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js new file mode 100644 index 000000000000..5beaec6b397f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var increwmean = require( '@stdlib/stats/incr/ewmean' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes an exponentially weighted mean, ignoring `NaN` values. +* +* @param {NonNegativeNumber} alpha - smoothing factor +* @throws {TypeError} must provide a nonnegative number +* @throws {RangeError} must be on the interval `[0,1]` +* @returns {Function} accumulator function +* +* @example +* var accumulator = increwmean( 0.5 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( -5.0 ); +* // returns -1.5 +* +* v = accumulator(); +* // returns -1.5 +*/ +function incrnanewmean( alpha ) { + var nanewmean = increwmean( alpha ); + 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 nanewmean(); + } + return nanewmean( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanewmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/package.json b/lib/node_modules/@stdlib/stats/incr/nanewmean/package.json new file mode 100644 index 000000000000..f35f24e8c535 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/incr/nanewmean", + "version": "0.0.0", + "description": "Compute an exponentially weighted mean 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", + "weighted", + "exponential", + "moving average", + "ema", + "ewma", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js new file mode 100644 index 000000000000..4784c888426a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/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 incrnanewmean = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanewmean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a nonnegative number', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + NaN, + true, + false, + null, + void 0, + [], + {}, + 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() { + incrnanewmean( value ); + }; + } +}); + +tape( 'the function throws an error if provided a nonnegative number which does not reside on the interval `[0,1]`', function test( t ) { + var values; + var i; + + values = [ + 1.5, + 3.14, + 1.0001, + 1.0e300 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanewmean( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanewmean( 0.5 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanewmean( 0.5 ); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes an exponentially weighted mean', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 2.0, NaN, 4.0, NaN, 3.0, 4.0 ]; + N = data.length; + + expected = [ 2.0, 2.5, 2.25, 2.25, 3.125, 3.125, 3.0625, 3.53125 ]; + actual = []; + + acc = incrnanewmean( 0.5 ); + + for ( i = 0; i < N; i++ ) { + actual.push(acc( data[ i ] )); + } + t.deepEqual( actual, expected, 'returns expected incremental results' ); + 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 = [ NaN, 3.0, 1.0 ]; + acc = incrnanewmean( 0.5 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 2.0, 'returns the current accumulated mean' ); + t.end(); +}); From 8aa1f12d41e09f32b723c12c5356456ebc0a4d37 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 20:13:12 +0530 Subject: [PATCH 2/7] update main.js --- lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js index 5beaec6b397f..657dcd765ddf 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js @@ -34,7 +34,7 @@ var increwmean = require( '@stdlib/stats/incr/ewmean' ); * @returns {Function} accumulator function * * @example -* var accumulator = increwmean( 0.5 ); +* var accumulator = incrnanewmean( 0.5 ); * * var v = accumulator(); * // returns null From accce89227fa144789db9dadd4608cbffd5a29c1 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 20:19:55 +0530 Subject: [PATCH 3/7] update repl.txt --- lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt index 69d4b15617ed..10bb20079f92 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/repl.txt @@ -1,8 +1,8 @@ {{alias}}( α ) Returns an accumulator function which incrementally computes an - exponentially weighted mean, where α is a smoothing factor between 0 and 1, ignoring - `NaN` values. + exponentially weighted mean, where α is a smoothing factor between 0 and 1, + 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. From 68bf49334d68fff8f423d72ac1ce83849feb3aa4 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Sat, 15 Mar 2025 13:52:04 +0530 Subject: [PATCH 4/7] made suggested change --- .../@stdlib/stats/incr/nanewmean/lib/main.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js index 657dcd765ddf..1cf744cdb74d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js @@ -21,6 +21,7 @@ // MODULES // var increwmean = require( '@stdlib/stats/incr/ewmean' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); // MAIN // @@ -52,7 +53,7 @@ var increwmean = require( '@stdlib/stats/incr/ewmean' ); * // returns -1.5 */ function incrnanewmean( alpha ) { - var nanewmean = increwmean( alpha ); + var ewmean = increwmean( alpha ); return accumulator; /** @@ -63,10 +64,10 @@ function incrnanewmean( alpha ) { * @returns {(number|null)} mean value or null */ function accumulator(x) { - if ( arguments.length === 0 || isNaN( x ) ) { - return nanewmean(); + if ( arguments.length === 0 || isnan( x ) ) { + return ewmean(); } - return nanewmean( x ); + return ewmean( x ); } } From 6eb20007060ebd43d5cca3cc5dbd861c8765415f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 20 Jul 2026 15:26:23 -0500 Subject: [PATCH 5/7] fix: address review feedback for stats/incr/nanewmean --- .../@stdlib/stats/incr/nanewmean/benchmark/benchmark.js | 3 ++- .../@stdlib/stats/incr/nanewmean/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanewmean/examples/index.js | 4 ++-- lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js index e3935495004f..105e6c38f48d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var incrnanewmean = require( './../lib' ); @@ -46,7 +47,7 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::accumulator', function benchmark( b ) { +bench( format( '%s::accumulator', pkg ), function benchmark( b ) { var acc; var v; var i; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts index e2fcbe6ccfd1..ffb5c01ab307 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts @@ -36,7 +36,7 @@ type accumulator = ( x?: number ) => number | null; * @returns accumulator function * * @example -* var accumulator = increwmean( 0.5 ); +* var accumulator = incrnanewmean( 0.5 ); * * var v = accumulator(); * // returns null diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js index 31958f146fbe..ea5abe4b26a5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js @@ -38,6 +38,6 @@ for ( i = 0; i < 100; i++ ) { v = randu() * 100.0; } mu = accumulator( v ); - console.log( '%d\t%d', (v === null ) ? v : v.toFixed( 4 ), (mu === null ) ? mu : mu.toFixed( 4 ) ); + console.log( '%s\t%s', ( v === null ) ? v : v.toFixed( 4 ), ( mu === null ) ? mu : mu.toFixed( 4 ) ); } -console.log( '\nFinal mean: %d\n', accumulator() ); +console.log( '\nFinal mean: %s\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js index 1cf744cdb74d..1bf3751594bb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js @@ -63,7 +63,7 @@ function incrnanewmean( alpha ) { * @param {number} [x] - new value * @returns {(number|null)} mean value or null */ - function accumulator(x) { + function accumulator( x ) { if ( arguments.length === 0 || isnan( x ) ) { return ewmean(); } From f4b1c5c4294b87a26d9a1dae165921c3f3ac80ae Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 20 Jul 2026 20:55:07 +0000 Subject: [PATCH 6/7] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanewmean/README.md | 2 +- .../@stdlib/stats/incr/nanewmean/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanewmean/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanewmean/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md index 1f25dead68d1..5ed237bc9b09 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2026 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js index 105e6c38f48d..5cc2fecefdc3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts index ffb5c01ab307..bbac004e7ba0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts index 127716eedbb6..a18e75baac78 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js index ea5abe4b26a5..c72b3ee82ac5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js index 7bef983614f9..e786bd23b77a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js index 1bf3751594bb..95dfc9963df5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js index 4784c888426a..7313f531ba20 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 403b9af14f5d9134705d43b37b9a24ea8f25f5c8 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 20 Jul 2026 16:23:15 -0500 Subject: [PATCH 7/7] fix: correct index.js example and docs in stats/incr/nanewmean --- .../@stdlib/stats/incr/nanewmean/README.md | 13 ------------- .../stats/incr/nanewmean/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanewmean/lib/index.js | 4 ++-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md index 5ed237bc9b09..2e2eb84ffdbe 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/README.md @@ -140,11 +140,6 @@ console.log( accumulator() ); ## See Also -- [`@stdlib/stats/incr/ewvariance`][@stdlib/stats/incr/ewvariance]: compute an exponentially weighted variance incrementally. -- [`@stdlib/stats/incr/mean`][@stdlib/stats/incr/mean]: compute an arithmetic mean incrementally. -- [`@stdlib/stats/incr/mmean`][@stdlib/stats/incr/mmean]: compute a moving arithmetic mean incrementally. -- [`@stdlib/stats/incr/wmean`][@stdlib/stats/incr/wmean]: compute a weighted arithmetic mean incrementally. - @@ -157,14 +152,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/ewvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/ewvariance - -[@stdlib/stats/incr/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mean - -[@stdlib/stats/incr/mmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmean - -[@stdlib/stats/incr/wmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/wmean - diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts index bbac004e7ba0..2aea8a3aff4b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/docs/types/index.d.ts @@ -32,7 +32,7 @@ type accumulator = ( x?: number ) => number | null; * Returns an accumulator function which incrementally computes an exponentially weighted mean, ignoring `NaN` values. * * @param alpha - smoothing factor -* @throws alpha must be on the interval `[0,1]` +* @throws must be on the interval `[0,1]` * @returns accumulator function * * @example diff --git a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js index e786bd23b77a..9d20d2c5ad79 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewmean/lib/index.js @@ -19,14 +19,14 @@ 'use strict'; /** -* Compute an exponentially weighted mean incrementally. +* Compute an exponentially weighted mean incrementally, ignoring `NaN` values. * * @module @stdlib/stats/incr/nanewmean * * @example * var incrnanewmean = require( '@stdlib/stats/incr/nanewmean' ); * -* var accumulator = incrnanewmean(); +* var accumulator = incrnanewmean( 0.5 ); * * var v = accumulator(); * // returns null