From aab58e062ca05e936eb0688b1af2edd408f0de7c Mon Sep 17 00:00:00 2001 From: Girish Garg Date: Sun, 16 Mar 2025 23:18:55 +0530 Subject: [PATCH 1/8] feat: add incremental exponentially weighted standard deviation accumulator --- .../@stdlib/stats/incr/nanewstdev/README.md | 171 ++++++++++++++++++ .../incr/nanewstdev/benchmark/benchmark.js | 69 +++++++ ...uation_exponentially_weighted_variance.svg | 89 +++++++++ .../stats/incr/nanewstdev/docs/repl.txt | 40 ++++ .../incr/nanewstdev/docs/types/index.d.ts | 65 +++++++ .../stats/incr/nanewstdev/docs/types/test.ts | 60 ++++++ .../stats/incr/nanewstdev/examples/index.js | 40 ++++ .../stats/incr/nanewstdev/lib/index.js | 54 ++++++ .../@stdlib/stats/incr/nanewstdev/lib/main.js | 78 ++++++++ .../stats/incr/nanewstdev/package.json | 74 ++++++++ .../stats/incr/nanewstdev/test/test.js | 158 ++++++++++++++++ 11 files changed, 898 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/img/equation_exponentially_weighted_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md new file mode 100644 index 000000000000..ce563ae25d2b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md @@ -0,0 +1,171 @@ + + +# incrnanewstdev + +> Compute an [exponentially weighted standard deviation][moving-average] incrementally. + +
+ +An [exponentially weighted variance][moving-average] can be defined recursively as + + + +```math +S_n = \begin{cases} 0 & \textrm{if}\ n = 0 \\ (1 - \alpha) (S_{n-1} + \alpha(x_n - \mu_{n-1})^2) & \textrm{if}\ n > 0 \end{cases} +``` + + + + + +where `μ` is the [exponentially weighted mean][@stdlib/stats/incr/ewmean]. The [exponentially weighted standard deviation][moving-average] is the square root of the [exponentially weighted variance][moving-average]. + +
+ + + +
+ +## Usage + +```javascript +var incrnanewstdev = require( '@stdlib/stats/incr/nanewstdev' ); +``` + +#### incrnanewstdev( alpha ) + +Returns an accumulator `function` which incrementally computes an [exponentially weighted standard deviation][moving-average], where `alpha` is a smoothing factor between `0` and `1`. + +```javascript +var accumulator = incrnanewstdev( 0.5 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated standard deviation. If not provided an input value `x`, the accumulator function returns the current standard deviation. + +```javascript +var accumulator = incrnanewstdev( 0.5 ); + +var s = accumulator(); +// returns null + +s = accumulator( 2.0 ); +// returns 0.0 + +s = accumulator( 1.0 ); +// returns 0.5 + +s = accumulator( NaN ); +// returns 0.5 + +s = accumulator( 3.0 ); +// returns ~0.83 + +s = accumulator(); +// returns ~0.83 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, it will be **ignored** but 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 incrnanewstdev = require( './../lib' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + +var accumulator; +var s; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanewstdev( 0.5 ); + +// For each simulated datum, update the exponentially weighted standard deviation... +for ( i = 0; i < 100; i++ ) { + v = (randu() < 0.1) ? NaN : randu() * 100.0; + s = accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js new file mode 100644 index 000000000000..27805c0447dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanewstdev = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanewstdev( 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 = incrnanewstdev( 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/nanewstdev/docs/img/equation_exponentially_weighted_variance.svg b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/img/equation_exponentially_weighted_variance.svg new file mode 100644 index 000000000000..ec759179e837 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/img/equation_exponentially_weighted_variance.svg @@ -0,0 +1,89 @@ + +upper S Subscript n Baseline equals StartLayout Enlarged left-brace 1st Row 1st Column 0 2nd Column if n equals 0 2nd Row 1st Column left-parenthesis 1 minus alpha right-parenthesis left-parenthesis upper S Subscript n minus 1 Baseline plus alpha left-parenthesis x Subscript n Baseline minus mu Subscript n minus 1 Baseline right-parenthesis squared right-parenthesis 2nd Column if n greater-than 0 EndLayout + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt new file mode 100644 index 000000000000..d5a84bc36df9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( α ) + Returns an accumulator function which incrementally computes an + exponentially weighted standard deviation, where α is a smoothing factor + between 0 and 1. + + If provided a value, the accumulator function returns an updated standard + deviation. If not provided a value, the accumulator function returns the + current standard deviation. + + If provided `NaN` or a value which, when used in computations, results in + `NaN`, it will be ignored by accumulator function. + + Parameters + ---------- + α: number + Smoothing factor (value between 0 and 1). + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 0.5 ); + > var s = accumulator() + null + > s = accumulator( 2.0 ) + 0.0 + > s = accumulator( NaN ) + 0.0 + > s = accumulator( -5.0 ) + 3.5 + > s = accumulator() + 3.5 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts new file mode 100644 index 000000000000..622578056e16 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts @@ -0,0 +1,65 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, the accumulator function returns an updated standard deviation. If not provided a value, the accumulator function returns the current standard deviation. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, it will be ignored. +* +* @param x - value +* @returns standard deviation or null +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes an exponentially weighted standard deviation. +* +* @param alpha - smoothing factor +* @throws must be on the interval `[0,1]` +* @returns accumulator function +* +* @example +* var accumulator = incrnanewstdev( 0.5 ); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( NaN ); // ignored +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns 3.5 +* +* s = accumulator(); +* // returns 3.5 +*/ +declare function incrnanewstdev( alpha: number ): accumulator; + + +// EXPORTS // + +export = incrnanewstdev; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts new file mode 100644 index 000000000000..173cbfdd2add --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @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 incrnanewstdev = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanewstdev( 0.5 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanewstdev( '5' ); // $ExpectError + incrnanewstdev( true ); // $ExpectError + incrnanewstdev( false ); // $ExpectError + incrnanewstdev( null ); // $ExpectError + incrnanewstdev( undefined ); // $ExpectError + incrnanewstdev( [] ); // $ExpectError + incrnanewstdev( {} ); // $ExpectError + incrnanewstdev( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanewstdev( 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 = incrnanewstdev( 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/nanewstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js new file mode 100644 index 000000000000..879536b913f9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 incrnanewstdev = require( './../lib' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + +var accumulator; +var s; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanewstdev( 0.5 ); + +// For each simulated datum, update the exponentially weighted standard deviation... +console.log( '\nValue\tStDev\n' ); +for ( i = 0; i < 100; i++ ) { + v = (randu() < 0.1) ? NaN : randu() * 100.0; // 10% chance of a NaN + s = accumulator( v ); + console.log( '%d\t%d', isnan(v) ? 'NaN' : v.toFixed( 4 ), s.toFixed( 4 ) ); +} +console.log( '\nFinal StDev: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js new file mode 100644 index 000000000000..a1da3a34481d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 standard deviation incrementally. +* +* @module @stdlib/stats/incr/nanewstdev +* +* @example +* var increwstdev = require( '@stdlib/stats/incr/nanewstdev' ); +* +* var accumulator = increwstdev(); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( NaN ); // ignored +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns 3.5 +* +* s = accumulator(); +* // returns 3.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js new file mode 100644 index 000000000000..1087e4587bad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 increwstdev = require('@stdlib/stats/incr/ewstdev'); + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes an exponentially weighted standard deviation, 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 = incrnanewstdev( 0.5 ); +* +* var s = accumulator(); +* // returns null +* +* s = accumulator( 2.0 ); +* // returns 0.0 +* +* s = accumulator( NaN ); // ignored +* // returns 0.0 +* +* s = accumulator( -5.0 ); +* // returns 3.5 +* +* s = accumulator(); +* // returns 3.5 +*/ +function incrnanewstdev( alpha ) { + var ewstdev; + + ewstdev = increwstdev(alpha); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated standard deviation. If not provided a value, the accumulator function returns the current standard deviation. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} standard deviation or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return ewstdev(); + } + return ewstdev( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanewstdev; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json new file mode 100644 index 000000000000..8aaff5f065f5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/stats/incr/nanewstdev", + "version": "0.0.0", + "description": "Compute an exponentially weighted standard deviation 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", + "stdev", + "std", + "variance", + "var", + "standard", + "deviation", + "dispersion", + "weighted", + "exponential", + "emsd", + "emv", + "ewmv", + "ewmsd", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js new file mode 100644 index 000000000000..5548b9e74c2e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var incrnanewstdev = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanewstdev, '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, + 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() { + incrnanewstdev( 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() { + incrnanewstdev( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanewstdev( 0.5 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanewstdev( 0.5 ); + t.equal( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes an exponentially weighted standard deviation', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ + 2.0, + NaN, + 3.0, + 2.0, + 4.0, + NaN, + 3.0, + 4.0 + ]; + N = data.length; + + // Note: manually computed using the recurrence relation S_n = (1-α)(S_{n-1} + α(x_n - mu_{n-1})^2) = S_n = (1-α)S_{n-1} + α(1-α)(x_n - mu_{n-1})^2 + expected = [ + 0.0, // m = 2.0, s2 = 0.0 + 0.0, // Ignore NaN values + sqrt( (0.5*0.0) + (0.25*pow( 3.0-2.0, 2 )) ), // m = 2.5, s2 = 0.25 + sqrt( (0.5*0.25) + (0.25*pow( 2.0-2.5, 2 )) ), // m = 2.25, s2 = 0.1875 + sqrt( (0.5*0.1875) + (0.25*pow( 4.0-2.25, 2 )) ), // m = 3.125, s2 = 0.859375 + sqrt( (0.5*0.1875) + (0.25*pow( 4.0-2.25, 2 )) ), // Ignore NaN values + sqrt( (0.5*0.859375) + (0.25*pow( 3.0-3.125, 2 )) ), // m = 3.0625, s2 = 0.43359375 + sqrt( (0.5*0.43359375) + (0.25*pow( 4.0-3.0625, 2 )) ) // m = 3.53125, s2 = 0.4365234375 + ]; + actual = new Array( N ); + + acc = incrnanewstdev( 0.5 ); + + for ( i = 0; i < N; i++ ) { + actual[ i ] = acc( data[ i ] ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current standard deviation', function test( t ) { + var data; + var acc; + var i; + + data = [ + 2.0, // m = 2.0, s2 = 0.0 + 3.0, // m = 2.5, s2 = 0.25 + NaN, // Ignore NaN values + 1.0 // m = 1.75, s2 = 0.6875 + ]; + acc = incrnanewstdev( 0.5 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), sqrt( 0.6875 ), 'returns expected value' ); + t.end(); +}); From 002035b8e8806479a61514d2d97d24c555610b52 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:50:10 +0000 Subject: [PATCH 2/8] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md | 2 +- .../@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanewstdev/docs/types/test.ts | 2 +- .../@stdlib/stats/incr/nanewstdev/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md index ce563ae25d2b..5b3bb6a4a1b8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js index 27805c0447dc..5c39c6181cfe 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts index 622578056e16..22defba41fd3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts index 173cbfdd2add..304949f455f7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js index 879536b913f9..bbf7264ba3eb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js index a1da3a34481d..2798875df356 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js index 1087e4587bad..678309d3dfb9 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js index 5548b9e74c2e..703b5b62c573 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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 8468926221b1ebeec5903e480c9d47c719e720e1 Mon Sep 17 00:00:00 2001 From: Girish Garg Date: Wed, 30 Apr 2025 15:35:21 +0530 Subject: [PATCH 3/8] chore: fixed linting and clean-up --- lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md | 8 ++++---- .../@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js | 3 +-- .../@stdlib/stats/incr/nanewstdev/docs/repl.txt | 5 +---- .../@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts | 8 ++------ .../@stdlib/stats/incr/nanewstdev/examples/index.js | 6 +++--- .../@stdlib/stats/incr/nanewstdev/lib/index.js | 4 ++-- .../@stdlib/stats/incr/nanewstdev/lib/main.js | 5 +++-- .../@stdlib/stats/incr/nanewstdev/package.json | 2 +- .../@stdlib/stats/incr/nanewstdev/test/test.js | 4 ++-- 9 files changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md index 5b3bb6a4a1b8..12a9b6cefb58 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md @@ -20,7 +20,7 @@ limitations under the License. # incrnanewstdev -> Compute an [exponentially weighted standard deviation][moving-average] incrementally. +> Compute an [exponentially weighted standard deviation][moving-average] incrementally, ignoring `NaN` values.
@@ -55,7 +55,7 @@ var incrnanewstdev = require( '@stdlib/stats/incr/nanewstdev' ); #### incrnanewstdev( alpha ) -Returns an accumulator `function` which incrementally computes an [exponentially weighted standard deviation][moving-average], where `alpha` is a smoothing factor between `0` and `1`. +Returns an accumulator `function` which incrementally computes an [exponentially weighted standard deviation][moving-average], where `alpha` is a smoothing factor between `0` and `1`, ignoring `NaN` values. ```javascript var accumulator = incrnanewstdev( 0.5 ); @@ -95,7 +95,7 @@ s = accumulator(); ## Notes -- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, it will be **ignored** but you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- Input values are **not** type checked.If non-numeric inputs are possible, but you are advised to type check and handle accordingly **before** passing the value to the accumulator function.
@@ -109,8 +109,8 @@ s = accumulator(); ```javascript var randu = require( '@stdlib/random/base/randu' ); -var incrnanewstdev = require( './../lib' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanewstdev = require( '@stdlib/stats/incr/nanewstdev' ); var accumulator; var s; diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js index 5c39c6181cfe..7a33014e0702 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js @@ -21,7 +21,6 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var pkg = require( './../package.json' ).name; var incrnanewstdev = require( './../lib' ); @@ -55,7 +54,7 @@ bench( pkg+'::accumulator', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = acc( randu() ); + v = acc( i ); if ( v !== v ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt index d5a84bc36df9..963c62d036c8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/repl.txt @@ -2,15 +2,12 @@ {{alias}}( α ) Returns an accumulator function which incrementally computes an exponentially weighted standard deviation, where α is a smoothing factor - between 0 and 1. + between 0 and 1, ignoring `NaN` values. If provided a value, the accumulator function returns an updated standard deviation. If not provided a value, the accumulator function returns the current standard deviation. - If provided `NaN` or a value which, when used in computations, results in - `NaN`, it will be ignored by accumulator function. - Parameters ---------- α: number diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts index 22defba41fd3..d9aaefb7cffd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts @@ -23,17 +23,13 @@ /** * If provided a value, the accumulator function returns an updated standard deviation. If not provided a value, the accumulator function returns the current standard deviation. * -* ## Notes -* -* - If provided `NaN` or a value which, when used in computations, results in `NaN`, it will be ignored. -* * @param x - value * @returns standard deviation or null */ type accumulator = ( x?: number ) => number | null; /** -* Returns an accumulator function which incrementally computes an exponentially weighted standard deviation. +* Returns an accumulator function which incrementally computes an exponentially weighted standard deviation, ignoring `NaN` values. * * @param alpha - smoothing factor * @throws must be on the interval `[0,1]` @@ -48,7 +44,7 @@ type accumulator = ( x?: number ) => number | null; * s = accumulator( 2.0 ); * // returns 0.0 * -* s = accumulator( NaN ); // ignored +* s = accumulator( NaN ); * // returns 0.0 * * s = accumulator( -5.0 ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js index bbf7264ba3eb..eee4f27531ed 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js @@ -19,8 +19,8 @@ 'use strict'; var randu = require( '@stdlib/random/base/randu' ); -var incrnanewstdev = require( './../lib' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanewstdev = require( './../lib' ); var accumulator; var s; @@ -33,8 +33,8 @@ accumulator = incrnanewstdev( 0.5 ); // For each simulated datum, update the exponentially weighted standard deviation... console.log( '\nValue\tStDev\n' ); for ( i = 0; i < 100; i++ ) { - v = (randu() < 0.1) ? NaN : randu() * 100.0; // 10% chance of a NaN + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; // 10% chance of a NaN s = accumulator( v ); - console.log( '%d\t%d', isnan(v) ? 'NaN' : v.toFixed( 4 ), s.toFixed( 4 ) ); + console.log( '%d\t%d', ( isnan(v) ) ? 'NaN' : v.toFixed( 4 ), s.toFixed( 4 ) ); } console.log( '\nFinal StDev: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js index 2798875df356..e8c0b6b737af 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute an exponentially weighted standard deviation incrementally. +* Compute an exponentially weighted standard deviation incrementally, ignoring `NaN` values. * * @module @stdlib/stats/incr/nanewstdev * @@ -34,7 +34,7 @@ * s = accumulator( 2.0 ); * // returns 0.0 * -* s = accumulator( NaN ); // ignored +* s = accumulator( NaN ); * // returns 0.0 * * s = accumulator( -5.0 ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js index 678309d3dfb9..a7de9ec2809a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js @@ -21,7 +21,8 @@ // MODULES // var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var increwstdev = require('@stdlib/stats/incr/ewstdev'); +var increwstdev = require( '@stdlib/stats/incr/ewstdev' ); + // MAIN // @@ -42,7 +43,7 @@ var increwstdev = require('@stdlib/stats/incr/ewstdev'); * s = accumulator( 2.0 ); * // returns 0.0 * -* s = accumulator( NaN ); // ignored +* s = accumulator( NaN ); * // returns 0.0 * * s = accumulator( -5.0 ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json index 8aaff5f065f5..4bfef3d5ca93 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nanewstdev", "version": "0.0.0", - "description": "Compute an exponentially weighted standard deviation incrementally.", + "description": "Compute an exponentially weighted standard deviation incrementally, ignoring `NaN` values.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js index 703b5b62c573..1aed109b702a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js @@ -127,12 +127,12 @@ tape( 'the accumulator function incrementally computes an exponentially weighted sqrt( (0.5*0.859375) + (0.25*pow( 3.0-3.125, 2 )) ), // m = 3.0625, s2 = 0.43359375 sqrt( (0.5*0.43359375) + (0.25*pow( 4.0-3.0625, 2 )) ) // m = 3.53125, s2 = 0.4365234375 ]; - actual = new Array( N ); + actual = []; acc = incrnanewstdev( 0.5 ); for ( i = 0; i < N; i++ ) { - actual[ i ] = acc( data[ i ] ); + actual.push( acc( data[ i ] ) ); } t.deepEqual( actual, expected, 'returns expected values' ); t.end(); From bf551695c34c79ac20a8902f7aae527d69206094 Mon Sep 17 00:00:00 2001 From: Girish Garg Date: Wed, 30 Apr 2025 15:52:01 +0530 Subject: [PATCH 4/8] chore: fixed linting --- lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md index 12a9b6cefb58..1727feca5703 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md @@ -8,7 +8,7 @@ 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 + 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, From ef79af23d859b6a69b5c2c22c8e6cd966de1fbc4 Mon Sep 17 00:00:00 2001 From: Girish Garg Date: Wed, 30 Apr 2025 18:57:08 +0530 Subject: [PATCH 5/8] chore: fix example file --- .../@stdlib/stats/incr/nanewstdev/examples/index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js index eee4f27531ed..99e8b99aca7f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js @@ -19,22 +19,19 @@ 'use strict'; var randu = require( '@stdlib/random/base/randu' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanewstdev = require( './../lib' ); -var accumulator; -var s; -var v; -var i; - // Initialize an accumulator: -accumulator = incrnanewstdev( 0.5 ); +var accumulator = incrnanewstdev( 0.5 ); // For each simulated datum, update the exponentially weighted standard deviation... console.log( '\nValue\tStDev\n' ); +var s; +var v; +var i; for ( i = 0; i < 100; i++ ) { v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; // 10% chance of a NaN s = accumulator( v ); - console.log( '%d\t%d', ( isnan(v) ) ? 'NaN' : v.toFixed( 4 ), s.toFixed( 4 ) ); + console.log( '%d\t%d', v.toFixed( 4 ), ( s === null ) ? NaN : s.toFixed( 4 ) ); } console.log( '\nFinal StDev: %d\n', accumulator() ); From 872b0b04d68b65ecd013370e8fdb06db87bc56a2 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 12 Jul 2026 00:28:06 -0500 Subject: [PATCH 6/8] chore: address review feedback and update copyright years - remove backticks around NaN in package.json description - fix grammar in README notes - add spaces inside parentheses in main.js - use %s format specifier for toFixed string output in example - remove manually populated See Also section - use `format` for benchmark name string concatenation --- .../@stdlib/stats/incr/nanewstdev/README.md | 18 ++---------------- .../incr/nanewstdev/benchmark/benchmark.js | 5 +++-- .../incr/nanewstdev/docs/types/index.d.ts | 2 +- .../stats/incr/nanewstdev/docs/types/test.ts | 2 +- .../stats/incr/nanewstdev/examples/index.js | 4 ++-- .../@stdlib/stats/incr/nanewstdev/lib/index.js | 2 +- .../@stdlib/stats/incr/nanewstdev/lib/main.js | 4 ++-- .../@stdlib/stats/incr/nanewstdev/package.json | 2 +- .../@stdlib/stats/incr/nanewstdev/test/test.js | 2 +- 9 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md index 1727feca5703..5c54370854ea 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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. @@ -95,7 +95,7 @@ s = accumulator(); ## Notes -- Input values are **not** type checked.If non-numeric inputs are possible, but you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- 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. @@ -136,14 +136,6 @@ console.log( accumulator() ); @@ -158,12 +150,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/mstdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mstdev - -[@stdlib/stats/incr/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/stdev - diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js index 7a33014e0702..843d2d95f1d9 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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. @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var incrnanewstdev = require( './../lib' ); @@ -45,7 +46,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/nanewstdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts index d9aaefb7cffd..fb39f89b5b59 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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/nanewstdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts index 304949f455f7..f8fe122a22c3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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/nanewstdev/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js index 99e8b99aca7f..9eb5296f9793 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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. @@ -32,6 +32,6 @@ var i; for ( i = 0; i < 100; i++ ) { v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; // 10% chance of a NaN s = accumulator( v ); - console.log( '%d\t%d', v.toFixed( 4 ), ( s === null ) ? NaN : s.toFixed( 4 ) ); + console.log( '%s\t%s', v.toFixed( 4 ), ( s === null ) ? NaN : s.toFixed( 4 ) ); } console.log( '\nFinal StDev: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js index e8c0b6b737af..9b461298534a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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/nanewstdev/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js index a7de9ec2809a..f6d760b5fc1c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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. @@ -55,7 +55,7 @@ var increwstdev = require( '@stdlib/stats/incr/ewstdev' ); function incrnanewstdev( alpha ) { var ewstdev; - ewstdev = increwstdev(alpha); + ewstdev = increwstdev( alpha ); return accumulator; /** diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json index 4bfef3d5ca93..fa5b93747fed 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nanewstdev", "version": "0.0.0", - "description": "Compute an exponentially weighted standard deviation incrementally, ignoring `NaN` values.", + "description": "Compute an exponentially weighted standard deviation incrementally, ignoring NaN values.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js index 1aed109b702a..30f54b8e7e07 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/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 943ddfe5367c1d257264908c81575498016d19a9 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 12 Jul 2026 00:34:49 -0500 Subject: [PATCH 7/8] fix: correct function name and provide required `alpha` argument in doctest The `@module` `@example` used the wrong function name and called the accumulator factory without the required smoothing factor, causing the jsdoc-doctest lint to fail. --- lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js index 9b461298534a..aa08a08da761 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/lib/index.js @@ -24,9 +24,9 @@ * @module @stdlib/stats/incr/nanewstdev * * @example -* var increwstdev = require( '@stdlib/stats/incr/nanewstdev' ); +* var incrnanewstdev = require( '@stdlib/stats/incr/nanewstdev' ); * -* var accumulator = increwstdev(); +* var accumulator = incrnanewstdev( 0.5 ); * * var s = accumulator(); * // returns null From cfc0a7809d4281063b62cf4ad5b86371e3da6ea7 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 12 Jul 2026 01:06:08 -0500 Subject: [PATCH 8/8] chore: address review feedback - remove unused `isnan` import from README example - add spaces inside parentheses to satisfy `space-in-parens` --- lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md index 5c54370854ea..4aa1d8baaefc 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanewstdev/README.md @@ -109,7 +109,6 @@ s = accumulator(); ```javascript var randu = require( '@stdlib/random/base/randu' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanewstdev = require( '@stdlib/stats/incr/nanewstdev' ); var accumulator; @@ -122,7 +121,7 @@ accumulator = incrnanewstdev( 0.5 ); // For each simulated datum, update the exponentially weighted standard deviation... for ( i = 0; i < 100; i++ ) { - v = (randu() < 0.1) ? NaN : randu() * 100.0; + v = ( randu() < 0.1 ) ? NaN : randu() * 100.0; s = accumulator( v ); } console.log( accumulator() );