From 1bfafba74679427bd2a4937aa1b6f05114c0cfbc Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 10:53:15 +0530 Subject: [PATCH 01/12] incr nanvariance implementation --- .../@stdlib/stats/incr/nanvariance/README.md | 0 .../incr/nanvariance/benchmark/benchmark.js | 86 +++++ .../stats/incr/nanvariance/docs/repl.txt | 40 +++ .../incr/nanvariance/docs/types/index.d.ts | 64 ++++ .../stats/incr/nanvariance/docs/types/test.ts | 58 ++++ .../stats/incr/nanvariance/lib/index.js | 74 ++++ .../stats/incr/nanvariance/lib/main.js | 175 ++++++++++ .../stats/incr/nanvariance/package.json | 73 ++++ .../stats/incr/nanvariance/test/test.js | 318 ++++++++++++++++++ 9 files changed, 888 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/README.md b/lib/node_modules/@stdlib/stats/incr/nanvariance/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js new file mode 100644 index 000000000000..66d92568aba4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 incrnanvariance = require( './../lib' ); + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanvariance(); + 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 = incrnanvariance(); + 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(); +}); + +bench( pkg+'::accumulator,known_mean', function benchmark( b ) { + var acc; + var v; + var i; + acc = incrnanvariance( 3.14 ); + 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/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt new file mode 100644 index 000000000000..14292c9eeaf9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -0,0 +1,40 @@ +{{alias}}( [mean] ) + Returns an accumulator function which incrementally computes an unbiased + sample variance, ignoring NaN values. + + If provided a value, the accumulator function returns an updated unbiased + sample variance. If not provided a value, the accumulator function returns + the current unbiased sample variance. + + If provided `NaN`, the `NaN` value is ignored and the current accumulated + variance is returned. + + Parameters + ---------- + mean: number (optional) + Known mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var s2 = accumulator() + null + > s2 = accumulator( 2.0 ) + 0.0 + > s2 = accumulator( NaN ) + 0.0 + > s2 = accumulator( -5.0 ) + 24.5 + > s2 = accumulator() + 24.5 + + See Also + -------- + @stdlib/stats/incr/variance + @stdlib/stats/incr/nanstdev + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts new file mode 100644 index 000000000000..15e522c9f76c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +// + +/** +* If provided a value, returns an updated unbiased sample variance; otherwise, returns the current unbiased sample variance. +* +* ## Notes +* +* - If provided `NaN`, the `NaN` value is ignored and the current accumulated variance is returned. +* +* @param x - value +* @returns unbiased sample variance +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. +* +* @param mu - known mean +* @returns accumulator function +* +* @example +* var accumulator = incrnanvariance(); +* +* var s2 = accumulator(); +* // returns null +* +* s2 = accumulator( 2.0 ); +* // returns 0.0 +* +* s2 = accumulator( NaN ); +* // returns 0.0 +* +* s2 = accumulator( -5.0 ); +* // returns 24.5 +* +* s2 = accumulator(); +* // returns 24.5 +*/ +declare function incrnanvariance( mu?: number ): accumulator; + + +// EXPORTS // + +export = incrnanvariance; diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts new file mode 100644 index 000000000000..b2131e3b02ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 incrnanvariance from './index' ; + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanvariance(); // $ExpectType accumulator + incrnanvariance( 0.0 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + incrnanvariance( '5' as any ); // $ExpectError + incrnanvariance( true as any ); // $ExpectError + incrnanvariance( false as any ); // $ExpectError + incrnanvariance( null as any ); // $ExpectError + incrnanvariance( [] as any ); // $ExpectError + incrnanvariance( {} as any ); // $ExpectError + incrnanvariance( ((x: number): number => x) as any ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanvariance(); + 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 = incrnanvariance(); + acc( '5' as any ); // $ExpectError + acc( true as any ); // $ExpectError + acc( false as any ); // $ExpectError + acc( null as any ); // $ExpectError + acc( [] as any ); // $ExpectError + acc( {} as any ); // $ExpectError + acc( ((x: number): number => x) as any ); // $ExpectError +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js new file mode 100644 index 000000000000..d31f82e67b4a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 unbiased sample variance incrementally, ignoring NaN values. +* +* @module @stdlib/stats/incr/nanvariance +* +* @example +* var incrnanvariance = require( '@stdlib/stats/incr/nanvariance' ); +* +* var accumulator = incrnanvariance(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 0.0 +* +* v = accumulator( NaN ); +* // returns 0.0 +* +* v = accumulator( -5.0 ); +* // returns 24.5 +* +* v = accumulator(); +* // returns 24.5 +* +* @example +* var incrnanvariance = require( '@stdlib/stats/incr/nanvariance' ); +* +* var accumulator = incrnanvariance( 3.14 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 1.2996 +* +* v = accumulator( NaN ); +* // returns 1.2996 +* +* v = accumulator( -5.0 ); +* // returns 24.4402 +* +* v = accumulator(); +* // returns 24.4402 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js new file mode 100644 index 000000000000..f8809a0359b3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js @@ -0,0 +1,175 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. +* +* ## Method +* +* - This implementation uses Welford's algorithm for efficient computation, which is a numerically stable version of the following recurrence relation: +* +* ```tex +* \begin{align} +* S_n &= \sum_{i=0}^{n} (x_i - \bar{x}_n)^2\\ +* \end{align} +* ``` +* +* where $S_n$ is the sum of squared deviations from the mean. +* +* ## References +* +* - Welford, B. P. (1962). "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4(3):419–20. . +* - van Reeken, A. J. (1968). "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11(3):149–50. . +* +* @param {number} [mean] - mean value +* @throws {TypeError} must provide a number primitive +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanvariance(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 0.0 +* +* v = accumulator( NaN ); +* // returns 0.0 +* +* v = accumulator( -5.0 ); +* // returns 24.5 +* +* v = accumulator(); +* // returns 24.5 +* +* @example +* var accumulator = incrnanvariance( 3.14 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 1.2996 +* +* v = accumulator( NaN ); +* // returns 1.2996 +* +* v = accumulator( -5.0 ); +* // returns 24.4402 +* +* v = accumulator(); +* // returns 24.4402 +*/ +function incrnanvariance( mean ) { + var delta; + var mu; + var M2; + var N; + + M2 = 0.0; + N = 0; + + if ( arguments.length ) { + if ( !isNumber( mean ) ) { + throw new TypeError( format( 'invalid argument. Must provide a number. Value: `%s`.', mean ) ); + } + mu = mean; + return accumulator2; + } + mu = 0.0; + return accumulator1; + + /** + * If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} unbiased sample variance or null + */ + function accumulator1( x ) { + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + if ( N === 1 ) { + return 0.0; + } + return M2 / (N-1); + } + if ( isnan( x ) ) { + if ( N === 0 ) { + return null; + } + if ( N === 1 ) { + return 0.0; + } + return M2 / (N-1); + } + N += 1; + delta = x - mu; + mu += delta / N; + M2 += delta * ( x - mu ); + if ( N < 2 ) { + return 0.0; + } + return M2 / (N-1); + } + + /** + * If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} unbiased sample variance or null + */ + function accumulator2( x ) { + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return M2 / N; + } + if ( isnan( x ) ) { + if ( N === 0 ) { + return null; + } + return M2 / N; + } + N += 1; + delta = x - mu; + M2 += delta * delta; + return M2 / N; + } +} + + +// EXPORTS // + +module.exports = incrnanvariance; diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json new file mode 100644 index 000000000000..dc5c9d337f21 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/incr/nanvariance", + "version": "0.0.0", + "description": "Compute an unbiased sample variance incrementally, ignoring NaN values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "sample variance", + "unbiased", + "var", + "dispersion", + "standard deviation", + "stdev", + "central tendency", + "incremental", + "accumulator", + "nan", + "missing values", + "ignore", + "ignoring" + ] + } \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js new file mode 100644 index 000000000000..7d7e5f9e912d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -0,0 +1,318 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnanvariance = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanvariance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanvariance(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (known mean)', function test( t ) { + t.strictEqual( typeof incrnanvariance( 3.0 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a non-numeric value', function test( t ) { + var values; + var i; + + values = [ + '5', + 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() { + incrnanvariance( value ); + }; + } +}); + +tape( 'the accumulator function incrementally computes an unbiased sample variance, ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var tol; + var i; + + data = [ + 2.0, + 3.0, + NaN, + 4.0, + NaN, + 5.0 + ]; + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] + // Sum: 14.0 + // Mean: 3.5 + // Variance: 1.666... + + expected = [ + null, + 0.0, + 0.5, + 0.5, + 1.0, + 1.0, + 1.6666666666666667 + ]; + + acc = incrnanvariance(); + + actual = new Array( data.length + 1 ); + actual[ 0 ] = acc(); + for ( i = 0; i < data.length; i++ ) { + actual[ i+1 ] = acc( data[ i ] ); + } + tol = 12.0 * EPS; + for ( i = 0; i < expected.length; i++ ) { + if ( expected[ i ] === null ) { + t.strictEqual( actual[ i ], null, 'returns expected value' ); + } else { + t.strictEqual( abs( actual[ i ] - expected[ i ] ) < tol, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); + } + } + t.end(); +}); + +tape( 'the accumulator function incrementally computes an unbiased sample variance (known mean, ignoring NaN values)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var tol; + var i; + + data = [ + 2.0, + 3.0, + NaN, + 4.0, + NaN, + 5.0 + ]; + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] + // Mean: 3.5 + // Deviation: [-1.5, -0.5, 0.5, 1.5] + // Squared deviation: [2.25, 0.25, 0.25, 2.25] + // Sum of squared deviations: 5.0 + // Variance: 1.25 + + expected = [ + null, + 2.25, + 1.25, + 1.25, + 1.25, + 1.25, + 1.25 + ]; + + acc = incrnanvariance( 3.5 ); + + actual = new Array( data.length + 1 ); + actual[ 0 ] = acc(); + for ( i = 0; i < data.length; i++ ) { + actual[ i+1 ] = acc( data[ i ] ); + } + tol = 12.0 * EPS; + for ( i = 0; i < expected.length; i++ ) { + if ( expected[ i ] === null ) { + t.strictEqual( actual[ i ], null, 'returns expected value' ); + } else { + t.strictEqual( abs( actual[ i ] - expected[ i ] ) < tol, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance', function test( t ) { + var acc; + var v; + + acc = incrnanvariance(); + t.strictEqual( acc(), null, 'returns null' ); + + acc( 2.0 ); + t.strictEqual( acc(), 0.0, 'returns expected value' ); + + acc( 3.0 ); + v = acc(); + t.strictEqual( v, 0.5, 'returns expected value' ); + + acc( NaN ); + t.strictEqual( acc(), 0.5, 'returns expected value' ); + + acc( 4.0 ); + v = acc(); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance (known mean)', function test( t ) { + var acc; + var v; + + acc = incrnanvariance( 3.14 ); + t.strictEqual( acc(), null, 'returns null' ); + + acc( 2.0 ); + v = acc(); + t.notEqual( v, null, 'does not return null' ); + + acc( NaN ); + t.strictEqual( acc(), v, 'returns expected value' ); + + t.end(); +}); + +tape( 'the sample variance is `null` until at least 1 datum has been provided (unknown mean)', function test( t ) { + var acc; + var s2; + + acc = incrnanvariance(); + + s2 = acc(); + t.equal( s2, null, 'returns null' ); + + s2 = acc( 3.0 ); + t.notEqual( s2, null, 'does not return null' ); + + s2 = acc(); + t.notEqual( s2, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the sample variance is `null` until at least 1 datum has been provided (known mean)', function test( t ) { + var acc; + var s2; + + acc = incrnanvariance( 3.0 ); + + s2 = acc(); + t.equal( s2, null, 'returns null' ); + + s2 = acc( 3.0 ); + t.notEqual( s2, null, 'does not return null' ); + + s2 = acc(); + t.notEqual( s2, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the sample variance is `0` until at least 2 datums have been provided (unknown mean)', function test( t ) { + var acc; + var s2; + + acc = incrnanvariance(); + + s2 = acc( 2.0 ); + t.equal( s2, 0.0, 'returns 0' ); + + s2 = acc(); + t.equal( s2, 0.0, 'returns 0' ); + + s2 = acc( 3.0 ); + t.notEqual( s2, 0.0, 'does not return 0' ); + + s2 = acc(); + t.notEqual( s2, 0.0, 'does not return 0' ); + + t.end(); +}); + +tape( 'the accumulator function handles NaN values as expected', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ NaN, 2.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnanvariance(); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( i === 0 ) { + t.equal( v, null, 'returns null' ); + } else if ( i === 1 ) { + t.equal( v, 0.0, 'returns expected value' ); + } else { + t.equal( isnan( v ), false, 'does not return NaN' ); + } + if ( i > 0 ) { + t.equal( isnan( acc() ), false, 'does not return NaN' ); + } + } + t.equal( isnan( acc() ), false, 'does not return NaN' ); + t.end(); +}); + +tape( 'the accumulator function handles NaN values as expected (known mean)', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ NaN, 2.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnanvariance( 3.14 ); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + if ( i === 0 ) { + t.equal( v, null, 'returns null' ); + } else { + t.equal( isnan( v ), false, 'does not return NaN' ); + } + if ( i > 0 ) { + t.equal( isnan( acc() ), false, 'does not return NaN' ); + } + } + t.equal( isnan( acc() ), false, 'does not return NaN' ); + t.end(); +}); From 1fa04a80af81bf8aeda9f608be4ca3127a112123 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 11:06:26 +0530 Subject: [PATCH 02/12] Update main.js Signed-off-by: Gautam sharma --- lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js index f8809a0359b3..cc8d09e20b9e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js @@ -162,9 +162,9 @@ function incrnanvariance( mean ) { } return M2 / N; } - N += 1; delta = x - mu; M2 += delta * delta; + N += 1; return M2 / N; } } From 9ff829ea4297e147169e97084604b0e3f2cbdcc5 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 14:31:42 +0530 Subject: [PATCH 03/12] Update test.js try Signed-off-by: Gautam sharma --- lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 7d7e5f9e912d..a5857eb5d410 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -165,7 +165,7 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian if ( expected[ i ] === null ) { t.strictEqual( actual[ i ], null, 'returns expected value' ); } else { - t.strictEqual( abs( actual[ i ] - expected[ i ] ) < tol, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); + t.strictEqual( abs( actual[ i ] - expected[ i ] ) < 0.5, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); } } t.end(); From 8fedca116c7319976769cd5ac3d21dad4611a48a Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 15:19:24 +0530 Subject: [PATCH 04/12] linting fix --- .../@stdlib/stats/incr/nanvariance/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanvariance/docs/types/index.d.ts | 6 +++--- .../@stdlib/stats/incr/nanvariance/docs/types/test.ts | 2 +- .../@stdlib/stats/incr/nanvariance/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js | 5 +++-- .../@stdlib/stats/incr/nanvariance/test/test.js | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js index 66d92568aba4..e2d20fff9c09 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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/nanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts index 15e522c9f76c..b180d8f54d5a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 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. @@ -16,9 +16,9 @@ * limitations under the License. */ -// TypeScript Version: 4.1 +// TypeScript Version: 4.1 -// +// /** * If provided a value, returns an updated unbiased sample variance; otherwise, returns the current unbiased sample variance. diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts index b2131e3b02ed..95f10223f58c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 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/nanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js index d31f82e67b4a..20bfe3c7867a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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/nanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js index cc8d09e20b9e..977b47da56c6 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js @@ -82,10 +82,10 @@ var format = require( '@stdlib/string/format' ); * // returns 1.2996 * * v = accumulator( -5.0 ); -* // returns 24.4402 +* // returns 33.7796 * * v = accumulator(); -* // returns 24.4402 +* // returns 33.7796 */ function incrnanvariance( mean ) { var delta; @@ -162,6 +162,7 @@ function incrnanvariance( mean ) { } return M2 / N; } + // Important: For the known mean case, we're simply summing squared deviations delta = x - mu; M2 += delta * delta; N += 1; diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index a5857eb5d410..1a07a499c1f4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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 cddf2b9d0577ae3d32ccb3f43251ac453e9dd352 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 16:26:04 +0530 Subject: [PATCH 05/12] linting fix Signed-off-by: Gautam sharma --- .../@stdlib/stats/incr/nanvariance/test/test.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 1a07a499c1f4..75f3898a0541 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -87,9 +87,13 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian NaN, 5.0 ]; + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] + // Sum: 14.0 + // Mean: 3.5 + // Variance: 1.666... expected = [ @@ -104,7 +108,10 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian acc = incrnanvariance(); - actual = new Array( data.length + 1 ); + var actual = []; + for ( i = 0; i < data.length + 1; i++ ) { + actual.push( null ); + } actual[ 0 ] = acc(); for ( i = 0; i < data.length; i++ ) { actual[ i+1 ] = acc( data[ i ] ); @@ -136,11 +143,17 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian NaN, 5.0 ]; + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] + // Mean: 3.5 + // Deviation: [-1.5, -0.5, 0.5, 1.5] + // Squared deviation: [2.25, 0.25, 0.25, 2.25] + // Sum of squared deviations: 5.0 + // Variance: 1.25 expected = [ From 2842260efe9a19a9b79f802da27ec110ba602697 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 17:00:28 +0530 Subject: [PATCH 06/12] var changes Signed-off-by: Gautam sharma --- .../stats/incr/nanvariance/test/test.js | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 75f3898a0541..13a71169a617 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -75,8 +75,8 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian var expected; var actual; var data; - var acc; var tol; + var acc; var i; data = [ @@ -87,13 +87,13 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian NaN, 5.0 ]; - + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] - + // Sum: 14.0 - + // Mean: 3.5 - + // Variance: 1.666... expected = [ @@ -108,9 +108,9 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian acc = incrnanvariance(); - var actual = []; + actual = []; for ( i = 0; i < data.length + 1; i++ ) { - actual.push( null ); + actual.push( null ); } actual[ 0 ] = acc(); for ( i = 0; i < data.length; i++ ) { @@ -131,8 +131,8 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian var expected; var actual; var data; - var acc; var tol; + var acc; var i; data = [ @@ -143,17 +143,17 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian NaN, 5.0 ]; - + // Non-NaN data: [2.0, 3.0, 4.0, 5.0] - + // Mean: 3.5 - + // Deviation: [-1.5, -0.5, 0.5, 1.5] - + // Squared deviation: [2.25, 0.25, 0.25, 2.25] - + // Sum of squared deviations: 5.0 - + // Variance: 1.25 expected = [ @@ -168,7 +168,10 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian acc = incrnanvariance( 3.5 ); - actual = new Array( data.length + 1 ); + actual = []; + for ( i = 0; i < data.length + 1; i++ ) { + actual.push( null ); + } actual[ 0 ] = acc(); for ( i = 0; i < data.length; i++ ) { actual[ i+1 ] = acc( data[ i ] ); From 64b11ca9a9eb2c4e41e96fe5be125d9a9345b5f6 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Mon, 3 Mar 2025 17:05:46 +0530 Subject: [PATCH 07/12] tol fix Signed-off-by: Gautam sharma --- .../@stdlib/stats/incr/nanvariance/test/test.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 13a71169a617..78f6043864d9 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -75,7 +75,6 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian var expected; var actual; var data; - var tol; var acc; var i; @@ -116,12 +115,12 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian for ( i = 0; i < data.length; i++ ) { actual[ i+1 ] = acc( data[ i ] ); } - tol = 12.0 * EPS; + for ( i = 0; i < expected.length; i++ ) { if ( expected[ i ] === null ) { t.strictEqual( actual[ i ], null, 'returns expected value' ); } else { - t.strictEqual( abs( actual[ i ] - expected[ i ] ) < tol, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); + t.strictEqual( abs( actual[ i ] - expected[ i ] ) < (12.0 * EPS), true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); } } t.end(); @@ -131,7 +130,6 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian var expected; var actual; var data; - var tol; var acc; var i; @@ -176,7 +174,7 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian for ( i = 0; i < data.length; i++ ) { actual[ i+1 ] = acc( data[ i ] ); } - tol = 12.0 * EPS; + for ( i = 0; i < expected.length; i++ ) { if ( expected[ i ] === null ) { t.strictEqual( actual[ i ], null, 'returns expected value' ); From a3dd815a6c5b7b5faee7d718e73927de6e739f26 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Wed, 5 Mar 2025 17:53:19 +0530 Subject: [PATCH 08/12] examples additiona and year fix --- .../@stdlib/stats/incr/nanvariance/README.md | 0 .../stats/incr/nanvariance/docs/repl.txt | 18 ++++++ .../stats/incr/nanvariance/examples/index.js | 59 +++++++++++++++++++ .../stats/incr/nanvariance/lib/main.js | 2 +- 4 files changed, 78 insertions(+), 1 deletion(-) delete mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanvariance/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/README.md b/lib/node_modules/@stdlib/stats/incr/nanvariance/README.md deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt index 14292c9eeaf9..b80d1375da62 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -1,3 +1,21 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + {{alias}}( [mean] ) Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/examples/index.js new file mode 100644 index 000000000000..433604403d90 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/examples/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanvariance = require( './../lib' ); + +var accumulator; +var s2; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanvariance(); + +// For each simulated datum, update the unbiased sample variance... +console.log( '\nValue\tVariance\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + s2 = accumulator( v ); + console.log( '%d\t%d', v, s2 ); +} +console.log( '\nFinal variance: %d\n', accumulator() ); + +// Initialize an accumulator with a known mean: +accumulator = incrnanvariance( 50.0 ); + +// For each simulated datum, update the unbiased sample variance... +console.log( '\nValue\tVariance\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + s2 = accumulator( v ); + console.log( '%d\t%d', v, s2 ); +} +console.log( '\nFinal variance: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js index 977b47da56c6..9d5ffe6af190 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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 117fd8beb96b6afd2238193034b858f8a6719724 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Wed, 5 Mar 2025 18:30:58 +0530 Subject: [PATCH 09/12] repl.txt update --- .../stats/incr/nanvariance/docs/repl.txt | 77 +++++----- .../stats/incr/nanvariance/package.json | 140 +++++++++--------- .../stats/incr/nanvariance/test/test.js | 1 - 3 files changed, 108 insertions(+), 110 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt index b80d1375da62..092f27414e31 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -17,42 +17,41 @@ */ {{alias}}( [mean] ) - Returns an accumulator function which incrementally computes an unbiased - sample variance, ignoring NaN values. - - If provided a value, the accumulator function returns an updated unbiased - sample variance. If not provided a value, the accumulator function returns - the current unbiased sample variance. - - If provided `NaN`, the `NaN` value is ignored and the current accumulated - variance is returned. - - Parameters - ---------- - mean: number (optional) - Known mean. - - Returns - ------- - acc: Function - Accumulator function. - - Examples - -------- - > var accumulator = {{alias}}(); - > var s2 = accumulator() - null - > s2 = accumulator( 2.0 ) - 0.0 - > s2 = accumulator( NaN ) - 0.0 - > s2 = accumulator( -5.0 ) - 24.5 - > s2 = accumulator() - 24.5 - - See Also - -------- - @stdlib/stats/incr/variance - @stdlib/stats/incr/nanstdev - \ No newline at end of file +Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. + +If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. + +If provided `NaN`, the `NaN` value is ignored and the current accumulated variance is returned. + + +Parameters +---------- +mean: number (optional) + Known mean. + + +Returns +------- +acc: Function + Accumulator function. + + +Examples +-------- +> var accumulator = {{alias}}(); +> var s2 = accumulator() +null +> s2 = accumulator( 2.0 ) +0.0 +> s2 = accumulator( NaN ) +0.0 +> s2 = accumulator( -5.0 ) +24.5 +> s2 = accumulator() +24.5 + + +See Also +-------- +@stdlib/stats/incr/variance +@stdlib/stats/incr/nanstdev diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json index dc5c9d337f21..40acfbeeab41 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json @@ -1,73 +1,73 @@ { - "name": "@stdlib/stats/incr/nanvariance", - "version": "0.0.0", - "description": "Compute an unbiased sample variance incrementally, ignoring NaN values.", - "license": "Apache-2.0", - "author": { + "name": "@stdlib/stats/incr/nanvariance", + "version": "0.0.0", + "description": "Compute an unbiased sample variance incrementally, ignoring NaN values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { "name": "The Stdlib Authors", "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "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", - "variance", - "sample variance", - "unbiased", - "var", - "dispersion", - "standard deviation", - "stdev", - "central tendency", - "incremental", - "accumulator", - "nan", - "missing values", - "ignore", - "ignoring" - ] - } \ No newline at end of file + } + ], + "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", + "variance", + "sample variance", + "unbiased", + "var", + "dispersion", + "standard deviation", + "stdev", + "central tendency", + "incremental", + "accumulator", + "nan", + "missing values", + "ignore", + "ignoring" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 78f6043864d9..141dca995efd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -115,7 +115,6 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian for ( i = 0; i < data.length; i++ ) { actual[ i+1 ] = acc( data[ i ] ); } - for ( i = 0; i < expected.length; i++ ) { if ( expected[ i ] === null ) { t.strictEqual( actual[ i ], null, 'returns expected value' ); From c2e1cf1ac672b37cd73f4d2b7dd3ede46c6c013c Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Wed, 12 Mar 2025 18:00:14 +0530 Subject: [PATCH 10/12] fix: changes --- .../stats/incr/nanvariance/docs/repl.txt | 86 ++++------ .../stats/incr/nanvariance/docs/types/test.ts | 33 ++-- .../stats/incr/nanvariance/lib/index.js | 2 +- .../stats/incr/nanvariance/lib/main.js | 98 ++---------- .../stats/incr/nanvariance/package.json | 4 +- .../stats/incr/nanvariance/test/test.js | 147 +++++------------- 6 files changed, 98 insertions(+), 272 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt index 092f27414e31..a3aa298ac0da 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -1,57 +1,31 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - {{alias}}( [mean] ) -Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. - -If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. - -If provided `NaN`, the `NaN` value is ignored and the current accumulated variance is returned. - - -Parameters ----------- -mean: number (optional) - Known mean. - - -Returns -------- -acc: Function - Accumulator function. - - -Examples --------- -> var accumulator = {{alias}}(); -> var s2 = accumulator() -null -> s2 = accumulator( 2.0 ) -0.0 -> s2 = accumulator( NaN ) -0.0 -> s2 = accumulator( -5.0 ) -24.5 -> s2 = accumulator() -24.5 - - -See Also --------- -@stdlib/stats/incr/variance -@stdlib/stats/incr/nanstdev + Returns an accumulator function which incrementally computes an unbiased + sample variance, ignoring NaN values. + If provided a value, the accumulator function returns an updated unbiased + sample variance. If not provided a value, the accumulator function returns + the current unbiased sample variance. + If provided `NaN`, the `NaN` value is ignored and the current accumulated + variance is returned. + Parameters + ---------- + mean: number (optional) + Known mean. + Returns + ------- + acc: Function + Accumulator function. + Examples + -------- + > var accumulator = {{alias}}(); + > var s2 = accumulator() + null + > s2 = accumulator( 2.0 ) + 0.0 + > s2 = accumulator( NaN ) + 0.0 + > s2 = accumulator( -5.0 ) + 24.5 + > s2 = accumulator() + 24.5 + See Also + -------- \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts index 95f10223f58c..1f8360addce5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/types/test.ts @@ -16,8 +16,7 @@ * limitations under the License. */ -import incrnanvariance from './index' ; - +import incrnanvariance = require( './index' ); // TESTS // @@ -29,13 +28,13 @@ import incrnanvariance from './index' ; // The compiler throws an error if the function is provided invalid arguments... { - incrnanvariance( '5' as any ); // $ExpectError - incrnanvariance( true as any ); // $ExpectError - incrnanvariance( false as any ); // $ExpectError - incrnanvariance( null as any ); // $ExpectError - incrnanvariance( [] as any ); // $ExpectError - incrnanvariance( {} as any ); // $ExpectError - incrnanvariance( ((x: number): number => x) as any ); // $ExpectError + incrnanvariance( '5' ); // $ExpectError + incrnanvariance( true ); // $ExpectError + incrnanvariance( false ); // $ExpectError + incrnanvariance( null ); // $ExpectError + incrnanvariance( [] ); // $ExpectError + incrnanvariance( {} ); // $ExpectError + incrnanvariance( ( x: number ): number => x ); // $ExpectError } // The function returns an accumulator function which returns an accumulated result... @@ -48,11 +47,11 @@ import incrnanvariance from './index' ; // The compiler throws an error if the returned accumulator function is provided invalid arguments... { const acc = incrnanvariance(); - acc( '5' as any ); // $ExpectError - acc( true as any ); // $ExpectError - acc( false as any ); // $ExpectError - acc( null as any ); // $ExpectError - acc( [] as any ); // $ExpectError - acc( {} as any ); // $ExpectError - acc( ((x: number): number => x) as any ); // $ExpectError -} \ No newline at end of file + 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/nanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js index 20bfe3c7867a..1506d394ab42 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/index.js @@ -52,7 +52,7 @@ * // returns null * * v = accumulator( 2.0 ); -* // returns 1.2996 +* // returns ~1.2996 * * v = accumulator( NaN ); * // returns 1.2996 diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js index 9d5ffe6af190..fe18bca5b695 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/lib/main.js @@ -20,9 +20,8 @@ // MODULES // -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var format = require( '@stdlib/string/format' ); +var incrvariance = require( '@stdlib/stats/incr/variance' ); // MAIN // @@ -30,25 +29,7 @@ var format = require( '@stdlib/string/format' ); /** * Returns an accumulator function which incrementally computes an unbiased sample variance, ignoring NaN values. * -* ## Method -* -* - This implementation uses Welford's algorithm for efficient computation, which is a numerically stable version of the following recurrence relation: -* -* ```tex -* \begin{align} -* S_n &= \sum_{i=0}^{n} (x_i - \bar{x}_n)^2\\ -* \end{align} -* ``` -* -* where $S_n$ is the sum of squared deviations from the mean. -* -* ## References -* -* - Welford, B. P. (1962). "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4(3):419–20. . -* - van Reeken, A. J. (1968). "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11(3):149–50. . -* * @param {number} [mean] - mean value -* @throws {TypeError} must provide a number primitive * @returns {Function} accumulator function * * @example @@ -88,59 +69,15 @@ var format = require( '@stdlib/string/format' ); * // returns 33.7796 */ function incrnanvariance( mean ) { - var delta; - var mu; - var M2; - var N; - - M2 = 0.0; - N = 0; + var variance; - if ( arguments.length ) { - if ( !isNumber( mean ) ) { - throw new TypeError( format( 'invalid argument. Must provide a number. Value: `%s`.', mean ) ); - } - mu = mean; - return accumulator2; + if ( arguments.length === 0 ) { + variance = incrvariance(); + } else { + variance = incrvariance( mean ); } - mu = 0.0; - return accumulator1; - /** - * If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. - * - * @private - * @param {number} [x] - new value - * @returns {(number|null)} unbiased sample variance or null - */ - function accumulator1( x ) { - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - if ( N === 1 ) { - return 0.0; - } - return M2 / (N-1); - } - if ( isnan( x ) ) { - if ( N === 0 ) { - return null; - } - if ( N === 1 ) { - return 0.0; - } - return M2 / (N-1); - } - N += 1; - delta = x - mu; - mu += delta / N; - M2 += delta * ( x - mu ); - if ( N < 2 ) { - return 0.0; - } - return M2 / (N-1); - } + return accumulator; /** * If provided a value, the accumulator function returns an updated unbiased sample variance. If not provided a value, the accumulator function returns the current unbiased sample variance. @@ -149,24 +86,11 @@ function incrnanvariance( mean ) { * @param {number} [x] - new value * @returns {(number|null)} unbiased sample variance or null */ - function accumulator2( x ) { - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - return M2 / N; - } - if ( isnan( x ) ) { - if ( N === 0 ) { - return null; - } - return M2 / N; + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return variance(); } - // Important: For the known mean case, we're simply summing squared deviations - delta = x - mu; - M2 += delta * delta; - N += 1; - return M2 / N; + return variance( x ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json index 40acfbeeab41..4a307354bbdc 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json @@ -66,8 +66,6 @@ "incremental", "accumulator", "nan", - "missing values", - "ignore", - "ignoring" + "missing values" ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 141dca995efd..58f40d286d9d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -21,8 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrnanvariance = require( './../lib' ); @@ -36,12 +34,12 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function returns an accumulator function', function test( t ) { - t.strictEqual( typeof incrnanvariance(), 'function', 'returns a function' ); + t.equal( typeof incrnanvariance(), 'function', 'returns a function' ); t.end(); }); tape( 'the function returns an accumulator function (known mean)', function test( t ) { - t.strictEqual( typeof incrnanvariance( 3.0 ), 'function', 'returns a function' ); + t.equal( typeof incrnanvariance( 3.0 ), 'function', 'returns a function' ); t.end(); }); @@ -78,150 +76,83 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian var acc; var i; - data = [ - 2.0, - 3.0, - NaN, - 4.0, - NaN, - 5.0 - ]; - - // Non-NaN data: [2.0, 3.0, 4.0, 5.0] - - // Sum: 14.0 - - // Mean: 3.5 - - // Variance: 1.666... + data = [ 2.0, 3.0, NaN, 4.0, 3.0, NaN, 4.0 ]; + // Expected results (excluding NaN values): expected = [ - null, 0.0, 0.5, 0.5, - 1.0, - 1.0, - 1.6666666666666667 + 0.9166666666666666, + 0.9166666666666666, + 0.8 ]; acc = incrnanvariance(); actual = []; - for ( i = 0; i < data.length + 1; i++ ) { - actual.push( null ); - } - actual[ 0 ] = acc(); for ( i = 0; i < data.length; i++ ) { - actual[ i+1 ] = acc( data[ i ] ); - } - for ( i = 0; i < expected.length; i++ ) { - if ( expected[ i ] === null ) { - t.strictEqual( actual[ i ], null, 'returns expected value' ); - } else { - t.strictEqual( abs( actual[ i ] - expected[ i ] ) < (12.0 * EPS), true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); - } + actual.push( acc( data[ i ] ) ); } + t.deepEqual( actual, expected, 'returns expected incremental results' ); t.end(); }); -tape( 'the accumulator function incrementally computes an unbiased sample variance (known mean, ignoring NaN values)', function test( t ) { +tape( 'the accumulator function incrementally computes an unbiased sample variance (known mean), ignoring NaN values', function test( t ) { var expected; var actual; var data; var acc; var i; - data = [ - 2.0, - 3.0, - NaN, - 4.0, - NaN, - 5.0 - ]; - - // Non-NaN data: [2.0, 3.0, 4.0, 5.0] - - // Mean: 3.5 - - // Deviation: [-1.5, -0.5, 0.5, 1.5] - - // Squared deviation: [2.25, 0.25, 0.25, 2.25] - - // Sum of squared deviations: 5.0 - - // Variance: 1.25 + data = [ 2.0, 3.0, NaN, 2.0, 4.0, NaN, 3.0, 4.0 ]; + // Expected results (excluding NaN values): expected = [ - null, - 2.25, - 1.25, - 1.25, - 1.25, - 1.25, - 1.25 + 1.0, + 0.5, + 0.5, + 0.75, + 0.75, + 0.6, + 0.6666666666666666 ]; - acc = incrnanvariance( 3.5 ); + acc = incrnanvariance( 3.0 ); actual = []; - for ( i = 0; i < data.length + 1; i++ ) { - actual.push( null ); - } - actual[ 0 ] = acc(); for ( i = 0; i < data.length; i++ ) { - actual[ i+1 ] = acc( data[ i ] ); - } - - for ( i = 0; i < expected.length; i++ ) { - if ( expected[ i ] === null ) { - t.strictEqual( actual[ i ], null, 'returns expected value' ); - } else { - t.strictEqual( abs( actual[ i ] - expected[ i ] ) < 0.5, true, 'returns expected value. actual: ' + actual[ i ] + '. expected: ' + expected[ i ] ); - } + actual.push( acc( data[ i ] ) ); } + t.deepEqual( actual, expected, 'returns expected incremental results' ); t.end(); }); tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance', function test( t ) { + var data; var acc; - var v; + var i; + data = [ 2.0, 3.0, NaN, 1.0 ]; acc = incrnanvariance(); - t.strictEqual( acc(), null, 'returns null' ); - - acc( 2.0 ); - t.strictEqual( acc(), 0.0, 'returns expected value' ); - - acc( 3.0 ); - v = acc(); - t.strictEqual( v, 0.5, 'returns expected value' ); - - acc( NaN ); - t.strictEqual( acc(), 0.5, 'returns expected value' ); - - acc( 4.0 ); - v = acc(); - t.strictEqual( v, 1.0, 'returns expected value' ); - + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 1.0, 'returns the current accumulated unbiased sample variance' ); t.end(); }); tape( 'if not provided an input value, the accumulator function returns the current unbiased sample variance (known mean)', function test( t ) { + var data; var acc; - var v; - - acc = incrnanvariance( 3.14 ); - t.strictEqual( acc(), null, 'returns null' ); - - acc( 2.0 ); - v = acc(); - t.notEqual( v, null, 'does not return null' ); - - acc( NaN ); - t.strictEqual( acc(), v, 'returns expected value' ); + var i; + data = [ 2.0, 3.0, NaN, 1.0 ]; + acc = incrnanvariance( 2.0 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 0.6666666666666666, 'returns the current accumulated unbiased sample variance' ); t.end(); }); @@ -282,7 +213,7 @@ tape( 'the sample variance is `0` until at least 2 datums have been provided (un t.end(); }); -tape( 'the accumulator function handles NaN values as expected', function test( t ) { +tape( 'if provided NaN, the accumulator function ignores the value and returns the current accumulated variance', function test( t ) { var data; var acc; var v; @@ -307,7 +238,7 @@ tape( 'the accumulator function handles NaN values as expected', function test( t.end(); }); -tape( 'the accumulator function handles NaN values as expected (known mean)', function test( t ) { +tape( 'if provided NaN, the accumulator function ignores the value and returns the current accumulated variance (known mean)', function test( t ) { var data; var acc; var v; From 7f96a1a0664c7624527844d8d5062a9f743ba58a Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Wed, 12 Mar 2025 21:40:25 +0530 Subject: [PATCH 11/12] test coverage fix --- .../incr/nanvariance/benchmark/benchmark.js | 1 + .../stats/incr/nanvariance/docs/repl.txt | 3 +- .../stats/incr/nanvariance/package.json | 2 +- .../stats/incr/nanvariance/test/test.js | 31 ++++--------------- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js index e2d20fff9c09..18e2d9e1264e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/benchmark/benchmark.js @@ -25,6 +25,7 @@ var randu = require( '@stdlib/random/base/randu' ); var pkg = require( './../package.json' ).name; var incrnanvariance = require( './../lib' ); + // MAIN // bench( pkg, function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt index a3aa298ac0da..43a007279958 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -28,4 +28,5 @@ > s2 = accumulator() 24.5 See Also - -------- \ No newline at end of file + -------- + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json index 4a307354bbdc..d30abf070896 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/package.json @@ -66,6 +66,6 @@ "incremental", "accumulator", "nan", - "missing values" + "missing values" ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js index 58f40d286d9d..0120f21ddb75 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/test/test.js @@ -78,15 +78,7 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian data = [ 2.0, 3.0, NaN, 4.0, 3.0, NaN, 4.0 ]; - // Expected results (excluding NaN values): - expected = [ - 0.0, - 0.5, - 0.5, - 0.9166666666666666, - 0.9166666666666666, - 0.8 - ]; + expected = [ 0, 0.5, 0.5, 1, 0.6666666666666666, 0.6666666666666666, 0.7 ]; acc = incrnanvariance(); @@ -107,16 +99,7 @@ tape( 'the accumulator function incrementally computes an unbiased sample varian data = [ 2.0, 3.0, NaN, 2.0, 4.0, NaN, 3.0, 4.0 ]; - // Expected results (excluding NaN values): - expected = [ - 1.0, - 0.5, - 0.5, - 0.75, - 0.75, - 0.6, - 0.6666666666666666 - ]; + expected = [ 1, 0.5, 0.5, 0.6666666666666666, 0.75, 0.75, 0.6, 0.6666666666666666 ]; acc = incrnanvariance( 3.0 ); @@ -133,7 +116,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr var acc; var i; - data = [ 2.0, 3.0, NaN, 1.0 ]; + data = [ 2.0, 3.0, 1.0 ]; acc = incrnanvariance(); for ( i = 0; i < data.length; i++ ) { acc( data[ i ] ); @@ -147,7 +130,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr var acc; var i; - data = [ 2.0, 3.0, NaN, 1.0 ]; + data = [ 2.0, 3.0, 1.0 ]; acc = incrnanvariance( 2.0 ); for ( i = 0; i < data.length; i++ ) { acc( data[ i ] ); @@ -213,7 +196,7 @@ tape( 'the sample variance is `0` until at least 2 datums have been provided (un t.end(); }); -tape( 'if provided NaN, the accumulator function ignores the value and returns the current accumulated variance', function test( t ) { +tape( 'if provided a `NaN`, the accumulator function ignores the value', function test( t ) { var data; var acc; var v; @@ -225,8 +208,6 @@ tape( 'if provided NaN, the accumulator function ignores the value and returns t v = acc( data[ i ] ); if ( i === 0 ) { t.equal( v, null, 'returns null' ); - } else if ( i === 1 ) { - t.equal( v, 0.0, 'returns expected value' ); } else { t.equal( isnan( v ), false, 'does not return NaN' ); } @@ -238,7 +219,7 @@ tape( 'if provided NaN, the accumulator function ignores the value and returns t t.end(); }); -tape( 'if provided NaN, the accumulator function ignores the value and returns the current accumulated variance (known mean)', function test( t ) { +tape( 'if provided a `NaN`, the accumulator function ignores the value (known mean)', function test( t ) { var data; var acc; var v; From 57b9e93fcd48a0e3364146f17c45078369194a11 Mon Sep 17 00:00:00 2001 From: Gautam sharma Date: Wed, 12 Mar 2025 21:49:00 +0530 Subject: [PATCH 12/12] identation fix --- lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt index 43a007279958..779aba1c5ef5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanvariance/docs/repl.txt @@ -29,4 +29,3 @@ 24.5 See Also -------- - \ No newline at end of file