From 9281e0c635d452b09867c4b07e1434a657c5d48b Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 11 Nov 2025 08:44:01 +0530 Subject: [PATCH 01/17] feat: add incrnanmmeanvar (moving mean/variance with NaN skipping) --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 247 +++++++++++ .../incr/nanmmeanvar/benchmark/benchmark.js | 69 +++ .../docs/img/equation_arithmetic_mean.svg | 43 ++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../incr/nanmmeanvar/docs/img/nan_skip.svg | 40 ++ .../stats/incr/nanmmeanvar/docs/repl.txt | 52 +++ .../incr/nanmmeanvar/docs/types/index.d.ts | 101 +++++ .../stats/incr/nanmmeanvar/docs/types/test.ts | 78 ++++ .../stats/incr/nanmmeanvar/examples/index.js | 38 ++ .../stats/incr/nanmmeanvar/lib/index.js | 54 +++ .../stats/incr/nanmmeanvar/lib/main.js | 84 ++++ .../stats/incr/nanmmeanvar/package.json | 80 ++++ .../stats/incr/nanmmeanvar/test/test.js | 414 ++++++++++++++++++ 13 files changed, 1361 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md new file mode 100644 index 000000000000..0ae66d01226d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -0,0 +1,247 @@ + + +# incrnanmmeanvar + +> Compute a moving [arithmetic mean][arithmetic-mean] and [unbiased sample variance][sample-variance] incrementally, **skipping `NaN` values**. + +
+ +For a window of size `W`, the [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\bar{x} = \frac{1}{W} \sum_{i=0}^{W-1} x_i +``` + + + + + +and the [unbiased sample variance][sample-variance] is defined as + + + +```math +s^2 = \frac{1}{W-1} \sum_{i=0}^{W-1} ( x_i - \bar{x} )^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); +``` + +#### incrnanmmeanvar( \[out,] window ) + +Returns an accumulator `function` which incrementally computes a moving [arithmetic mean][arithmetic-mean] and [unbiased sample variance][sample-variance] **while skipping `NaN` values**. The `window` parameter defines the maximum number of most recent **non-NaN** values used to compute the moving statistics. + +```javascript +var accumulator = incrnanmmeanvar( 3 ); +``` + +By default, the returned accumulator `function` returns the accumulated values as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object. Unlike `incrmmeanvar`, this accumulator ignores (skips) any `NaN` values and does not allow them to propagate into the moving mean and variance. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var accumulator = incrnanmmeanvar( new Float64Array( 2 ), 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function updates and returns the current moving arithmetic mean and unbiased sample variance. If `x` is `NaN`, the value is ignored (i.e., it does not affect the window). If not provided an input value `x`, the accumulator function returns the current accumulated values without updating. + +```javascript +var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); + +var accumulator = incrnanmmeanvar( 3 ); + +var out = accumulator(); +// returns null + +// Fill the window (no NaNs yet)... +out = accumulator( 2.0 ); // [2.0] +// returns [ 2.0, 0.0 ] + +out = accumulator( NaN ); // NaN is ignored [2.0] +// returns [ 2.0, 0.0 ] + +out = accumulator( 1.0 ); // [2.0, 1.0] +// returns [ 1.5, 0.5 ] + +out = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns [ 2.0, 1.0 ] + +// Window begins sliding... +out = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +// returns [ -1.0, 28.0 ] + +out = accumulator( NaN ); // NaN ignored [1.0, 3.0, -7.0] +// returns [ -1.0, 28.0 ] + +out = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +// returns [ -3.0, 28.0 ] + +out = accumulator(); +// returns [ -3.0, 28.0 ] +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN`, the value is ignored and does not affect the moving window or the accumulated statistics. If non-numeric inputs are possible, you are advised to type check and handle them **before** passing values to the accumulator function. +- As `W` valid (non-`NaN`) values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window has received `W` valid values, each returned value is calculated from all valid inputs seen so far. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ArrayBuffer = require( '@stdlib/array/buffer' ); +var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); + +var offset; +var acc; +var buf; +var out; +var mv; +var N; +var v; +var i; +var j; + +// Define the number of accumulators: +N = 5; + +// Create an array buffer for storing accumulator output: +buf = new ArrayBuffer( N*2*8 ); + +// Initialize accumulators: +acc = []; +for ( i = 0; i < N; i++ ) { + // Compute the byte offset for the i­th accumulator: + offset = i * 2 * 8; + + // Create a typed array view over the correct section of the buffer: + out = new Float64Array( buf, offset, 2 ); + + // Create a moving mean/variance accumulator with window W = 5: + acc.push( incrnanmmeanvar( out, 5 ) ); +} + +// Simulate streaming data updates: +for ( i = 0; i < 100; i++ ) { + for ( j = 0; j < N; j++ ) { + + // Generate random values, but occasionally insert NaN. + // Any NaNs are ignored by the accumulator. + v = ( randu() > 0.1 ) ? randu() * 100 : NaN; + + // Update accumulator j: + acc[ j ]( v ); + } +} + +// Display final moving means and variances: +console.log( 'Mean\tVariance' ); +for ( i = 0; i < N; i++ ) { + mv = acc[ i ](); // Get the current result + console.log( mv[ 0 ].toFixed( 3 ) + '\t' + mv[ 1 ].toFixed( 3 ) ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js new file mode 100644 index 000000000000..7cc52cded276 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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 incrnanmmeanvar = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmmeanvar( (i%5)+1 ); + 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 = incrnanmmeanvar( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v.length !== 2 ) { + b.fail( 'should contain two elements' ); + } + } + b.toc(); + if ( v[ 0 ] !== v[ 0 ] || v[ 1 ] !== v[ 1 ] ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg new file mode 100644 index 000000000000..1a89a2bfb996 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over upper W EndFraction sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..f4722f986a70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals StartFraction 1 Over upper W minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg new file mode 100644 index 000000000000..cbdb866b2589 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg @@ -0,0 +1,40 @@ + + + + + NaN values are skipped when updating the moving window: + + + + + + + + + + 2.0 + NaN + 4.0 + NaN + 3.0 + + + + + + + + + + + + + + + { 2.0, 4.0, 3.0 } + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt new file mode 100644 index 000000000000..aee755efd6d6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt @@ -0,0 +1,52 @@ + +{{alias}}( [out,] W ) + Returns an accumulator function which incrementally computes a moving + arithmetic mean and unbiased sample variance while skipping NaN values. + + The `W` parameter defines the number of most recent non-NaN values over + which to compute the moving arithmetic mean and unbiased sample variance. + + If provided a value, the accumulator function returns updated accumulated + values. If not provided a value, the accumulator function returns the + current moving accumulated values. + + NaN values are ignored and do not affect the accumulator state. + + Until the window contains at least one valid (non-NaN) value, the accumulator + returns `null`. If the window contains only one valid value, the sample + variance is `0.0`. + + Parameters + ---------- + out: Array|TypedArray (optional) + Output array. + + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var v = accumulator() + null + > v = accumulator( 2.0 ) + [ 2.0, 0.0 ] + > v = accumulator( NaN ) + [ 2.0, 0.0 ] + > v = accumulator( 4.0 ) + [ 3.0, 2.0 ] + > v = accumulator( 6.0 ) + [ 4.0, 4.0 ] + > v = accumulator( NaN ) + [ 4.0, 4.0 ] + > v = accumulator() + [ 4.0, 4.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts new file mode 100644 index 000000000000..1eefbb2462bf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts @@ -0,0 +1,101 @@ +/* +* @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 + +/// + +import { ArrayLike } from '@stdlib/types/array'; + +/** +* If provided a value, the accumulator function returns an updated moving arithmetic mean and unbiased sample variance. If not provided a value, the accumulator function returns the current moving arithmetic mean and unbiased sample variance. +* +* ## Notes +* +* - If provided `NaN`, the value is **ignored** and the accumulator state is **not updated**. +* +* @param x - input value +* @returns output array or null +*/ +type accumulator = ( x?: number ) => ArrayLike | null; + +/** +* Returns an accumulator function which incrementally computes a moving arithmetic mean and unbiased sample variance while **skipping NaN values**. +* +* ## Notes +* +* - The `window` parameter defines the number of most-recent **valid (non-NaN)** values used to compute the moving statistics. +* - Until at least one valid value has been provided, the accumulator returns `null`. +* - If only one valid value has been observed, the sample variance is `0.0`. +* +* @param out - output array +* @param window - window size +* @throws window size must be a positive integer +* @returns accumulator function +*/ +declare function incrnanmmeanvar( out: ArrayLike, window: number ): accumulator; + +/** +* Returns an accumulator function which incrementally computes a moving arithmetic mean and unbiased sample variance while **skipping NaN values**. +* +* ## Notes +* +* - The `window` parameter defines the number of most-recent **valid (non-NaN)** values used to compute the moving statistics. +* - Until at least one valid value has been provided, the accumulator returns `null`. +* - If only one valid value has been observed, the sample variance is `0.0`. +* +* @param window - window size +* @throws window size must be a positive integer +* @returns accumulator function +* @example +* var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); +* +* var accumulator = incrnanmmeanvar( 3 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns [ 2.0, 0.0 ] +* +* v = accumulator( NaN ); +* // returns [ 2.0, 0.0 ] +* +* v = accumulator( 4.0 ); +* // returns [ 3.0, 2.0 ] +* +* v = accumulator( 6.0 ); +* // returns [ 4.0, 4.0 ] +* +* v = accumulator( NaN ); +* // returns [ 4.0, 4.0 ] +* +* v = accumulator( 8.0 ); +* // Window is [4,6,8] +* // mean = 6, variance = ((4-6)^2+(6-6)^2+(8-6)^2) / 2 = 4 +* // returns [ 6.0, 4.0 ] +* +* v = accumulator(); +* // returns [ 6.0, 4.0 ] +*/ +declare function incrnanmmeanvar( window: number ): accumulator; + + +// EXPORTS // + +export = incrnanmmeanvar; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts new file mode 100644 index 000000000000..4885114b1047 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts @@ -0,0 +1,78 @@ +/* +* @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 incrnanmmeanvar = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmmeanvar( 3 ); // $ExpectType accumulator + const out = [ 0.0, 0.0 ]; + incrnanmmeanvar( out, 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided a last argument that is not a number... +{ + incrnanmmeanvar( '5' ); // $ExpectError + incrnanmmeanvar( true ); // $ExpectError + incrnanmmeanvar( false ); // $ExpectError + incrnanmmeanvar( null ); // $ExpectError + incrnanmmeanvar( {} ); // $ExpectError + incrnanmmeanvar( ( x: number ): number => x ); // $ExpectError + + const out = [ 0.0, 0.0 ]; + incrnanmmeanvar( out, '5' ); // $ExpectError + incrnanmmeanvar( out, true ); // $ExpectError + incrnanmmeanvar( out, false ); // $ExpectError + incrnanmmeanvar( out, null ); // $ExpectError + incrnanmmeanvar( out, {} ); // $ExpectError + incrnanmmeanvar( out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an output array that is not an array-like object of numbers... +{ + incrnanmmeanvar( '5', 3 ); // $ExpectError + incrnanmmeanvar( true, 3 ); // $ExpectError + incrnanmmeanvar( false, 3 ); // $ExpectError + incrnanmmeanvar( null, 3 ); // $ExpectError + incrnanmmeanvar( {}, 3 ); // $ExpectError + incrnanmmeanvar( ( x: number ): number => x, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmmeanvar( 3 ); + + acc(); // $ExpectType ArrayLike | null + acc( 3.14 ); // $ExpectType ArrayLike | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmmeanvar( 3 ); + + 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/nanmmeanvar/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js new file mode 100644 index 000000000000..67417d7172a0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 incrnanmmeanvar = require( './../lib' ); + +var acc; +var out; +var i; + +// Create an accumulator for a window size of 5: +acc = incrnanmmeanvar( 5 ); + +// Simulated data stream: +var data = [ 2.0, NaN, 4.0, 3.0, 5.0, NaN, 6.0 ]; + +for ( i = 0; i < data.length; i++ ) { + out = acc( data[ i ] ); + console.log( 'x: %d -> mean: %d, variance: %d', data[ i ], out ? out[0] : null, out ? out[1] : null ); +} + +console.log( '\nCurrent values:', acc() ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js new file mode 100644 index 000000000000..0b59d82a1b17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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 a moving arithmetic mean and unbiased sample variance incrementally. +* +* @module @stdlib/stats/incr/nanmmeanvar +* +* @example +* var incrmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); +* +* var accumulator = incrnanmmeanvar( 3 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns [ 2.0, 0.0 ] +* +* v = accumulator( NaN ); +* // returns [ 2.0, 0.0 ] // NaN skipped +* +* v = accumulator( 4.0 ); +* // returns [ 3.0, 2.0 ] +* +* v = accumulator(); +* // returns [ 3.0, 2.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js new file mode 100644 index 000000000000..759d95d5d202 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -0,0 +1,84 @@ +/** +* @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 incrmmeanvar = require( '@stdlib/stats/incr/mmeanvar' ); +var isArrayLike = require( '@stdlib/assert/is-array-like' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving arithmetic mean and unbiased sample variance, skipping NaN values. +* +* @param {(ArrayLike|PositiveInteger)} out - output array or window size +* @param {PositiveInteger} [W] - window size +* @throws {TypeError} must provide a positive integer number for window size +* @returns {Function} accumulator function +* +* @example +* var acc = incrnanmmeanvar( 3 ); +* acc( 2.0 ); // => [ 2.0, 0.0 ] +* acc( NaN ); // => [ 2.0, 0.0 ] (NaN skipped) +* acc( 4.0 ); // => [ 3.0, 2.0 ] +* +* @example +* var out = [ 0.0, 0.0 ]; +* var acc = incrnanmmeanvar( out, 3 ); +* acc( 2.0 ); +* console.log( out ); // => [ 2.0, 0.0 ] +*/ +function incrnanmmeanvar( out, W ) { + var mmeanvar; + + // Detect signature: (W) or (out, W) + if ( isArrayLike( out ) ) { + mmeanvar = incrmmeanvar( out, W ); + } else { + mmeanvar = incrmmeanvar( out ); + } + + return accumulator; + + /** + * Accumulator function. + * + * @param {number} [x] - input value + * @returns {(Array|null)} current mean and variance + */ + function accumulator( x ) { + // If no arguments → return current state: + if ( arguments.length === 0 ) { + return mmeanvar(); + } + // Skip NaNs (do not update): + if ( isnan( x ) ) { + return mmeanvar(); + } + // Update with valid number: + return mmeanvar( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmmeanvar; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json new file mode 100644 index 000000000000..8a5623c3acc3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/stats/incr/nanmmeanvar", + "version": "0.0.0", + "description": "Compute a moving arithmetic mean and unbiased sample variance incrementally.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "mean", + "arithmetic mean", + "central tendency", + "moving mean", + "moving average", + "variance", + "sample", + "sample variance", + "unbiased", + "stdev", + "standard", + "deviation", + "dispersion", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving" + ] +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js new file mode 100644 index 000000000000..d7475bc0194b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js @@ -0,0 +1,414 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanmmeanvar = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmmeanvar, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer for the window size', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + 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() { + incrnanmmeanvar( value ); + }; + } +}); + +tape( 'the function throws an error if not provided a positive integer for the window size', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + 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() { + incrnanmmeanvar( value ); + }; + } +}); + +tape( 'the function throws an error if not provided a positive integer for the window size (output)', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + false, + null, + void 0, + NaN, + [], + {}, + 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() { + incrnanmmeanvar( [ 0.0, 0.0 ], value ); + }; + } +}); + +tape( 'the function throws an error if not provided an array-like object for an output argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + true, + false, + null, + void 0, + NaN, + {}, + 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() { + incrnanmmeanvar( value, 3 ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanmmeanvar( 3 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (output)', function test( t ) { + t.strictEqual( typeof incrnanmmeanvar( [ 0.0, 0.0 ], 3 ), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving arithmetic mean and unbiased sample variance incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, 4.0, -1.0, 3.0, 1.0 ]; + N = data.length; + + acc = incrnanmmeanvar( 3 ); + + expected = [ + [ 2.0, 0.0 ], + [ 2.5, 0.5 ], + [ 3.0, 1.0 ], + [ 2.0, 7.0 ], + [ 2.0, 7.0 ], + [ 1.0, 4.0 ] + ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[ i ] ); + t.deepEqual( actual, expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the accumulator function computes a moving arithmetic mean and unbiased sample variance incrementally (output)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var out; + var N; + var i; + + data = [ 2.0, 3.0, 4.0, -1.0, 3.0, 1.0 ]; + N = data.length; + + out = [ 0.0, 0.0 ]; + acc = incrnanmmeanvar( out, 3 ); + + expected = [ + [ 2.0, 0.0 ], + [ 2.5, 0.5 ], + [ 3.0, 1.0 ], + [ 2.0, 7.0 ], + [ 2.0, 7.0 ], + [ 1.0, 4.0 ] + ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[ i ] ); + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current arithmetic mean and unbiased sample variance', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var i; + + data = [ 2.0, 3.0, 10.0 ]; + acc = incrnanmmeanvar( 3 ); + for ( i = 0; i < data.length-1; i++ ) { + acc( data[ i ] ); + } + t.deepEqual( acc(), [ 2.5, 0.5 ], 'returns expected value' ); + + acc( data[ data.length-1 ] ); + + expected = [ 5.0, 19.0 ]; + actual = acc(); + + t.strictEqual( actual[ 0 ], expected[ 0 ], 'returns expected value' ); + + delta = abs( actual[ 1 ] - expected[ 1 ] ); + tol = EPS * expected[ 1 ]; + t.strictEqual( delta < tol, true, 'expected: '+expected[ 1 ]+'. actual: '+actual+'. tol: '+tol+'. delta: '+delta+'.' ); + + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmmeanvar( 3 ); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'if only one datum has been provided, the accumulator function returns `0` for the sample variance', function test( t ) { + var acc = incrnanmmeanvar( 3 ); + var v = acc( 2.0 ); + t.strictEqual( v[ 0 ], 2.0, 'returns expected value' ); + t.strictEqual( v[ 1 ], 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if the window size is `1`, the accumulator functions always returns `0` for the sample variance', function test( t ) { + var acc; + var out; + var v; + var i; + + acc = incrnanmmeanvar( 1 ); + for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + out = acc( v ); + t.strictEqual( out[ 0 ], v, 'returns expected value' ); + t.strictEqual( out[ 1 ], 0.0, 'returns expected value' ); + } + t.end(); +}); + +tape( 'if provided `NaN`, the accumulator skips the value and returns the previous mean and variance', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmeanvar( 3 ); + + data = [ + NaN, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 + ]; + expected = [ + null, + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ] + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + + + if ( i === 0 ) { + t.strictEqual( v, null, 'NaN ignored; still no data' ); + continue; + } + if ( isnan( data[ i ] ) ) { + t.deepEqual( v, acc(), 'NaN skipped — state unchanged at step '+i ); + } + else { + t.strictEqual( isnan( v[0] ), false, 'mean is not NaN' ); + t.strictEqual( isnan( v[1] ), false, 'variance is not NaN' ); + } + } + t.end(); +}); + +tape( 'if provided `NaN`, the accumulator skips values when W=1', function test( t ) { + var expected; + var data; + var acc; + var v; + var i; + + acc = incrnanmmeanvar( 1 ); + + data = [ + NaN, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 + ]; + expected = [ + null, + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ] + ]; + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.deepEqual( v, expected[ i ], 'returns expected value at step '+i ); + } + t.end(); +}); From 80cbbdb2cdd2d543913daea8ecd90873eacf6bb8 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 11 Nov 2025 17:35:03 +0000 Subject: [PATCH 02/17] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md | 2 +- .../@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts | 2 +- .../@stdlib/stats/incr/nanmmeanvar/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 0ae66d01226d..dcb941d3166f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js index 7cc52cded276..e00885173070 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts index 1eefbb2462bf..d01471fc10c9 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts index 4885114b1047..cb203ef0b27a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js index 67417d7172a0..23774c25875a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js index 0b59d82a1b17..04294e615206 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 759d95d5d202..72ea8c15ba24 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js index d7475bc0194b..4e6906a677c3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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 f7c0075e7b3962e6c16e2bc89f6ca50c46333585 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 11 Nov 2025 23:19:32 +0530 Subject: [PATCH 03/17] fix: correct import variable name in example and also added trailing newline --- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js index 04294e615206..5adcdbca1325 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/index.js @@ -24,7 +24,7 @@ * @module @stdlib/stats/incr/nanmmeanvar * * @example -* var incrmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); +* var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); * * var accumulator = incrnanmmeanvar( 3 ); * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 72ea8c15ba24..0b0bb6f6e4eb 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -81,4 +81,4 @@ function incrnanmmeanvar( out, W ) { // EXPORTS // -module.exports = incrnanmmeanvar; \ No newline at end of file +module.exports = incrnanmmeanvar; From 4ae8a4b69f6139d12644be001299fea8554b900e Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 2 Dec 2025 08:02:18 +0530 Subject: [PATCH 04/17] fix:lint_changed_files / Lint Changed Files (pull_request) and also fix:run_affected_examples / Run changed examples (pull_request) --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 20 +++--- .../incr/nanmmeanvar/benchmark/benchmark.js | 2 +- .../stats/incr/nanmmeanvar/docs/repl.txt | 25 +++---- .../incr/nanmmeanvar/docs/types/index.d.ts | 17 +++-- .../stats/incr/nanmmeanvar/lib/main.js | 9 +-- .../stats/incr/nanmmeanvar/test/test.js | 71 +++++++++---------- 6 files changed, 72 insertions(+), 72 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index dcb941d3166f..997bec52539d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -88,37 +88,34 @@ If provided an input value `x`, the accumulator function updates and returns the ```javascript var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); - var accumulator = incrnanmmeanvar( 3 ); - var out = accumulator(); -// returns null // Fill the window (no NaNs yet)... out = accumulator( 2.0 ); // [2.0] -// returns [ 2.0, 0.0 ] +// => [ 2.0, 0.0 ] out = accumulator( NaN ); // NaN is ignored [2.0] -// returns [ 2.0, 0.0 ] +// => [ 2.0, 0.0 ] out = accumulator( 1.0 ); // [2.0, 1.0] -// returns [ 1.5, 0.5 ] +// => [ 1.5, 0.5 ] out = accumulator( 3.0 ); // [2.0, 1.0, 3.0] -// returns [ 2.0, 1.0 ] +// => [ 2.0, 1.0 ] // Window begins sliding... out = accumulator( -7.0 ); // [1.0, 3.0, -7.0] -// returns [ -1.0, 28.0 ] +// => [ -1.0, 28.0 ] out = accumulator( NaN ); // NaN ignored [1.0, 3.0, -7.0] -// returns [ -1.0, 28.0 ] +// => [ -1.0, 28.0 ] out = accumulator( -5.0 ); // [3.0, -7.0, -5.0] -// returns [ -3.0, 28.0 ] +// => [ -3.0, 28.0 ] out = accumulator(); -// returns [ -3.0, 28.0 ] +// => [ -3.0, 28.0 ] ``` @@ -141,7 +138,6 @@ out = accumulator(); ## Examples - ```javascript var randu = require( '@stdlib/random/base/randu' ); var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js index e00885173070..999d303f84ee 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js @@ -66,4 +66,4 @@ bench( pkg+'::accumulator', function benchmark( b ) { } b.pass( 'benchmark finished' ); b.end(); -}); \ No newline at end of file +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt index aee755efd6d6..652afcddf10d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt @@ -10,10 +10,12 @@ values. If not provided a value, the accumulator function returns the current moving accumulated values. - NaN values are ignored and do not affect the accumulator state. + NaN values are ignored + and do not affect the accumulator state. - Until the window contains at least one valid (non-NaN) value, the accumulator - returns `null`. If the window contains only one valid value, the sample + Until the window contains at least one valid (non-NaN) value, the + accumulator returns `null`. + If the window contains only one valid value, the sample variance is `0.0`. Parameters @@ -35,18 +37,17 @@ > var v = accumulator() null > v = accumulator( 2.0 ) - [ 2.0, 0.0 ] - > v = accumulator( NaN ) - [ 2.0, 0.0 ] + [ 2, 0 ] + > v = accumulator( NaN ) + [ 2, 0 ] > v = accumulator( 4.0 ) - [ 3.0, 2.0 ] + [ 3, 2 ] > v = accumulator( 6.0 ) - [ 4.0, 4.0 ] - > v = accumulator( NaN ) - [ 4.0, 4.0 ] + [ 4, 4 ] + > v = accumulator( NaN ) + [ 4, 4 ] > v = accumulator() - [ 4.0, 4.0 ] + [ 4, 4 ] See Also -------- - diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts index d01471fc10c9..27ebba87301a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts @@ -30,6 +30,7 @@ import { ArrayLike } from '@stdlib/types/array'; * - If provided `NaN`, the value is **ignored** and the accumulator state is **not updated**. * * @param x - input value +* * @returns output array or null */ type accumulator = ( x?: number ) => ArrayLike | null; @@ -47,6 +48,7 @@ type accumulator = ( x?: number ) => ArrayLike | null; * @param window - window size * @throws window size must be a positive integer * @returns accumulator function +* */ declare function incrnanmmeanvar( out: ArrayLike, window: number ): accumulator; @@ -62,6 +64,7 @@ declare function incrnanmmeanvar( out: ArrayLike, window: number ): accu * @param window - window size * @throws window size must be a positive integer * @returns accumulator function +* * @example * var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); * @@ -71,27 +74,27 @@ declare function incrnanmmeanvar( out: ArrayLike, window: number ): accu * // returns null * * v = accumulator( 2.0 ); -* // returns [ 2.0, 0.0 ] +* // returns [ 2, 0 ] * * v = accumulator( NaN ); -* // returns [ 2.0, 0.0 ] +* // returns [ 2, 0 ] * * v = accumulator( 4.0 ); -* // returns [ 3.0, 2.0 ] +* // returns [ 3, 2 ] * * v = accumulator( 6.0 ); -* // returns [ 4.0, 4.0 ] +* // returns [ 4, 4 ] * * v = accumulator( NaN ); -* // returns [ 4.0, 4.0 ] +* // returns [ 4, 4 ] * * v = accumulator( 8.0 ); * // Window is [4,6,8] * // mean = 6, variance = ((4-6)^2+(6-6)^2+(8-6)^2) / 2 = 4 -* // returns [ 6.0, 4.0 ] +* // returns [ 6, 4 ] * * v = accumulator(); -* // returns [ 6.0, 4.0 ] +* // returns [ 6, 4 ] */ declare function incrnanmmeanvar( window: number ): accumulator; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 0b0bb6f6e4eb..97fbe2fa3845 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -36,15 +36,15 @@ var isArrayLike = require( '@stdlib/assert/is-array-like' ); * * @example * var acc = incrnanmmeanvar( 3 ); -* acc( 2.0 ); // => [ 2.0, 0.0 ] -* acc( NaN ); // => [ 2.0, 0.0 ] (NaN skipped) -* acc( 4.0 ); // => [ 3.0, 2.0 ] +* acc( 2.0 ); // returns [ 2, 0 ] +* acc( NaN ); // returns [ 2, 0 ] (NaN skipped) +* acc( 4.0 ); // returns [ 3, 2 ] * * @example * var out = [ 0.0, 0.0 ]; * var acc = incrnanmmeanvar( out, 3 ); * acc( 2.0 ); -* console.log( out ); // => [ 2.0, 0.0 ] +* console.log( out ); // returns [ 2, 0 ] */ function incrnanmmeanvar( out, W ) { var mmeanvar; @@ -63,6 +63,7 @@ function incrnanmmeanvar( out, W ) { * * @param {number} [x] - input value * @returns {(Array|null)} current mean and variance + * @private */ function accumulator( x ) { // If no arguments → return current state: diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js index 4e6906a677c3..bc6ebb99cc53 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js @@ -308,46 +308,46 @@ tape( 'if provided `NaN`, the accumulator skips the value and returns the previo 3.14, NaN, 3.14, - 3.14, - NaN, - NaN, - NaN, - NaN, - 3.14 + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 ]; expected = [ null, - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ] + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ] ]; for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); - + if ( i === 0 ) { t.strictEqual( v, null, 'NaN ignored; still no data' ); continue; } - if ( isnan( data[ i ] ) ) { + if ( isnan( data[ i ] ) ) { t.deepEqual( v, acc(), 'NaN skipped — state unchanged at step '+i ); } - else { + else { t.strictEqual( isnan( v[0] ), false, 'mean is not NaN' ); t.strictEqual( isnan( v[1] ), false, 'variance is not NaN' ); } @@ -363,7 +363,6 @@ tape( 'if provided `NaN`, the accumulator skips values when W=1', function test( var i; acc = incrnanmmeanvar( 1 ); - data = [ NaN, 3.14, @@ -386,25 +385,25 @@ tape( 'if provided `NaN`, the accumulator skips values when W=1', function test( 3.14 ]; expected = [ - null, - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], + null, + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], - [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], - [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], - [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], [ 3.14, 0.0 ], - [ 3.14, 0.0 ] + [ 3.14, 0.0 ] ]; for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); From f39415cbf697e7cb7f32790c7f8641d9ff7fc6a5 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Wed, 3 Dec 2025 16:22:59 +0530 Subject: [PATCH 05/17] fix: run_affected_examples / Run changed examples (pull_request) and lint_changed_files / Lint Changed Files (pull_request) --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 3 +- .../stats/incr/nanmmeanvar/docs/repl.txt | 5 +- .../incr/nanmmeanvar/docs/types/index.d.ts | 4 +- .../stats/incr/nanmmeanvar/examples/index.js | 2 +- .../stats/incr/nanmmeanvar/package.json | 2 +- .../stats/incr/nanmmeanvar/test/test.js | 72 +++++++++---------- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 997bec52539d..7456040257b7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -90,6 +90,7 @@ If provided an input value `x`, the accumulator function updates and returns the var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); var accumulator = incrnanmmeanvar( 3 ); var out = accumulator(); +// => null // Fill the window (no NaNs yet)... out = accumulator( 2.0 ); // [2.0] @@ -138,6 +139,7 @@ out = accumulator(); ## Examples + ```javascript var randu = require( '@stdlib/random/base/randu' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -176,7 +178,6 @@ for ( i = 0; i < N; i++ ) { // Simulate streaming data updates: for ( i = 0; i < 100; i++ ) { for ( j = 0; j < N; j++ ) { - // Generate random values, but occasionally insert NaN. // Any NaNs are ignored by the accumulator. v = ( randu() > 0.1 ) ? randu() * 100 : NaN; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt index 652afcddf10d..6d782127615c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt @@ -10,10 +10,9 @@ values. If not provided a value, the accumulator function returns the current moving accumulated values. - NaN values are ignored - and do not affect the accumulator state. + NaN values are ignored and do not affect the accumulator state. - Until the window contains at least one valid (non-NaN) value, the + Until the window contains at least one valid (non-NaN) value, the accumulator returns `null`. If the window contains only one valid value, the sample variance is `0.0`. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts index 27ebba87301a..79fc9a5da38b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/types/index.d.ts @@ -48,7 +48,7 @@ type accumulator = ( x?: number ) => ArrayLike | null; * @param window - window size * @throws window size must be a positive integer * @returns accumulator function -* +* */ declare function incrnanmmeanvar( out: ArrayLike, window: number ): accumulator; @@ -64,7 +64,7 @@ declare function incrnanmmeanvar( out: ArrayLike, window: number ): accu * @param window - window size * @throws window size must be a positive integer * @returns accumulator function -* +* * @example * var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js index 23774c25875a..65a7324c63f1 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/examples/index.js @@ -35,4 +35,4 @@ for ( i = 0; i < data.length; i++ ) { console.log( 'x: %d -> mean: %d, variance: %d', data[ i ], out ? out[0] : null, out ? out[1] : null ); } -console.log( '\nCurrent values:', acc() ); \ No newline at end of file +console.log( '\nCurrent values:', acc() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json index 8a5623c3acc3..94f1594f3682 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/package.json @@ -77,4 +77,4 @@ "window", "moving" ] -} \ No newline at end of file +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js index bc6ebb99cc53..30dc05554afe 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js @@ -296,45 +296,45 @@ tape( 'if provided `NaN`, the accumulator skips the value and returns the previo data = [ NaN, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - NaN, - NaN, - NaN, - NaN, - 3.14 + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + 3.14, + NaN, + 3.14, + 3.14, + NaN, + NaN, + NaN, + NaN, + 3.14 ]; expected = [ null, - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ] + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ], + [ 3.14, 0.0 ] ]; for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); From 2c7c6d6cabcb8ffd798e71589f6415e503882d92 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Sat, 13 Dec 2025 11:15:12 +0530 Subject: [PATCH 06/17] Tests updated with more meaningful in terms of actual computation. --- .../stats/incr/nanmmeanvar/lib/main.js | 2 +- .../stats/incr/nanmmeanvar/test/test.js | 102 +++++++----------- 2 files changed, 39 insertions(+), 65 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 97fbe2fa3845..4a8ad61d9cce 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -50,7 +50,7 @@ function incrnanmmeanvar( out, W ) { var mmeanvar; // Detect signature: (W) or (out, W) - if ( isArrayLike( out ) ) { + if ( arguments.length > 1 ) { mmeanvar = incrmmeanvar( out, W ); } else { mmeanvar = incrmmeanvar( out ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js index 30dc05554afe..3237c9f269c3 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/test/test.js @@ -296,45 +296,19 @@ tape( 'if provided `NaN`, the accumulator skips the value and returns the previo data = [ NaN, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - 3.14, - NaN, - 3.14, - 3.14, - NaN, + 1.5, + 2.5, NaN, - NaN, - NaN, - 3.14 + 3.5, + 4.5, ]; expected = [ null, - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ] + [ 1.5, 0.0 ], + [ 2.0, 0.5 ], + [ 2.0, 0.5 ], + [ 2.5, 1.0 ], + [ 3.5, 1.0 ], ]; for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); @@ -365,45 +339,45 @@ tape( 'if provided `NaN`, the accumulator skips values when W=1', function test( acc = incrnanmmeanvar( 1 ); data = [ NaN, - 3.14, - 3.14, + 7.2, NaN, - 3.14, - 3.14, - 3.14, + 12.8, + 12.8, NaN, - 3.14, - 3.14, - 3.14, + 4.6, + 4.6, + NaN, + 9.9, NaN, - 3.14, - 3.14, NaN, + 15.3, + 15.3, NaN, + 8.1, NaN, NaN, - 3.14 + 3.7 ]; expected = [ null, - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ], - [ 3.14, 0.0 ] + [ 7.2, 0.0 ], + [ 7.2, 0.0 ], + [ 12.8, 0.0 ], + [ 12.8, 0.0 ], + [ 12.8, 0.0 ], + [ 4.6, 0.0 ], + [ 4.6, 0.0 ], + [ 4.6, 0.0 ], + [ 9.9, 0.0 ], + [ 9.9, 0.0 ], + [ 9.9, 0.0 ], + [ 15.3, 0.0 ], + [ 15.3, 0.0 ], + [ 15.3, 0.0 ], + [ 8.1, 0.0 ], + [ 8.1, 0.0 ], + [ 8.1, 0.0 ], + [ 3.7, 0.0 ] ]; for ( i = 0; i < data.length; i++ ) { v = acc( data[ i ] ); From 0348aaff8a8cb03a83fb3d44e1514c45dd20d462 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Mon, 15 Dec 2025 22:17:00 +0530 Subject: [PATCH 07/17] Cleared linting issues --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 14 +++++++------- .../@stdlib/stats/incr/nanmmeanvar/lib/main.js | 16 ++++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 7456040257b7..0b80854e406a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -93,26 +93,26 @@ var out = accumulator(); // => null // Fill the window (no NaNs yet)... -out = accumulator( 2.0 ); // [2.0] +out = accumulator( 2.0 ); // => [ 2.0, 0.0 ] -out = accumulator( NaN ); // NaN is ignored [2.0] +out = accumulator( NaN ); // => [ 2.0, 0.0 ] -out = accumulator( 1.0 ); // [2.0, 1.0] +out = accumulator( 1.0 ); // => [ 1.5, 0.5 ] -out = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +out = accumulator( 3.0 ); // => [ 2.0, 1.0 ] // Window begins sliding... -out = accumulator( -7.0 ); // [1.0, 3.0, -7.0] +out = accumulator( -7.0 ); // => [ -1.0, 28.0 ] -out = accumulator( NaN ); // NaN ignored [1.0, 3.0, -7.0] +out = accumulator( NaN ); // => [ -1.0, 28.0 ] -out = accumulator( -5.0 ); // [3.0, -7.0, -5.0] +out = accumulator( -5.0 ); // => [ -3.0, 28.0 ] out = accumulator(); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 4a8ad61d9cce..c5af5e495321 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -19,9 +19,9 @@ 'use strict'; // MODULES // + var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrmmeanvar = require( '@stdlib/stats/incr/mmeanvar' ); -var isArrayLike = require( '@stdlib/assert/is-array-like' ); // MAIN // @@ -36,15 +36,19 @@ var isArrayLike = require( '@stdlib/assert/is-array-like' ); * * @example * var acc = incrnanmmeanvar( 3 ); -* acc( 2.0 ); // returns [ 2, 0 ] -* acc( NaN ); // returns [ 2, 0 ] (NaN skipped) -* acc( 4.0 ); // returns [ 3, 2 ] +* acc( 2.0 ); +* // returns [ 2, 0 ] +* acc( NaN ); +* // returns [ 2, 0 ] (NaN skipped) +* acc( 4.0 ); +* // returns [ 3, 2 ] * * @example * var out = [ 0.0, 0.0 ]; * var acc = incrnanmmeanvar( out, 3 ); * acc( 2.0 ); -* console.log( out ); // returns [ 2, 0 ] +* console.log( out ); +* // returns [ 2, 0 ] */ function incrnanmmeanvar( out, W ) { var mmeanvar; @@ -61,9 +65,9 @@ function incrnanmmeanvar( out, W ) { /** * Accumulator function. * + * @private * @param {number} [x] - input value * @returns {(Array|null)} current mean and variance - * @private */ function accumulator( x ) { // If no arguments → return current state: From 4fdb603db9c019826388084f0887f2b99623747c Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 16 Dec 2025 21:09:12 +0530 Subject: [PATCH 08/17] fixed run_affected_examples / Run changed examples (pull_request) and lint_changed_files / Lint Changed Files (pull_request) --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 30 +++++++++---------- .../stats/incr/nanmmeanvar/lib/main.js | 11 +++---- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 0b80854e406a..e434820869ac 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -90,33 +90,33 @@ If provided an input value `x`, the accumulator function updates and returns the var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); var accumulator = incrnanmmeanvar( 3 ); var out = accumulator(); -// => null +// returns null // Fill the window (no NaNs yet)... -out = accumulator( 2.0 ); -// => [ 2.0, 0.0 ] +out = accumulator( 2.0 ); +// returns [ 2.0, 0.0 ] out = accumulator( NaN ); -// => [ 2.0, 0.0 ] +// returns [ 2.0, 0.0 ] -out = accumulator( 1.0 ); -// => [ 1.5, 0.5 ] +out = accumulator( 1.0 ); +// returns [ 1.5, 0.5 ] -out = accumulator( 3.0 ); -// => [ 2.0, 1.0 ] +out = accumulator( 3.0 ); +// returns [ 2.0, 1.0 ] // Window begins sliding... -out = accumulator( -7.0 ); -// => [ -1.0, 28.0 ] +out = accumulator( -7.0 ); +// returns [ -1.0, 28.0 ] -out = accumulator( NaN ); -// => [ -1.0, 28.0 ] +out = accumulator( NaN ); +// returns [ -1.0, 28.0 ] -out = accumulator( -5.0 ); -// => [ -3.0, 28.0 ] +out = accumulator( -5.0 ); +// returns [ -3.0, 28.0 ] out = accumulator(); -// => [ -3.0, 28.0 ] +// returns [ -3.0, 28.0 ] ``` diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index c5af5e495321..2a7e1e7db424 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -36,18 +36,15 @@ var incrmmeanvar = require( '@stdlib/stats/incr/mmeanvar' ); * * @example * var acc = incrnanmmeanvar( 3 ); -* acc( 2.0 ); -* // returns [ 2, 0 ] -* acc( NaN ); -* // returns [ 2, 0 ] (NaN skipped) -* acc( 4.0 ); -* // returns [ 3, 2 ] +* acc( 2.0 ); +* acc( NaN ); +* acc( 4.0 ); * * @example * var out = [ 0.0, 0.0 ]; * var acc = incrnanmmeanvar( out, 3 ); * acc( 2.0 ); -* console.log( out ); +* console.log( out ); * // returns [ 2, 0 ] */ function incrnanmmeanvar( out, W ) { From 9bb404d822e0535936268ae236176f13dac495a4 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 30 Dec 2025 21:42:58 +0530 Subject: [PATCH 09/17] Fixed : lint_changed_files / Lint Changed Files (pull_request) --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 19 +++++++------- .../stats/incr/nanmmeanvar/docs/repl.txt | 26 +++++++++---------- .../stats/incr/nanmmeanvar/lib/main.js | 1 - 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index e434820869ac..1a5e5ff1c717 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -88,35 +88,34 @@ If provided an input value `x`, the accumulator function updates and returns the ```javascript var incrnanmmeanvar = require( '@stdlib/stats/incr/nanmmeanvar' ); + var accumulator = incrnanmmeanvar( 3 ); var out = accumulator(); // returns null -// Fill the window (no NaNs yet)... out = accumulator( 2.0 ); -// returns [ 2.0, 0.0 ] +// returns [ 2, 0 ] -out = accumulator( NaN ); -// returns [ 2.0, 0.0 ] +out = accumulator( NaN ); +// returns [ 2, 0 ] out = accumulator( 1.0 ); // returns [ 1.5, 0.5 ] out = accumulator( 3.0 ); -// returns [ 2.0, 1.0 ] +// returns [ 2, 1 ] -// Window begins sliding... out = accumulator( -7.0 ); -// returns [ -1.0, 28.0 ] +// returns [ -1, 28 ] out = accumulator( NaN ); -// returns [ -1.0, 28.0 ] +// returns [ -1, 28 ] out = accumulator( -5.0 ); -// returns [ -3.0, 28.0 ] +// returns [ -3, 28 ] out = accumulator(); -// returns [ -3.0, 28.0 ] +// returns [ -3, 28 ] ``` diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt index 6d782127615c..391f01776908 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/repl.txt @@ -33,20 +33,20 @@ Examples -------- > var accumulator = {{alias}}( 3 ); - > var v = accumulator() + > accumulator() null - > v = accumulator( 2.0 ) - [ 2, 0 ] - > v = accumulator( NaN ) - [ 2, 0 ] - > v = accumulator( 4.0 ) - [ 3, 2 ] - > v = accumulator( 6.0 ) - [ 4, 4 ] - > v = accumulator( NaN ) - [ 4, 4 ] - > v = accumulator() - [ 4, 4 ] + > accumulator( 2.0 ) + [ 2.0, 0.0 ] + > accumulator( NaN ) + [ 2.0, 0.0 ] + > accumulator( 4.0 ) + [ 3.0, 2.0 ] + > accumulator( 6.0 ) + [ 4.0, 4.0 ] + > accumulator( NaN ) + [ 4.0, 4.0 ] + > accumulator() + [ 4.0, 4.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 2a7e1e7db424..916090feed67 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -50,7 +50,6 @@ var incrmmeanvar = require( '@stdlib/stats/incr/mmeanvar' ); function incrnanmmeanvar( out, W ) { var mmeanvar; - // Detect signature: (W) or (out, W) if ( arguments.length > 1 ) { mmeanvar = incrmmeanvar( out, W ); } else { From 2e32f592518e5a149787f5d6ff036c4f8998e2dc Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 30 Dec 2025 23:58:30 +0530 Subject: [PATCH 10/17] Removed the unwanted related notations in README --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 1a5e5ff1c717..944ca32bca9e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md @@ -206,12 +206,6 @@ for ( i = 0; i < N; i++ ) { ## See Also -- [`@stdlib/stats/incr/mmeanvar`][@stdlib/stats/incr/mmeanvar]: compute a moving arithmetic mean and unbiased sample variance incrementally (**propagates NaN values**). -- [`@stdlib/stats/incr/meanvar`][@stdlib/stats/incr/meanvar]: compute an arithmetic mean and unbiased sample variance incrementally. -- [`@stdlib/stats/incr/mmean`][@stdlib/stats/incr/mmean]: compute a moving arithmetic mean incrementally. -- [`@stdlib/stats/incr/mmeanstdev`][@stdlib/stats/incr/mmeanstdev]: compute a moving arithmetic mean and corrected sample standard deviation incrementally. -- [`@stdlib/stats/incr/mvariance`][@stdlib/stats/incr/mvariance]: compute a moving unbiased sample variance incrementally. - @@ -224,20 +218,6 @@ for ( i = 0; i < N; i++ ) { [sample-variance]: https://en.wikipedia.org/wiki/Variance - - -[@stdlib/stats/incr/mmeanvar]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmeanvar - -[@stdlib/stats/incr/meanvar]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/meanvar - -[@stdlib/stats/incr/mmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmean - -[@stdlib/stats/incr/mmeanstdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmeanstdev - -[@stdlib/stats/incr/mvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mvariance - - - From a93936bcdf97d2a885b21fd7cc92c478940623d5 Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Wed, 31 Dec 2025 14:25:30 +0530 Subject: [PATCH 11/17] Removed the unwanted image file --- .../incr/nanmmeanvar/docs/img/nan_skip.svg | 40 ------------------- 1 file changed, 40 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg deleted file mode 100644 index cbdb866b2589..000000000000 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/nan_skip.svg +++ /dev/null @@ -1,40 +0,0 @@ - - - - - NaN values are skipped when updating the moving window: - - - - - - - - - - 2.0 - NaN - 4.0 - NaN - 3.0 - - - - - - - - - - - - - - - { 2.0, 4.0, 3.0 } - - From c7a945a8a00c199571b1ffa9e51b75704e403e64 Mon Sep 17 00:00:00 2001 From: Anoof Mohammed KP Date: Thu, 15 Jan 2026 11:21:32 +0530 Subject: [PATCH 12/17] Update lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js Co-authored-by: Athan Signed-off-by: Anoof Mohammed KP --- .../@stdlib/stats/incr/nanmmeanvar/lib/main.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js index 916090feed67..bdf683444bad 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/lib/main.js @@ -66,15 +66,9 @@ function incrnanmmeanvar( out, W ) { * @returns {(Array|null)} current mean and variance */ function accumulator( x ) { - // If no arguments → return current state: - if ( arguments.length === 0 ) { + if ( arguments.length === 0 || isnan(x ) ) { return mmeanvar(); } - // Skip NaNs (do not update): - if ( isnan( x ) ) { - return mmeanvar(); - } - // Update with valid number: return mmeanvar( x ); } } From d7777ccfffd28fe237f9bd1b7093fec71e02c0ad Mon Sep 17 00:00:00 2001 From: anoofmhd Date: Tue, 10 Mar 2026 17:58:54 +0530 Subject: [PATCH 13/17] feat: add incremental NaN-aware moving mean and variance module. --- .../@stdlib/stats/incr/nanmmeanvar/README.md | 2 +- .../incr/nanmmeanvar/benchmark/benchmark.js | 44 +-- .../docs/img/equation_arithmetic_mean.svg | 18 ++ .../img/equation_unbiased_sample_variance.svg | 18 ++ .../stats/incr/nanmmeanvar/docs/repl.txt | 64 +++-- .../incr/nanmmeanvar/docs/types/index.d.ts | 8 +- .../stats/incr/nanmmeanvar/docs/types/test.ts | 93 ++++--- .../stats/incr/nanmmeanvar/examples/index.js | 16 +- .../stats/incr/nanmmeanvar/lib/index.js | 4 +- .../stats/incr/nanmmeanvar/lib/main.js | 20 +- .../stats/incr/nanmmeanvar/test/test.js | 258 +++++++++--------- 11 files changed, 310 insertions(+), 235 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md index 944ca32bca9e..3a2c1392be66 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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/nanmmeanvar/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js index 999d303f84ee..c804e5672db8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/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. @@ -20,50 +20,50 @@ // MODULES // -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var pkg = require( './../package.json' ).name; -var incrnanmmeanvar = require( './../lib' ); +var bench = require('@stdlib/bench'); +var randu = require('@stdlib/random/base/randu'); +var pkg = require('./../package.json').name; +var incrnanmmeanvar = require('./../lib'); // MAIN // -bench( pkg, function benchmark( b ) { +bench(pkg, function benchmark(b) { var f; var i; b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - f = incrnanmmeanvar( (i%5)+1 ); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); + for (i = 0; i < b.iterations; i++) { + f = incrnanmmeanvar((i % 5) + 1); + if (typeof f !== 'function') { + b.fail('should return a function'); } } b.toc(); - if ( typeof f !== 'function' ) { - b.fail( 'should return a function' ); + if (typeof f !== 'function') { + b.fail('should return a function'); } - b.pass( 'benchmark finished' ); + b.pass('benchmark finished'); b.end(); }); -bench( pkg+'::accumulator', function benchmark( b ) { +bench(pkg + '::accumulator', function benchmark(b) { var acc; var v; var i; - acc = incrnanmmeanvar( 5 ); + acc = incrnanmmeanvar(5); b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = acc( randu() ); - if ( v.length !== 2 ) { - b.fail( 'should contain two elements' ); + for (i = 0; i < b.iterations; i++) { + v = acc(randu()); + if (v.length !== 2) { + b.fail('should contain two elements'); } } b.toc(); - if ( v[ 0 ] !== v[ 0 ] || v[ 1 ] !== v[ 1 ] ) { - b.fail( 'should not return NaN' ); + if (v[0] !== v[0] || v[1] !== v[1]) { + b.fail('should not return NaN'); } - b.pass( 'benchmark finished' ); + b.pass('benchmark finished'); b.end(); }); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg index 1a89a2bfb996..52f3dffaa381 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg +++ b/lib/node_modules/@stdlib/stats/incr/nanmmeanvar/docs/img/equation_arithmetic_mean.svg @@ -1,3 +1,21 @@ + + x overbar equals StartFraction 1 Over upper W EndFraction sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts x Subscript i