From f3d4e018cf051f04eae9758b3fd7d617acf35ee9 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Sat, 8 Mar 2025 15:02:41 +0530 Subject: [PATCH 01/12] 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/12] 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 1c7d46a1480617c03d7f6a5c2d7e15cf29dedc15 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 19:35:07 +0530 Subject: [PATCH 03/12] done --- .../@stdlib/stats/incr/nanmrss/README.md | 186 ++++++++++++++++++ .../stats/incr/nanmrss/benchmark/benchmark.js | 69 +++++++ .../@stdlib/stats/incr/nanmrss/docs/repl.txt | 51 +++++ .../stats/incr/nanmrss/docs/types/index.d.ts | 83 ++++++++ .../stats/incr/nanmrss/docs/types/test.ts | 74 +++++++ .../stats/incr/nanmrss/examples/index.js | 41 ++++ .../@stdlib/stats/incr/nanmrss/lib/index.js | 66 +++++++ .../@stdlib/stats/incr/nanmrss/lib/main.js | 92 +++++++++ .../@stdlib/stats/incr/nanmrss/package.json | 91 +++++++++ .../@stdlib/stats/incr/nanmrss/test/test.js | 136 +++++++++++++ 10 files changed, 889 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md new file mode 100644 index 000000000000..99ebc71d12bd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md @@ -0,0 +1,186 @@ + + +# incrnanmrss + +> Compute a moving [residual sum of squares][residual-sum-of-squares] (RSS) incrementally, ignoring `NaN` calues. + +
+ +For a window of size `W`, the [residual sum of squares][residual-sum-of-squares] (also referred to as the **sum of squared residuals** (SSR) and the **sum of squared errors** (SSE)) is defined as + + + +```math +\mathop{\mathrm{RSS}} = \sum_{i=0}^{W-1} (y_i - x_i)^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmrss = require( '@stdlib/stats/incr/nanmrss' ); +``` + +#### incrnanmrss( window ) + +Returns an accumulator `function` which incrementally computes a moving [residual sum of squares][residual-sum-of-squares]. The `window` parameter defines the number of values over which to compute the moving [residual sum of squares][residual-sum-of-squares]. + +```javascript +var accumulator = incrnanmrss( 3 ); +``` + +#### accumulator( \[x, y] ) + +If provided input values `x` and `y`, the accumulator function returns an updated [residual sum of squares][residual-sum-of-squares]. If not provided input values `x` and `y`, the accumulator function returns the current [residual sum of squares][residual-sum-of-squares]. + +```javascript +var accumulator = incrnanmrss( 3 ); + +var r = accumulator(); +// returns null + +// Fill the window... +r = accumulator( 2.0, 3.0 ); // [(2.0,3.0)] +// returns 1.0 + +// Fill the window... +r = accumulator( NaN, 3.0 ); // [(2.0,3.0), ( NaN, 3.0)] +// returns 1.0 + +// Fill the window... +r = accumulator( 2.0, NaN ); // [(2.0,3.0), ( NaN, 3.0), ( 2.0, NaN )] +// returns 1.0 + +// Fill the window... +r = accumulator( NaN, NaN ); // [(2.0,3.0)] +// returns 1.0 + +r = accumulator( -1.0, 4.0 ); // [(2.0,3.0), (-1.0,4.0)] +// returns 26.0 + +r = accumulator( 3.0, 9.0 ); // [(2.0,3.0), (-1.0,4.0), (3.0,9.0)] +// returns 62.0 + +// Window begins sliding... +r = accumulator( -7.0, 3.0 ); // [(-1.0,4.0), (3.0,9.0), (-7.0,3.0)] +// returns 161.0 + +r = accumulator( -5.0, -3.0 ); // [(3.0,9.0), (-7.0,3.0), (-5.0,-3.0)] +// returns 140.0 + +r = accumulator(); +// returns 140.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- As `W` (x,y) pairs are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanmrss = require( '@stdlib/stats/incr/nanmrss' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmrss( 5 ); + +// For each simulated datum, update the moving residual sum of squares... +for ( i = 0; i < 100; i++ ) { + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + accumulator( v1, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/benchmark/benchmark.js new file mode 100644 index 000000000000..59e0712908da --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanmrss = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmrss( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmrss( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()-0.5, randu()-0.5 ); + 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/nanmrss/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/repl.txt new file mode 100644 index 000000000000..256b89602fbc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + residual sum of squares (RSS), ignoring `NaN` values. + + The `W` parameter defines the number of values over which to compute the + moving residual sum of squares. + + If provided a value, the accumulator function returns an updated moving + residual sum of squares. If not provided a value, the accumulator function + returns the current moving residual sum of squares. + + As `W` values are needed to fill the window buffer, the first `W-1` returned + values are calculated from smaller sample sizes. Until the window is full, + each returned value is calculated from all provided values. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var r = accumulator() + null + > r = accumulator( 2.0, 3.0 ) + 1.0 + > r = accumulator( NaN, 3.0 ) + 1.0 + > r = accumulator( 2.0, NaN ) + 1.0 + > r = accumulator( NaN, NaN ) + 1.0 + > r = accumulator( -5.0, 2.0 ) + 50.0 + > r = accumulator( 3.0, 2.0 ) + 51.0 + > r = accumulator( 5.0, -2.0 ) + 99.0 + > r = accumulator() + 99.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts new file mode 100644 index 000000000000..2235b84f0661 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts @@ -0,0 +1,83 @@ +/* +* @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 arguments, returns an updated residual sum of squares; otherwise, returns the current residual sum of squares, ignoring `NaN` values. +* +* ## 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 +* @param y - value +* @returns residual sum of squares +*/ +type accumulator = ( x?: number, y?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving residual sum of squares, ignoring `NaN` values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving residual sum of squares. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrmrss( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( NaN, NaN ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( NaN, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns 51.0 +* +* r = accumulator( 5.0, -2.0 ); +* // returns 99.0 +* +* r = accumulator(); +* // returns 99.0 +*/ +declare function incrnanmrss( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmrss; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts new file mode 100644 index 000000000000..294826e5b5ef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts @@ -0,0 +1,74 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025The 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 incrnanmrss = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmrss( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanmrss( '5' ); // $ExpectError + incrnanmrss( true ); // $ExpectError + incrnanmrss( false ); // $ExpectError + incrnanmrss( null ); // $ExpectError + incrnanmrss( undefined ); // $ExpectError + incrnanmrss( [] ); // $ExpectError + incrnanmrss( {} ); // $ExpectError + incrnanmrss( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrnanmrss(); // $ExpectError + incrnanmrss( 2, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmrss( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14, 2.0 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanmrss( 3 ); + + acc( '5', 1.0 ); // $ExpectError + acc( true, 1.0 ); // $ExpectError + acc( false, 1.0 ); // $ExpectError + acc( null, 1.0 ); // $ExpectError + acc( [], 1.0 ); // $ExpectError + acc( {}, 1.0 ); // $ExpectError + acc( ( x: number ): number => x, 1.0 ); // $ExpectError + + acc( 3.14, '5' ); // $ExpectError + acc( 3.14, true ); // $ExpectError + acc( 3.14, false ); // $ExpectError + acc( 3.14, null ); // $ExpectError + acc( 3.14, [] ); // $ExpectError + acc( 3.14, {} ); // $ExpectError + acc( 3.14, ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js new file mode 100644 index 000000000000..b3184265cbb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var incrnanmrss = require( './../lib' ); + +var accumulator; +var rss; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanmrss( 5 ); + +// For each simulated datum, update the moving residual sum of squares... +console.log( '\nValue\tValue\tRSS\n' ); +for ( i = 0; i < 100; i++ ) { + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + rss = accumulator( v1, v2 ); + console.log( '%s\t%s\t%s', v1 !== v1 ? 'NaN' : v1.toFixed( 3 ), v2 !== v2 ? 'NaN' : v2.toFixed( 3 ), rss !== null && rss === rss ? rss.toFixed( 3 ) : 'null'); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/index.js new file mode 100644 index 000000000000..fc5efd0ae1e6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/index.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'; + +/** +* Compute a moving residual sum of squares (RSS) incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanmrss +* +* @example +* var incrnanmrss = require( '@stdlib/stats/incr/nanmrss' ); +* +* var accumulator = incrnanmrss( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( NaN, 3.0 ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( NaN, NaN ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns 51.0 +* +* r = accumulator( 5.0, -2.0 ); +* // returns 99.0 +* +* r = accumulator(); +* // returns 99.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js new file mode 100644 index 000000000000..111033e21b2f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmrss = require( '@stdlib/stats/incr/mrss' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving residual sum of squares, ignoring `NaN` values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmrss( 3 ); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( NaN, 3.0 ); +* // returns 1.0 +* +* r = accumulator( 2.0, NaN ); +* // returns 1.0 +* +* r = accumulator( NaN, NaN ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator( 3.0, 2.0 ); +* // returns 51.0 +* +* r = accumulator( 5.0, -2.0 ); +* // returns 99.0 +* +* r = accumulator(); +* // returns 99.0 +*/ +function incrnanmrss( W ) { + var mrss = incrmrss( W ); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated residual sum of squares. If not provided input values, the accumulator function returns the current residual sum of squares. + * + * @private + * @param {number} [x] - input value + * @param {number} [y] - input value + * @returns {(number|null)} residual sum of squares or null + */ + function accumulator( x, y ) { + if ( arguments.length === 0 ){ + return mrss(); + } + if ( isnan( x ) || isnan( y ) ) { + return mrss(); + } + return mrss( isnan(x) ? 0 : x, isnan(y) ? 0 : y ); + } +} + + +// EXPORTS // + +module.exports = incrnanmrss; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/package.json b/lib/node_modules/@stdlib/stats/incr/nanmrss/package.json new file mode 100644 index 000000000000..85952d1d4618 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/package.json @@ -0,0 +1,91 @@ +{ + "name": "@stdlib/stats/incr/nanmrss", + "version": "0.0.0", + "description": "Compute a moving residual sum of squares (RSS) 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", + "error", + "err", + "rss", + "ssr", + "sse", + "residuals", + "sum", + "total", + "squares", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "sliding window", + "sliding", + "window", + "moving", + "time series", + "timeseries", + "forecasting", + "forecast", + "model", + "selection", + "evaluation", + "prediction", + "manhattan", + "cityblock", + "city-block", + "distance", + "dist" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js new file mode 100644 index 000000000000..d8c0a6ad7f8a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js @@ -0,0 +1,136 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanmrss = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmrss, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmrss( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmrss( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving residual sum of squares incrementally', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var N; + var i; + + data = [ + [ 2.0, 3.0 ], + [ NaN, 3.0 ], + [ 2.0, NaN ], + [ 3.0, -1.0 ], + [ 2.0, 5.0 ], + [ 4.0, -4.0 ], + [ NaN, NaN ], + [ 3.0, 0.0 ], + [ -4.0, 5.0 ] + ]; + N = data.length; + + acc = incrnanmrss( 3 ); + + expected = [ 1.0, 1.0, 1.0, 17.0, 26.0, 89.0, 89.0, 82.0, 154.0 ]; + for ( i = 0; i < N; i++ ) { + actual = acc( data[i][0], data[i][1] ); + if ( actual === expected[i] ) { + t.equal( actual, expected[i], 'returns expected value' ); + } else { + delta = abs( expected[i] - actual ); + tol = 1.0 * EPS * abs( expected[i] ); + t.equal( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected[i]+'. Delta: '+delta+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current residual sum of squares', function test( t ) { + var data; + var acc; + var i; + + data = [ + [ 2.0, 3.0 ], + [ NaN, 5.0 ], + [ 3.0, -5.0 ], + [ 1.0, NaN ], + [ 1.0, 10.0 ] + ]; + acc = incrnanmrss( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[i][0], data[i][1] ); + } + t.equal( acc(), 145.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmrss( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); From ea2a0bb32b5118ca086ba5e8da1d67bd0baff1ca Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 19:44:29 +0530 Subject: [PATCH 04/12] lint --- lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js index 111033e21b2f..463e5895aeae 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js index d8c0a6ad7f8a..434460e8a930 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); var EPS = require( '@stdlib/constants/float64/eps' ); var incrnanmrss = require( './../lib' ); From 70cece240763a0bbd7873e0ba90ed7a3ea86efc7 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 19:58:04 +0530 Subject: [PATCH 05/12] added nanmrss --- .../@stdlib/stats/incr/nanmrss/README.md | 4 ++-- .../@stdlib/stats/incr/nanmrss/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanmrss/lib/main.js | 12 ++++++------ .../@stdlib/stats/incr/nanmrss/test/test.js | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md index 99ebc71d12bd..df37b2463ca5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md @@ -138,9 +138,9 @@ accumulator = incrnanmrss( 5 ); // For each simulated datum, update the moving residual sum of squares... for ( i = 0; i < 100; i++ ) { - v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); - accumulator( v1, v2 ); + accumulator( v1, v2 ); } console.log( accumulator() ); ``` diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts index 2235b84f0661..260190bfc49e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts @@ -53,7 +53,7 @@ type accumulator = ( x?: number, y?: number ) => number | null; * * r = accumulator( 2.0, 3.0 ); * // returns 1.0 -* +* * r = accumulator( NaN, NaN ); * // returns 1.0 * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js index 463e5895aeae..703f28b6d8fc 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js @@ -77,12 +77,12 @@ function incrnanmrss( W ) { */ function accumulator( x, y ) { if ( arguments.length === 0 ){ - return mrss(); - } - if ( isnan( x ) || isnan( y ) ) { - return mrss(); - } - return mrss( isnan(x) ? 0 : x, isnan(y) ? 0 : y ); + return mrss(); + } + if ( isnan( x ) || isnan( y ) ) { + return mrss(); + } + return mrss( (isnan(x) ? 0 : x), (isnan(y) ? 0 : y) ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js index 434460e8a930..58c9f0b4da06 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js @@ -81,12 +81,12 @@ tape( 'the accumulator function computes a moving residual sum of squares increm data = [ [ 2.0, 3.0 ], - [ NaN, 3.0 ], + [ NaN, 3.0 ], [ 2.0, NaN ], [ 3.0, -1.0 ], [ 2.0, 5.0 ], [ 4.0, -4.0 ], - [ NaN, NaN ], + [ NaN, NaN ], [ 3.0, 0.0 ], [ -4.0, 5.0 ] ]; @@ -115,9 +115,9 @@ tape( 'if not provided an input value, the accumulator function returns the curr data = [ [ 2.0, 3.0 ], - [ NaN, 5.0 ], + [ NaN, 5.0 ], [ 3.0, -5.0 ], - [ 1.0, NaN ], + [ 1.0, NaN ], [ 1.0, 10.0 ] ]; acc = incrnanmrss( 2 ); From 86b1cdc8a535f90c7c6baaff93bdcfd3da594267 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 20:10:53 +0530 Subject: [PATCH 06/12] added module --- lib/node_modules/@stdlib/stats/incr/nanmrss/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md index df37b2463ca5..c35376d4ea83 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md @@ -138,9 +138,9 @@ accumulator = incrnanmrss( 5 ); // For each simulated datum, update the moving residual sum of squares... for ( i = 0; i < 100; i++ ) { - v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); - v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); - accumulator( v1, v2 ); + v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); + accumulator( v1, v2 ); } console.log( accumulator() ); ``` From fada70fb59507c5553e7eb0dcccdc6d0aeab68d5 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 20:29:00 +0530 Subject: [PATCH 07/12] added module --- .../@stdlib/stats/incr/nanmrss/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js | 4 ++-- lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts index 294826e5b5ef..77d1f992fd79 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025The 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/nanmrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js index 703f28b6d8fc..9a348edbf7b1 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js @@ -76,13 +76,13 @@ function incrnanmrss( W ) { * @returns {(number|null)} residual sum of squares or null */ function accumulator( x, y ) { - if ( arguments.length === 0 ){ + if ( arguments.length === 0 ) { return mrss(); } if ( isnan( x ) || isnan( y ) ) { return mrss(); } - return mrss( (isnan(x) ? 0 : x), (isnan(y) ? 0 : y) ); + return mrss( ( ( isnan( x ) ) ? 0 : x), ( ( isnan( y ) ) ? 0 : y ) ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js index 58c9f0b4da06..f620072da62b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/test/test.js @@ -82,7 +82,7 @@ tape( 'the accumulator function computes a moving residual sum of squares increm data = [ [ 2.0, 3.0 ], [ NaN, 3.0 ], - [ 2.0, NaN ], + [ 2.0, NaN ], [ 3.0, -1.0 ], [ 2.0, 5.0 ], [ 4.0, -4.0 ], From 2cc2fc71b254986660179df5e1c27d771f7807e3 Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 20:42:42 +0530 Subject: [PATCH 08/12] lint --- lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js index b3184265cbb6..e1082629d5e4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js @@ -37,5 +37,5 @@ for ( i = 0; i < 100; i++ ) { v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); rss = accumulator( v1, v2 ); - console.log( '%s\t%s\t%s', v1 !== v1 ? 'NaN' : v1.toFixed( 3 ), v2 !== v2 ? 'NaN' : v2.toFixed( 3 ), rss !== null && rss === rss ? rss.toFixed( 3 ) : 'null'); + console.log( '%s\t%s\t%s', ((v1 !== v1) ? 'NaN' : v1.toFixed(3)), ((v2 !== v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && (rss === rss)) ? rss.toFixed(3) : 'null'); } From 7ff1424f363acc47bbb828f998fb76bf9f6025cf Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 20:52:03 +0530 Subject: [PATCH 09/12] lint --- lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js index e1082629d5e4..42af66f3e0f4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js @@ -37,5 +37,5 @@ for ( i = 0; i < 100; i++ ) { v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); rss = accumulator( v1, v2 ); - console.log( '%s\t%s\t%s', ((v1 !== v1) ? 'NaN' : v1.toFixed(3)), ((v2 !== v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && (rss === rss)) ? rss.toFixed(3) : 'null'); + console.log( '%s\t%s\t%s', ((v1 === v1) ? 'NaN' : v1.toFixed(3)), ((v2 === v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && (rss === rss)) ? rss.toFixed(3) : 'null'); } From 58e1c8668f998984841c5ea6d63f1c1c48ee4e4d Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 20:55:19 +0530 Subject: [PATCH 10/12] lint --- lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js index 42af66f3e0f4..1c4b51a792ee 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js @@ -37,5 +37,5 @@ for ( i = 0; i < 100; i++ ) { v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); rss = accumulator( v1, v2 ); - console.log( '%s\t%s\t%s', ((v1 === v1) ? 'NaN' : v1.toFixed(3)), ((v2 === v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && (rss === rss)) ? rss.toFixed(3) : 'null'); + console.log( '%s\t%s\t%s', ((Number.isNaN(v1) ? 'NaN' : v1.toFixed(3)), (Number.isNaN(v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && !Number.isNaN(rss)) ? rss.toFixed(3) : 'null')); } From 2a8dbcd2335784380707352c9143de08249bda9a Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Wed, 19 Mar 2025 21:10:04 +0530 Subject: [PATCH 11/12] lint --- lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js index 1c4b51a792ee..8a2b9d6e37d5 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/examples/index.js @@ -37,5 +37,5 @@ for ( i = 0; i < 100; i++ ) { v1 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); v2 = ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ); rss = accumulator( v1, v2 ); - console.log( '%s\t%s\t%s', ((Number.isNaN(v1) ? 'NaN' : v1.toFixed(3)), (Number.isNaN(v2) ? 'NaN' : v2.toFixed(3)), ((rss !== null) && !Number.isNaN(rss)) ? rss.toFixed(3) : 'null')); + console.log( '%s\t%s\t%s', ((Number.isNaN(v1)) ? 'NaN' : v1.toFixed(3)), ((Number.isNaN(v2)) ? 'NaN' : v2.toFixed(3)), (((rss !== null) && (!Number.isNaN(rss))) ? rss.toFixed(3) : 'null')); } From b09bb59479972901135ff0a597a700039d9459bd Mon Sep 17 00:00:00 2001 From: jalajk3004 Date: Thu, 20 Mar 2025 10:13:00 +0530 Subject: [PATCH 12/12] check final --- .../@stdlib/stats/incr/nanmrss/README.md | 2 +- .../img/equation_residual_sum_of_squares.svg | 52 +++++++++++++++++++ .../stats/incr/nanmrss/docs/types/index.d.ts | 4 -- .../@stdlib/stats/incr/nanmrss/lib/main.js | 5 +- 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmrss/docs/img/equation_residual_sum_of_squares.svg diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md index c35376d4ea83..ae88b0ef2f9f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/README.md @@ -53,7 +53,7 @@ var incrnanmrss = require( '@stdlib/stats/incr/nanmrss' ); #### incrnanmrss( window ) -Returns an accumulator `function` which incrementally computes a moving [residual sum of squares][residual-sum-of-squares]. The `window` parameter defines the number of values over which to compute the moving [residual sum of squares][residual-sum-of-squares]. +Returns an accumulator `function` which incrementally computes a moving [residual sum of squares][residual-sum-of-squares]. The `window` parameter defines the number of values over which to compute the moving [residual sum of squares][residual-sum-of-squares], ignoring `NaN` values. ```javascript var accumulator = incrnanmrss( 3 ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/img/equation_residual_sum_of_squares.svg b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/img/equation_residual_sum_of_squares.svg new file mode 100644 index 000000000000..3d39639ab430 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/img/equation_residual_sum_of_squares.svg @@ -0,0 +1,52 @@ + +upper R upper S upper S equals sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts left-parenthesis y Subscript i Baseline minus x Subscript i Baseline right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts index 260190bfc49e..26bfe8ce5f1b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/docs/types/index.d.ts @@ -23,10 +23,6 @@ /** * If provided arguments, returns an updated residual sum of squares; otherwise, returns the current residual sum of squares, ignoring `NaN` values. * -* ## 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 * @param y - value * @returns residual sum of squares diff --git a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js index 9a348edbf7b1..e747f79f06a2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmrss/lib/main.js @@ -76,10 +76,7 @@ function incrnanmrss( W ) { * @returns {(number|null)} residual sum of squares or null */ function accumulator( x, y ) { - if ( arguments.length === 0 ) { - return mrss(); - } - if ( isnan( x ) || isnan( y ) ) { + if ( arguments.length === 0 || isnan( x ) || isnan( y ) ) { return mrss(); } return mrss( ( ( isnan( x ) ) ? 0 : x), ( ( isnan( y ) ) ? 0 : y ) );