From f3d4e018cf051f04eae9758b3fd7d617acf35ee9 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Sat, 8 Mar 2025 15:02:41 +0530 Subject: [PATCH 01/21] edit --- .../@stdlib/stats/base/dists/uniform/mgf/src/main.c | 2 +- .../@stdlib/stats/base/dists/uniform/mgf/test/test.native.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c index 49105477756c..4feab3bb73be 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c @@ -46,5 +46,5 @@ double stdlib_base_dists_uniform_mgf( const double t, const double a, const doub return 1.0; } // Case: t not equal to zero - return ( stdlib_base_exp( t * b ) - stdlib_base_exp( t * a ) ) / ( t * ( b - a ) ); + return stdlib_base_exp( v ) * ( stdlib_base_sinh ( u ) / u ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js index bc312890bdf3..868d3aae948d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js @@ -81,7 +81,7 @@ tape( 'if provided `a >= b`, the function returns `NaN`', opts, function test( t t.end(); }); -tape( 'if provided valid parameters, the function returns `1` for `t = 0`', function test( t ) { +tape( 'if provided valid parameters, the function returns `1` for `t = 0`', opts, function test( t ) { var y; y = mgf( 0.0, 2.0, 4.0 ); From ddced1cd3eb3a9a64ec05119e719344ecff0bbaf Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Sat, 8 Mar 2025 15:10:15 +0530 Subject: [PATCH 02/21] edit --- .../@stdlib/stats/base/dists/uniform/mgf/src/main.c | 2 +- .../@stdlib/stats/base/dists/uniform/mgf/test/test.native.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c index 4feab3bb73be..49105477756c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/src/main.c @@ -46,5 +46,5 @@ double stdlib_base_dists_uniform_mgf( const double t, const double a, const doub return 1.0; } // Case: t not equal to zero - return stdlib_base_exp( v ) * ( stdlib_base_sinh ( u ) / u ); + return ( stdlib_base_exp( t * b ) - stdlib_base_exp( t * a ) ) / ( t * ( b - a ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js index 868d3aae948d..bc312890bdf3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/mgf/test/test.native.js @@ -81,7 +81,7 @@ tape( 'if provided `a >= b`, the function returns `NaN`', opts, function test( t t.end(); }); -tape( 'if provided valid parameters, the function returns `1` for `t = 0`', opts, function test( t ) { +tape( 'if provided valid parameters, the function returns `1` for `t = 0`', function test( t ) { var y; y = mgf( 0.0, 2.0, 4.0 ); From 3e69108048ce972d5721fbfb41e7ef643a124d8c Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 13:03:40 +0530 Subject: [PATCH 03/21] added incr/nancv --- .../@stdlib/stats/incr/nancv/README.md | 207 +++++++++++++ .../stats/incr/nancv/benchmark/benchmark.js | 91 ++++++ .../@stdlib/stats/incr/nancv/docs/repl.txt | 38 +++ .../stats/incr/nancv/docs/types/index.d.ts | 67 +++++ .../stats/incr/nancv/docs/types/test.ts | 60 ++++ .../stats/incr/nancv/examples/index.js | 39 +++ .../@stdlib/stats/incr/nancv/lib/index.js | 54 ++++ .../@stdlib/stats/incr/nancv/lib/main.js | 66 ++++ .../@stdlib/stats/incr/nancv/package.json | 67 +++++ .../@stdlib/stats/incr/nancv/test/test.js | 284 ++++++++++++++++++ 10 files changed, 973 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nancv/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md new file mode 100644 index 000000000000..920899a86a17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -0,0 +1,207 @@ + + +# incrnancv + +> Compute the [coefficient of variation][coefficient-of-variation] (CV) incrementally, while ignoring 'NaN' values. + +
+ +The [corrected sample standard deviation][sample-stdev] is defined as + + + +```math +s = \sqrt{\frac{1}{n-1} \sum_{i=0}^{n-1} ( x_i - \bar{x} )^2} +``` + + + + + +and the [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The [coefficient of variation][coefficient-of-variation] (also known as **relative standard deviation**, RSD) is defined as + + + +```math +c_v = \frac{s}{\bar{x}} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrcv = require( '@stdlib/stats/incr/nancv' ); +``` + +#### incrnancv( \[mean] ) + +Returns an accumulator `function` which incrementally computes the [coefficient of variation][coefficient-of-variation], while ignoring 'NaN' value. + +```javascript +var accumulator = incrnancv(); +``` + +If the mean is already known, provide a `mean` argument. + +```javascript +var accumulator = incrnancv( 3.0 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated accumulated value. If not provided an input value `x`, the accumulator function returns the current accumulated value. + +```javascript +var accumulator = incrnancv(); + +var cv = accumulator( 2.0 ); +// returns 0.0 + +cv = accumulator( 1.0 ); // => s^2 = ((2-1.5)^2+(1-1.5)^2) / (2-1) +// returns ~0.47 + +cv=accumulator( 1.0 ); +// returns ~0.47 + +cv = accumulator( 3.0 ); // => s^2 = ((2-2)^2+(1-2)^2+(3-2)^2) / (3-1) +// returns 0.5 + +cv = accumulator(); +// returns 0.5 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **all** future invocations. +- The [coefficient of variation][coefficient-of-variation] is typically computed on nonnegative values. The measure may lack meaning for data which can assume both positive and negative values. +- For small and moderately sized samples, the accumulated value tends to be too low and is thus a **biased** estimator. Provided the generating distribution is known (e.g., a normal distribution), you may want to adjust the accumulated value or use an alternative implementation providing an unbiased estimator. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnancv = require( '@stdlib/stats/incr/nancv' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnancv(); + +// For each simulated datum, update the coefficient of variation... +for ( i = 0; i < 100; i++ ) { + v = ( (randu() < 0.1) ? NaN : (randu() * 100.0) ); + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js new file mode 100644 index 000000000000..a5509bf17cf5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnancv = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnancv(); + 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 = incrnancv(); + + 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 = incrnancv( 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/nancv/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt new file mode 100644 index 000000000000..37509a37d539 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt @@ -0,0 +1,38 @@ +{{alias}}( [mean] ) + Returns an accumulator function which incrementally computes the + coefficient of variation (CV), ignoring `NaN` values. + + If provided a value, the accumulator function returns an updated + accumulated value. If not provided a value, the accumulator function + returns the current accumulated value. + + If all received values are `NaN`, the accumulated value remains `null`. + + Parameters + ---------- + mean: number (optional) + Known mean. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var cv = accumulator() + null + > cv = accumulator( NaN ) + null + > cv = accumulator( 2.0 ) + 0.0 + > cv = accumulator( 1.0 ) + ~0.47 + > cv = accumulator( NaN ) + ~0.47 + > cv = accumulator() + ~0.47 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts new file mode 100644 index 000000000000..bb9e07551524 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts @@ -0,0 +1,67 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. +* +* ## Notes +* +* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* +* @param x - value +* @returns accumulated value or null +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring `NaN` values. +* +* @param mean - mean value +* @returns accumulator function +* +* @example +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* * cv = accumulator( NaN ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +* +* @example +* var accumulator = incrnancv( 3.14 ); +*/ +declare function incrnancv( mean?: number ): accumulator; + + +// EXPORTS // + +export = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts new file mode 100644 index 000000000000..44fe3a4d50f3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnancv = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnancv(); // $ExpectType accumulator + incrnancv( 0.0 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + incrnancv( '5' ); // $ExpectError + incrnancv( true ); // $ExpectError + incrnancv( false ); // $ExpectError + incrnancv( null ); // $ExpectError + incrnancv( [] ); // $ExpectError + incrnancv( {} ); // $ExpectError + incrnancv( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnancv(); + + 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 = incrnancv(); + + 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/nancv/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js new file mode 100644 index 000000000000..e15dd209e030 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 incrnancv = require( './../lib' ); + +var accumulator; +var cv; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnancv(); + +// For each simulated datum, update the coefficient of variation, ignoring NaN values... +console.log( '\nValue\tCV\n' ); +for ( i = 0; i < 100; i++ ) { + v = ( (randu() < 0.1) ? NaN : (randu() * 100.0) ); + cv = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), cv.toFixed( 4 ) ); +} +console.log( '\nFinal CV: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js new file mode 100644 index 000000000000..0a73c86c892e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the coefficient of variation (CV) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nancv +* +* @example +* var incrcv = require( '@stdlib/stats/incr/nancv' ); +* +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( NaN ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js new file mode 100644 index 000000000000..b0870057ef70 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // +var incrcv = require( './../incrcv/lib/main' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring NaN values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnancv(); +* +* var cv = accumulator(); +* // returns null +* +* cv = accumulator( 2.0 ); +* // returns 0.0 +* +* cv = accumulator( NaN ); +* // returns 0.0 +* +* cv = accumulator( 1.0 ); +* // returns ~0.47 +* +* cv = accumulator(); +* // returns ~0.47 +*/ +function incrnancv() { + var cv = incrcv(); + + return function accumulator( x ) { + if ( arguments.length === 0 ) { + return cv(); + } + if ( isnan( x ) ) { + return cv(); + } + return cv( x ); + }; +} + +// EXPORTS // + +module.exports = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/package.json b/lib/node_modules/@stdlib/stats/incr/nancv/package.json new file mode 100644 index 000000000000..92e37841b2a1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/incr/nancv", + "version": "0.0.0", + "description": "Incrementally compute the coefficient of variation (CV).", + "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", + "types": "./docs/types", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "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", + "statistics", + "math", + "stdev", + "variance", + "standard deviation", + "dispersion", + "relative", + "cv", + "mean", + "ratio", + "incremental", + "accumulator" + ] +} + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js new file mode 100644 index 000000000000..d0461ea46e45 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -0,0 +1,284 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrnancv = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnancv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnancv(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function (known mean)', function test( t ) { + t.equal( typeof incrnancv( 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() { + incrnancv( value ); + }; + } +}); + +tape( 'the accumulator function incrementally computes the coefficient of variation while ignoring NaN values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, 4.0, NaN, 3.0, 4.0 ]; + + // Expected values ignoring NaNs: + expected = [ + 0.0 / (2.0 / 1.0), + 0.0 / (2.0 / 1.0), // NaN ignored + sqrt( 0.5 ) / (5.0 / 2.0), + sqrt( 0.33333333333333337 ) / (7.0 / 3.0), + sqrt( 0.9166666666666666 ) / (11.0 / 4.0), + sqrt( 0.9166666666666666 ) / (11.0 / 4.0), // NaN ignored + sqrt( 0.7 ) / (14.0 / 5.0), + sqrt( 0.8 ) / (18.0 / 6.0) + ]; + + acc = incrnancv(); + + actual = new Array( data.length ); + for ( i = 0; i < data.length; i++ ) { + actual[ i ] = acc( data[ i ] ); + } + t.deepEqual( actual, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the coefficient of variation (known mean, ignoring NaNs)', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 2.0, 4.0, NaN, 3.0, 4.0 ]; + + // Test against Julia: + expected = [ + sqrt( 1.0 )/3.0, + sqrt( 0.5 )/3.0, + sqrt( 0.6666666666666666 )/3.0, + sqrt( 0.75 )/3.0, + sqrt( 0.6 )/3.0, + sqrt( 0.6666666666666666 )/3.0 + ]; + + acc = incrnancv( 3.0 ); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + if ( !isnan( data[i] ) ) { + actual.push( acc( data[i] ) ); + } + } + t.deepEqual( actual, expected, 'returns expected results while ignoring NaN values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current accumulated value', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 1.0 ]; + acc = incrnancv(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), sqrt( 1.0 ) / 2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current accumulated value (known mean, ignoring NaNs)', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, NaN, 3.0, 1.0, NaN ]; + acc = incrnancv( 2.0 ); + + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + + t.equal( acc(), sqrt( 0.6666666666666666 )/2.0, 'returns expected value while ignoring NaNs' ); + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (unknown mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (known mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv( 3.0 ); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `null` until at least 1 non-NaN datum has been provided', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc(); + t.equal( cv, null, 'returns null' ); + + cv = acc( NaN ); + t.equal( cv, null, 'returns null' ); + + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null' ); + + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); + + t.end(); +}); + +tape( 'the accumulated value is `0` until at least 2 valid datums have been provided (unknown mean, ignoring NaNs)', function test( t ) { + var acc; + var cv; + + acc = incrnancv(); + + cv = acc( 2.0 ); + t.equal( cv, 0.0, 'returns 0' ); + + cv = acc(); + t.equal( cv, 0.0, 'returns 0' ); + + cv = acc( NaN ); + t.equal( cv, 0.0, 'still returns 0 after NaN' ); + + cv = acc( 3.0 ); + t.notEqual( cv, 0.0, 'does not return 0 after two valid numbers' ); + + cv = acc(); + t.notEqual( cv, 0.0, 'does not return 0' ); + + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it and continues accumulating valid values (unknown mean)', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ 2.0, NaN, 1.0, NaN, 2.0, 3.0, NaN, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnancv(); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.notEqual( isnan( v ), true, 'does not return NaN' ); + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + } + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it and continues accumulating valid values (known mean)', function test( t ) { + var data; + var acc; + var v; + var i; + + data = [ 2.0, NaN, 1.0, NaN, 2.0, 3.0, NaN, 4.0, 5.0, 6.0, 7.0 ]; + acc = incrnancv( 3.14 ); + for ( i = 0; i < data.length; i++ ) { + v = acc( data[ i ] ); + t.notEqual( isnan( v ), true, 'does not return NaN' ); + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + } + t.notEqual( isnan( acc() ), true, 'does not return NaN' ); + t.end(); +}); + \ No newline at end of file From 34d0a84e09e7b397785f1091966141ae5c6ac2f4 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 13:22:10 +0530 Subject: [PATCH 04/21] testcase --- lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nancv/test/test.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index b0870057ef70..4d55479b3df0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -19,7 +19,7 @@ 'use strict'; // MODULES // -var incrcv = require( './../incrcv/lib/main' ); +var incrcv = require( './../../cv/lib/main' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); // MAIN // diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js index d0461ea46e45..4274d2d2413c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); var incrnancv = require( './../lib' ); @@ -58,7 +59,7 @@ tape( 'the function throws an error if provided a non-numeric value', function t function noop() {} ]; for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + t.throws( badValue(values[i]), TypeError, 'throws an error when provided ' + values[i] ); } t.end(); @@ -157,7 +158,7 @@ tape( 'if not provided an input value, the accumulator function returns the curr acc( data[ i ] ); } - t.equal( acc(), sqrt( 0.6666666666666666 )/2.0, 'returns expected value while ignoring NaNs' ); + t.equal( acc(), 0.5, 'returns expected value while ignoring NaNs' ); t.end(); }); From d8327b2ed83644bde38e404076e17865941c3a3a Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 14:54:13 +0530 Subject: [PATCH 05/21] edit --- .../@stdlib/stats/incr/nancv/test/test.js | 57 ------------------- 1 file changed, 57 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js index 4274d2d2413c..2945d54b3d09 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -44,32 +44,6 @@ tape( 'the function returns an accumulator function (known mean)', function test 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() { - incrnancv( value ); - }; - } -}); - tape( 'the accumulator function incrementally computes the coefficient of variation while ignoring NaN values', function test( t ) { var expected; var actual; @@ -101,37 +75,6 @@ tape( 'the accumulator function incrementally computes the coefficient of variat t.end(); }); -tape( 'the accumulator function incrementally computes the coefficient of variation (known mean, ignoring NaNs)', function test( t ) { - var expected; - var actual; - var data; - var acc; - var i; - - data = [ 2.0, NaN, 3.0, 2.0, 4.0, NaN, 3.0, 4.0 ]; - - // Test against Julia: - expected = [ - sqrt( 1.0 )/3.0, - sqrt( 0.5 )/3.0, - sqrt( 0.6666666666666666 )/3.0, - sqrt( 0.75 )/3.0, - sqrt( 0.6 )/3.0, - sqrt( 0.6666666666666666 )/3.0 - ]; - - acc = incrnancv( 3.0 ); - - actual = []; - for ( i = 0; i < data.length; i++ ) { - if ( !isnan( data[i] ) ) { - actual.push( acc( data[i] ) ); - } - } - t.deepEqual( actual, expected, 'returns expected results while ignoring NaN values' ); - t.end(); -}); - tape( 'if not provided an input value, the accumulator function returns the current accumulated value', function test( t ) { var data; var acc; From 35109d7c1a5c0777115f07deca35776534026f94 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 15:04:32 +0530 Subject: [PATCH 06/21] added module --- lib/node_modules/@stdlib/stats/incr/nancv/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md index 920899a86a17..c9370844ad4a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -78,7 +78,7 @@ c_v = \frac{s}{\bar{x}} ## Usage ```javascript -var incrcv = require( '@stdlib/stats/incr/nancv' ); +var incrnancv = require( '@stdlib/stats/incr/nancv' ); ``` #### incrnancv( \[mean] ) From 9fe81bc23f42c26f4d00b3fead8d127941e1ca82 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 15:06:56 +0530 Subject: [PATCH 07/21] check --- lib/node_modules/@stdlib/stats/incr/nancv/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md index c9370844ad4a..9354be5dd943 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -106,13 +106,13 @@ var cv = accumulator( 2.0 ); // returns 0.0 cv = accumulator( 1.0 ); // => s^2 = ((2-1.5)^2+(1-1.5)^2) / (2-1) -// returns ~0.47 +// returns 0.4330127018922193 cv=accumulator( 1.0 ); // returns ~0.47 cv = accumulator( 3.0 ); // => s^2 = ((2-2)^2+(1-2)^2+(3-2)^2) / (3-1) -// returns 0.5 +// returns 0.5471012044321932 cv = accumulator(); // returns 0.5 From 8abc195f3db2dc6f1d1cee2390d9e7fb4fa96c47 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 15:13:53 +0530 Subject: [PATCH 08/21] verify --- lib/node_modules/@stdlib/stats/incr/nancv/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md index 9354be5dd943..4e3a98ca63d4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -105,13 +105,13 @@ var accumulator = incrnancv(); var cv = accumulator( 2.0 ); // returns 0.0 -cv = accumulator( 1.0 ); // => s^2 = ((2-1.5)^2+(1-1.5)^2) / (2-1) +cv = accumulator( 1.0 ); // returns 0.4330127018922193 -cv=accumulator( 1.0 ); -// returns ~0.47 +cv = accumulator( NaN ); +// returns 0.4714045207910317 -cv = accumulator( 3.0 ); // => s^2 = ((2-2)^2+(1-2)^2+(3-2)^2) / (3-1) +cv = accumulator( 3.0 ); // returns 0.5471012044321932 cv = accumulator(); From 1a812f25ed9afe928f2eb1235bfe39d64807e69a Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 15:18:25 +0530 Subject: [PATCH 09/21] check --- lib/node_modules/@stdlib/stats/incr/nancv/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md index 4e3a98ca63d4..0a29c4abb565 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -106,13 +106,13 @@ var cv = accumulator( 2.0 ); // returns 0.0 cv = accumulator( 1.0 ); -// returns 0.4330127018922193 +// returns 0.47140452079103173 cv = accumulator( NaN ); // returns 0.4714045207910317 cv = accumulator( 3.0 ); -// returns 0.5471012044321932 +// returns 0.5 cv = accumulator(); // returns 0.5 From a75d19995e593dc32542c51c4c11868c4a7c64ff Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 19:34:09 +0530 Subject: [PATCH 10/21] edit --- .../@stdlib/stats/incr/cv/README.md | 2 +- .../@stdlib/stats/incr/cv/lib/main.js | 131 +++--------------- .../@stdlib/stats/incr/cv/package.json | 2 +- .../stats/incr/nancv/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nancv/lib/main.js | 7 +- 5 files changed, 28 insertions(+), 116 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/cv/README.md b/lib/node_modules/@stdlib/stats/incr/cv/README.md index 7580372fd6d7..7aeda367c0b3 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/cv/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/cv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js index cedf7555d05a..81e795b64e1a 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/cv/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. @@ -20,142 +20,51 @@ // 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 sqrt = require( '@stdlib/math/base/special/sqrt' ); +var isnan = require('@stdlib/math/base/assert/is-nan'); +var incrcv = require('./../../cv/lib/main'); // MAIN // /** -* Returns an accumulator function which incrementally computes the coefficient of variation (CV). +* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring NaN values. * -* ## Method -* -* - This implementation uses [Welford's method][algorithms-variance] for efficient computation, which can be derived as follows. Let -* -* ```tex -* \begin{align*} -* S_n &= n \sigma_n^2 \\ -* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ -* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 -* \end{align*} -* ``` -* -* Accordingly, -* -* ```tex -* \begin{align*} -* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ -* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ -* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ -* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ -* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) -* \end{align*} -* ``` -* -* where we use the identity -* -* ```tex -* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) -* ``` -* -* [algorithms-variance]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance -* -* @param {number} [mean] - mean value -* @throws {TypeError} must provide a number primitive * @returns {Function} accumulator function * * @example -* var accumulator = incrcv(); +* var accumulator = incrnancv(); * * var cv = accumulator(); * // returns null * -* cv = accumulator( 2.0 ); +* cv = accumulator(2.0); +* // returns 0.0 +* +* cv = accumulator(NaN); * // returns 0.0 * -* cv = accumulator( 1.0 ); +* cv = accumulator(1.0); * // returns ~0.47 * * cv = accumulator(); * // returns ~0.47 -* -* @example -* var accumulator = incrcv( 3.14 ); */ -function incrcv( 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 ) ); +function incrnancv() { + var cv = incrcv(); + function accumulator(x) { + if (arguments.length === 0) { + return cv(); } - mu = mean; - return accumulator2; - } - mu = 0.0; - return accumulator1; - - /** - * If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. - * - * @private - * @param {number} [x] - new value - * @returns {(number|null)} accumulated value or null - */ - function accumulator1( x ) { - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - if ( N === 1 ) { - return ( isnan( M2 ) ) ? NaN : 0.0/mu; - } - return sqrt( M2/(N-1) ) / mu; - } - N += 1; - delta = x - mu; - mu += delta / N; - M2 += delta * ( x - mu ); - if ( N < 2 ) { - return ( isnan( M2 ) ) ? NaN : 0.0/mu; + if (isnan(x)) { + return cv(); } - return sqrt( M2/(N-1) ) / mu; + return cv(x); } - /** - * If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. - * - * @private - * @param {number} [x] - new value - * @returns {(number|null)} accumulated value or null - */ - function accumulator2( x ) { - if ( arguments.length === 0 ) { - if ( N === 0 ) { - return null; - } - return sqrt( M2/N ) / mu; - } - N += 1; - delta = x - mu; - M2 += delta * delta; - return sqrt( M2/N ) / mu; - } + return accumulator; } // EXPORTS // -module.exports = incrcv; +module.exports = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/cv/package.json b/lib/node_modules/@stdlib/stats/incr/cv/package.json index cdf587558430..0f920daf9823 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/package.json +++ b/lib/node_modules/@stdlib/stats/incr/cv/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/stats/incr/cv", + "name": "@stdlib/stats/incr/nancv", "version": "0.0.0", "description": "Compute the coefficient of variation (CV) incrementally.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts index bb9e07551524..8f2ef43c8eed 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/types/index.d.ts @@ -50,7 +50,7 @@ type accumulator = ( x?: number ) => number | null; * cv = accumulator( 1.0 ); * // returns ~0.47 * -* * cv = accumulator( NaN ); +* cv = accumulator( NaN ); * // returns ~0.47 * * cv = accumulator(); diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 4d55479b3df0..de237b5ee804 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -19,8 +19,10 @@ 'use strict'; // MODULES // -var incrcv = require( './../../cv/lib/main' ); + var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrcv = require( './../../cv/lib/main' ); + // MAIN // @@ -38,7 +40,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * cv = accumulator( 2.0 ); * // returns 0.0 * -* cv = accumulator( NaN ); +* cv = accumulator( NaN ); * // returns 0.0 * * cv = accumulator( 1.0 ); @@ -61,6 +63,7 @@ function incrnancv() { }; } + // EXPORTS // module.exports = incrnancv; From 535d165f498ef49551606c8975735fd3fb24ba8d Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Mon, 10 Mar 2025 19:41:45 +0530 Subject: [PATCH 11/21] crlf to lf --- lib/node_modules/@stdlib/stats/incr/cv/README.md | 2 +- lib/node_modules/@stdlib/stats/incr/nancv/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/cv/README.md b/lib/node_modules/@stdlib/stats/incr/cv/README.md index 7aeda367c0b3..7580372fd6d7 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/cv/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +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. diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/README.md b/lib/node_modules/@stdlib/stats/incr/nancv/README.md index 0a29c4abb565..8274143bed05 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nancv/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 20125 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 26fe3ef00112b92c4a0d24c5eeaf48b728d9aadb Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 20:49:49 +0530 Subject: [PATCH 12/21] space --- .../@stdlib/stats/incr/nancv/docs/repl.txt | 6 +- .../@stdlib/stats/incr/nancv/lib/main.js | 20 ++-- .../@stdlib/stats/incr/nancv/package.json | 3 +- .../@stdlib/stats/incr/nancv/test/test.js | 97 +++++++++---------- 4 files changed, 62 insertions(+), 64 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt index 37509a37d539..0ebe3261bc0b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nancv/docs/repl.txt @@ -1,9 +1,9 @@ {{alias}}( [mean] ) - Returns an accumulator function which incrementally computes the + Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring `NaN` values. - If provided a value, the accumulator function returns an updated - accumulated value. If not provided a value, the accumulator function + If provided a value, the accumulator function returns an updated + accumulated value. If not provided a value, the accumulator function returns the current accumulated value. If all received values are `NaN`, the accumulated value remains `null`. diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index de237b5ee804..9e5d2be4eb56 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -50,17 +50,17 @@ var incrcv = require( './../../cv/lib/main' ); * // returns ~0.47 */ function incrnancv() { - var cv = incrcv(); + var cv = incrcv(); - return function accumulator( x ) { - if ( arguments.length === 0 ) { - return cv(); - } - if ( isnan( x ) ) { - return cv(); - } - return cv( x ); - }; + return function accumulator( x ) { + if ( arguments.length === 0 ) { + return cv(); + } + if ( isnan( x ) ) { + return cv(); + } + return cv( x ); + }; } diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/package.json b/lib/node_modules/@stdlib/stats/incr/nancv/package.json index 92e37841b2a1..d65448164428 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nancv/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nancv", "version": "0.0.0", - "description": "Incrementally compute the coefficient of variation (CV).", + "description": "Incrementally compute the coefficient of variation (CV), while ignoring `NaN` values.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -64,4 +64,3 @@ "accumulator" ] } - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js index 2945d54b3d09..a7b82c16824c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -90,61 +90,61 @@ tape( 'if not provided an input value, the accumulator function returns the curr }); tape( 'if not provided an input value, the accumulator function returns the current accumulated value (known mean, ignoring NaNs)', function test( t ) { - var data; - var acc; - var i; + var data; + var acc; + var i; - data = [ 2.0, NaN, 3.0, 1.0, NaN ]; - acc = incrnancv( 2.0 ); + data = [ 2.0, NaN, 3.0, 1.0, NaN ]; + acc = incrnancv( 2.0 ); - for ( i = 0; i < data.length; i++ ) { - acc( data[ i ] ); - } + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } - t.equal( acc(), 0.5, 'returns expected value while ignoring NaNs' ); - t.end(); + t.equal( acc(), 0.5, 'returns expected value while ignoring NaNs' ); + t.end(); }); tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (unknown mean, ignoring NaNs)', function test( t ) { - var acc; - var cv; + var acc; + var cv; - acc = incrnancv(); + acc = incrnancv(); - cv = acc(); - t.equal( cv, null, 'returns null' ); + cv = acc(); + t.equal( cv, null, 'returns null' ); - cv = acc( NaN ); - t.equal( cv, null, 'still returns null after NaN' ); + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); - cv = acc( 3.0 ); - t.notEqual( cv, null, 'does not return null after valid number' ); + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); - cv = acc(); - t.notEqual( cv, null, 'does not return null' ); + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); - t.end(); + t.end(); }); tape( 'the accumulated value is `null` until at least 1 valid datum has been provided (known mean, ignoring NaNs)', function test( t ) { - var acc; - var cv; + var acc; + var cv; - acc = incrnancv( 3.0 ); + acc = incrnancv( 3.0 ); - cv = acc(); - t.equal( cv, null, 'returns null' ); + cv = acc(); + t.equal( cv, null, 'returns null' ); - cv = acc( NaN ); - t.equal( cv, null, 'still returns null after NaN' ); + cv = acc( NaN ); + t.equal( cv, null, 'still returns null after NaN' ); - cv = acc( 3.0 ); - t.notEqual( cv, null, 'does not return null after valid number' ); + cv = acc( 3.0 ); + t.notEqual( cv, null, 'does not return null after valid number' ); - cv = acc(); - t.notEqual( cv, null, 'does not return null' ); + cv = acc(); + t.notEqual( cv, null, 'does not return null' ); - t.end(); + t.end(); }); tape( 'the accumulated value is `null` until at least 1 non-NaN datum has been provided', function test( t ) { @@ -169,27 +169,27 @@ tape( 'the accumulated value is `null` until at least 1 non-NaN datum has been p }); tape( 'the accumulated value is `0` until at least 2 valid datums have been provided (unknown mean, ignoring NaNs)', function test( t ) { - var acc; - var cv; + var acc; + var cv; - acc = incrnancv(); + acc = incrnancv(); - cv = acc( 2.0 ); - t.equal( cv, 0.0, 'returns 0' ); + cv = acc( 2.0 ); + t.equal( cv, 0.0, 'returns 0' ); - cv = acc(); - t.equal( cv, 0.0, 'returns 0' ); + cv = acc(); + t.equal( cv, 0.0, 'returns 0' ); - cv = acc( NaN ); - t.equal( cv, 0.0, 'still returns 0 after NaN' ); + cv = acc( NaN ); + t.equal( cv, 0.0, 'still returns 0 after NaN' ); - cv = acc( 3.0 ); - t.notEqual( cv, 0.0, 'does not return 0 after two valid numbers' ); + cv = acc( 3.0 ); + t.notEqual( cv, 0.0, 'does not return 0 after two valid numbers' ); - cv = acc(); - t.notEqual( cv, 0.0, 'does not return 0' ); + cv = acc(); + t.notEqual( cv, 0.0, 'does not return 0' ); - t.end(); + t.end(); }); tape( 'if provided a `NaN`, the accumulator function ignores it and continues accumulating valid values (unknown mean)', function test( t ) { @@ -225,4 +225,3 @@ tape( 'if provided a `NaN`, the accumulator function ignores it and continues ac t.notEqual( isnan( acc() ), true, 'does not return NaN' ); t.end(); }); - \ No newline at end of file From 8bb703740597aa023aba9fe9db4423dd0910c3d7 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:09:00 +0530 Subject: [PATCH 13/21] verify --- lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 9e5d2be4eb56..c7b613d6e0bc 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var incrcv = require( './../../cv/lib/main' ); +var incrcv = require( '@stdlib/stats/incr/cv' ); // MAIN // From e65cb4d15eeb5cd73d8ddc995f5c8b5d0da57dd7 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:13:52 +0530 Subject: [PATCH 14/21] check --- lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js index 0a73c86c892e..b7078cfde7fe 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/index.js @@ -24,7 +24,7 @@ * @module @stdlib/stats/incr/nancv * * @example -* var incrcv = require( '@stdlib/stats/incr/nancv' ); +* var incrnancv = require( '@stdlib/stats/incr/nancv' ); * * var accumulator = incrnancv(); * diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index c7b613d6e0bc..6e96c280833c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -20,8 +20,8 @@ // MODULES // -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrcv = require( '@stdlib/stats/incr/cv' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); // MAIN // From 62781dc93bd0c40a805492ce16736c8f89dffc02 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:20:46 +0530 Subject: [PATCH 15/21] verify --- .../@stdlib/stats/incr/cv/lib/main.js | 131 +++++++++++++++--- 1 file changed, 111 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js index 81e795b64e1a..6a9ab8f64ff4 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. @@ -20,51 +20,142 @@ // MODULES // -var isnan = require('@stdlib/math/base/assert/is-nan'); -var incrcv = require('./../../cv/lib/main'); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); // MAIN // /** -* Returns an accumulator function which incrementally computes the coefficient of variation (CV), ignoring NaN values. +* Returns an accumulator function which incrementally computes the coefficient of variation (CV). * +* ## Method +* +* - This implementation uses [Welford's method][algorithms-variance] for efficient computation, which can be derived as follows. Let +* +* ```tex +* \begin{align*} +* S_n &= n \sigma_n^2 \\ +* &= \sum_{i=1}^{n} (x_i - \mu_n)^2 \\ +* &= \biggl(\sum_{i=1}^{n} x_i^2 \biggr) - n\mu_n^2 +* \end{align*} +* ``` +* +* Accordingly, +* +* ```tex +* \begin{align*} +* S_n - S_{n-1} &= \sum_{i=1}^{n} x_i^2 - n\mu_n^2 - \sum_{i=1}^{n-1} x_i^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - n\mu_n^2 + (n-1)\mu_{n-1}^2 \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1}^2 - \mu_n^2) \\ +* &= x_n^2 - \mu_{n-1}^2 + n(\mu_{n-1} - \mu_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + (\mu_{n-1} - x_n)(\mu_{n-1} + \mu_n) \\ +* &= x_n^2 - \mu_{n-1}^2 + \mu_{n-1}^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= x_n^2 - x_n\mu_n - x_n\mu_{n-1} + \mu_n\mu_{n-1} \\ +* &= (x_n - \mu_{n-1})(x_n - \mu_n) \\ +* &= S_{n-1} + (x_n - \mu_{n-1})(x_n - \mu_n) +* \end{align*} +* ``` +* +* where we use the identity +* +* ```tex +* x_n - \mu_{n-1} = n (\mu_n - \mu_{n-1}) +* ``` +* +* [algorithms-variance]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance +* +* @param {number} [mean] - mean value +* @throws {TypeError} must provide a number primitive * @returns {Function} accumulator function * * @example -* var accumulator = incrnancv(); +* var accumulator = incrcv(); * * var cv = accumulator(); * // returns null * -* cv = accumulator(2.0); -* // returns 0.0 -* -* cv = accumulator(NaN); +* cv = accumulator( 2.0 ); * // returns 0.0 * -* cv = accumulator(1.0); +* cv = accumulator( 1.0 ); * // returns ~0.47 * * cv = accumulator(); * // returns ~0.47 +* +* @example +* var accumulator = incrcv( 3.14 ); */ -function incrnancv() { - var cv = incrcv(); - function accumulator(x) { - if (arguments.length === 0) { - return cv(); +function incrcv( 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 ) ); } - if (isnan(x)) { - return cv(); + mu = mean; + return accumulator2; + } + mu = 0.0; + return accumulator1; + + /** + * If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} accumulated value or null + */ + function accumulator1( x ) { + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + if ( N === 1 ) { + return ( isnan( M2 ) ) ? NaN : 0.0/mu; + } + return sqrt( M2/(N-1) ) / mu; + } + N += 1; + delta = x - mu; + mu += delta / N; + M2 += delta * ( x - mu ); + if ( N < 2 ) { + return ( isnan( M2 ) ) ? NaN : 0.0/mu; } - return cv(x); + return sqrt( M2/(N-1) ) / mu; } - return accumulator; + /** + * If provided a value, the accumulator function returns an updated accumulated value. If not provided a value, the accumulator function returns the current accumulated value. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} accumulated value or null + */ + function accumulator2( x ) { + if ( arguments.length === 0 ) { + if ( N === 0 ) { + return null; + } + return sqrt( M2/N ) / mu; + } + N += 1; + delta = x - mu; + M2 += delta * delta; + return sqrt( M2/N ) / mu; + } } // EXPORTS // -module.exports = incrnancv; +module.exports = incrcv; \ No newline at end of file From 64e372b21fd53e0a020e9f515e8758fcf03309c3 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:25:11 +0530 Subject: [PATCH 16/21] linting --- lib/node_modules/@stdlib/stats/incr/cv/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js index 6a9ab8f64ff4..cedf7555d05a 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/cv/lib/main.js @@ -158,4 +158,4 @@ function incrcv( mean ) { // EXPORTS // -module.exports = incrcv; \ No newline at end of file +module.exports = incrcv; From e4b2e64d97bcc006ad18be2792579397ccf86f23 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:30:57 +0530 Subject: [PATCH 17/21] check --- lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 6e96c280833c..330dae363ef1 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -51,8 +51,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); */ function incrnancv() { var cv = incrcv(); - - return function accumulator( x ) { + function accumulator( x ) { if ( arguments.length === 0 ) { return cv(); } @@ -61,6 +60,7 @@ function incrnancv() { } return cv( x ); }; + return accumulator; } From f6d69d3653899c4a71fc6b16fb51458d6975e434 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:38:02 +0530 Subject: [PATCH 18/21] space --- .../@stdlib/stats/incr/nancv/lib/main.js | 16 ++- .../@stdlib/stats/incr/nansum/package.json | 124 +++++++++--------- 2 files changed, 74 insertions(+), 66 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 330dae363ef1..4e5370b78811 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -23,7 +23,6 @@ var incrcv = require( '@stdlib/stats/incr/cv' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); - // MAIN // /** @@ -51,6 +50,15 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); */ function incrnancv() { var cv = incrcv(); + + /** + * If provided a value, the accumulator function returns an updated accumulated value. + * If not provided a value, the accumulator function returns the current accumulated value. + * + * @private + * @param {number} [x] - new value + * @returns {(number|null)} accumulated value or null + */ function accumulator( x ) { if ( arguments.length === 0 ) { return cv(); @@ -59,10 +67,10 @@ function incrnancv() { return cv(); } return cv( x ); - }; - return accumulator; -} + } + return accumulator; +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/incr/nansum/package.json b/lib/node_modules/@stdlib/stats/incr/nansum/package.json index 642ac23d3d53..1f057e3fa19d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nansum/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nansum/package.json @@ -1,64 +1,64 @@ { - "name": "@stdlib/stats/incr/nansum", - "version": "0.0.0", - "description": "Compute a sum 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", - "summation", - "sum", - "total", - "incremental", - "accumulator" - ] + "name": "@stdlib/stats/incr/nansum", + "version": "0.0.0", + "description": "Compute a sum 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", + "summation", + "sum", + "total", + "incremental", + "accumulator" + ] } From ea56dc9680e660bbe2fe0bbf9023c8e02a94563e Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:44:59 +0530 Subject: [PATCH 19/21] done --- .../@stdlib/stats/incr/nancv/lib/main.js | 2 + .../@stdlib/stats/incr/nancv/package.json | 126 +++++++++--------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 4e5370b78811..0be846e30522 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -23,6 +23,7 @@ var incrcv = require( '@stdlib/stats/incr/cv' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); + // MAIN // /** @@ -72,6 +73,7 @@ function incrnancv() { return accumulator; } + // EXPORTS // module.exports = incrnancv; diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/package.json b/lib/node_modules/@stdlib/stats/incr/nancv/package.json index d65448164428..1f057e3fa19d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nancv/package.json @@ -1,66 +1,64 @@ { - "name": "@stdlib/stats/incr/nancv", - "version": "0.0.0", - "description": "Incrementally compute the coefficient of variation (CV), while 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", - "types": "./docs/types", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "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", - "statistics", - "math", - "stdev", - "variance", - "standard deviation", - "dispersion", - "relative", - "cv", - "mean", - "ratio", - "incremental", - "accumulator" - ] + "name": "@stdlib/stats/incr/nansum", + "version": "0.0.0", + "description": "Compute a sum 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", + "summation", + "sum", + "total", + "incremental", + "accumulator" + ] } From 8170fc880f83bdecbe974d23a58a3fb5ccf4623d Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:52:47 +0530 Subject: [PATCH 20/21] done --- .../@stdlib/stats/incr/nancv/lib/main.js | 2 +- .../@stdlib/stats/incr/nansum/package.json | 124 +++++++++--------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js index 0be846e30522..85e21d8d2756 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/lib/main.js @@ -51,7 +51,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); */ function incrnancv() { var cv = incrcv(); - + /** * If provided a value, the accumulator function returns an updated accumulated value. * If not provided a value, the accumulator function returns the current accumulated value. diff --git a/lib/node_modules/@stdlib/stats/incr/nansum/package.json b/lib/node_modules/@stdlib/stats/incr/nansum/package.json index 1f057e3fa19d..642ac23d3d53 100644 --- a/lib/node_modules/@stdlib/stats/incr/nansum/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nansum/package.json @@ -1,64 +1,64 @@ { - "name": "@stdlib/stats/incr/nansum", - "version": "0.0.0", - "description": "Compute a sum 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", - "summation", - "sum", - "total", - "incremental", - "accumulator" - ] + "name": "@stdlib/stats/incr/nansum", + "version": "0.0.0", + "description": "Compute a sum 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", + "summation", + "sum", + "total", + "incremental", + "accumulator" + ] } From edd09483e15edeeb9189884276b2ba08526666f9 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 12 Mar 2025 21:59:57 +0530 Subject: [PATCH 21/21] check --- .../@stdlib/stats/incr/cv/package.json | 2 +- .../@stdlib/stats/incr/nancv/package.json | 133 ++++++++++-------- .../@stdlib/stats/incr/nancv/test/test.js | 5 +- 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/cv/package.json b/lib/node_modules/@stdlib/stats/incr/cv/package.json index 0f920daf9823..cdf587558430 100644 --- a/lib/node_modules/@stdlib/stats/incr/cv/package.json +++ b/lib/node_modules/@stdlib/stats/incr/cv/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/stats/incr/nancv", + "name": "@stdlib/stats/incr/cv", "version": "0.0.0", "description": "Compute the coefficient of variation (CV) incrementally.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/package.json b/lib/node_modules/@stdlib/stats/incr/nancv/package.json index 1f057e3fa19d..0f920daf9823 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nancv/package.json @@ -1,64 +1,73 @@ { - "name": "@stdlib/stats/incr/nansum", - "version": "0.0.0", - "description": "Compute a sum 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", - "summation", - "sum", - "total", - "incremental", - "accumulator" - ] + "name": "@stdlib/stats/incr/nancv", + "version": "0.0.0", + "description": "Compute the coefficient of variation (CV) incrementally.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "stdev", + "std", + "variance", + "var", + "standard", + "deviation", + "dispersion", + "relative", + "rsd", + "cv", + "mean", + "ratio", + "incremental", + "accumulator" + ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js index a7b82c16824c..e01019857f84 100644 --- a/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nancv/test/test.js @@ -46,7 +46,7 @@ tape( 'the function returns an accumulator function (known mean)', function test tape( 'the accumulator function incrementally computes the coefficient of variation while ignoring NaN values', function test( t ) { var expected; - var actual; + var actual = []; var data; var acc; var i; @@ -67,9 +67,8 @@ tape( 'the accumulator function incrementally computes the coefficient of variat acc = incrnancv(); - actual = new Array( data.length ); for ( i = 0; i < data.length; i++ ) { - actual[ i ] = acc( data[ i ] ); + actual.push( acc( data[ i ] ) ); } t.deepEqual( actual, expected, 'returns expected results' ); t.end();