From 2fbc41227c9a00fa637d452683d8bed440bbe488 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 11:44:40 +0530 Subject: [PATCH 01/11] feat: add package setup --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanwmean/lib/index.js | 54 ++++++++ .../@stdlib/stats/incr/nanwmean/lib/main.js | 120 ++++++++++++++++++ .../@stdlib/stats/incr/nanwmean/package.json | 69 ++++++++++ 3 files changed, 243 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/package.json diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js new file mode 100644 index 000000000000..60b564920f27 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a weighted arithmetic mean incrementally, ignoring NaN parameters. +* +* @module @stdlib/stats/incr/nanwmean +* +* @example +* var incrnanwmean = require( '@stdlib/stats/incr/nanwmean' ); +* +* var accumulator = incrnanwmean(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0, 1.0 ); +* // returns 2.0 +* +* mu = accumulator( 2.0, 0.5 ); +* // returns 2.0 +* +* mu = accumulator( 3.0, 1.5 ); +* // returns 2.5 +* +* mu = accumulator(); +* // returns 2.5 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js new file mode 100644 index 000000000000..bb582a4d5022 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrwmean = require( '@stdlib/stats/incr/wmean' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a weighted arithmetic mean, ignoring `NaN` parameters. +* +* ## Method +* +* - The weighted arithmetic mean is defined as +* +* ```tex +* \mu = \frac{\sum_{i=0}^{n-1} w_i x_i}{\sum_{i=0}^{n-1} w_i} +* ``` +* +* where \\( w_i \\) are the weights. +* +* - The weighted arithmetic mean is equivalent to the simple arithmetic mean when all weights are equal. +* +* ```tex +* \begin{align*} +* \mu &= \frac{\sum_{i=0}^{n-1} w x_i}{\sum_{i=0}^{n-1} w} \\ +* &= \frac{w\sum_{i=0}^{n-1} x_i}{nw} \\ +* &= \frac{1}{n} \sum_{i=0}^{n-1} +* \end{align*} +* ``` +* +* - If the weights are different, then one can view weights either as sample frequencies or as a means to calculate probabilities where \\( p_i = w_i / \sum w_i \\). +* +* - To derive an incremental formula for computing a weighted arithmetic mean, let +* +* ```tex +* W_n = \sum_{i=1}^{n} w_i +* ``` +* +* - Accordingly, +* +* ```tex +* \begin{align*} +* \mu_n &= \frac{1}{W_n} \sum_{i=1}^{n} w_i x_i \\ +* &= \frac{1}{W_n} \biggl(w_n x_n + \sum_{i=1}^{n-1} w_i x_i \biggr) \\ +* &= \frac{1}{W_n} (w_n x_n + W_{n-1} \mu_{n-1}) \\ +* &= \frac{1}{W_n} (w_n x_n + (W_n - w_n) \mu_{n-1}) \\ +* &= \frac{1}{W_n} (W_n \mu_{n-1} + w_n x_n - w_n\mu_{n-1}) \\ +* &= \mu_{n-1} + \frac{w_n}{W_n} (x_n - \mu_{n-1}) +* \end{align*} +* ``` +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanwmean(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0, 1.0 ); +* // returns 2.0 +* +* mu = accumulator( 2.0, 0.5 ); +* // returns 2.0 +* +* mu = accumulator( 3.0, 1.5 ); +* // returns 2.5 +* +* mu = accumulator(); +* // returns 2.5 +*/ +function incrnanwmean() { + var acc = incrwmean(); + + return accumulator; + + /** + * If provided arguments, the accumulator function returns an updated weighted mean. If not provided arguments, the accumulator function returns the current weighted mean. + * + * @private + * @param {number} [x] - value + * @param {number} [w] - weight + * @returns {(number|null)} weighted mean or null + */ + function accumulator( x, w ) { + if ( arguments.length === 0 ) { + return acc(); + } + if ( isnan( x ) || isnan( w ) ) { + return acc(); + } + return acc( x, w ); + } +} + + +// EXPORTS // + +module.exports = incrnanwmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/package.json b/lib/node_modules/@stdlib/stats/incr/nanwmean/package.json new file mode 100644 index 000000000000..7826d734f5f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/incr/nanwmean", + "version": "0.0.0", + "description": "Compute a weighted arithmetic mean 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", + "average", + "avg", + "mean", + "arithmetic mean", + "central tendency", + "incremental", + "accumulator", + "weighted", + "nan", + "ignore" + ] +} From 51c04690bf4eaeecfcc7c29767a79555c6313754 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 11:48:57 +0530 Subject: [PATCH 02/11] feat: add benchmark.js --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../incr/nanwmean/benchmark/benchmark.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js new file mode 100644 index 000000000000..e50f87db610b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var incrnanwmean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanwmean(); + 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( format( '%s::accumulator', pkg ), function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanwmean(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu(), 1.0 ); + 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(); +}); From eba692272f102b1bfa0d5a2a26f70b083981aaed Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 11:52:34 +0530 Subject: [PATCH 03/11] feat: add type decleration --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanwmean/docs/types/index.d.ts | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts new file mode 100644 index 000000000000..3cf9249c18c0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided both arguments, returns an updated weighted arithmetic mean; otherwise, returns the current weighted arithmetic mean. +* +* ## 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 w - weight +* @returns weighted arithmetic mean +*/ +type accumulator = ( x?: number, w?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a weighted arithmetic mean. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanwmean(); +* +* var mu = accumulator(); +* // returns null +* +* mu = accumulator( 2.0, 1.0 ); +* // returns 2.0 +* +* mu = accumulator( 2.0, 0.5 ); +* // returns 2.0 +* +* mu = accumulator( 3.0, 1.5 ); +* // returns 2.5 +* +* mu = accumulator(); +* // returns 2.5 +*/ +declare function incrnanwmean(): accumulator; + + +// EXPORTS // + +export = incrnanwmean; From d094f83812aa14204cd5b8a8dd16505703c460be Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 13:19:57 +0530 Subject: [PATCH 04/11] feat: add /docs/types/test.ts --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/incr/nanwmean/docs/types/test.ts | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts new file mode 100644 index 000000000000..a6d405af525f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrwmean = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrwmean(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrwmean( '5' ); // $ExpectError + incrwmean( 5 ); // $ExpectError + incrwmean( true ); // $ExpectError + incrwmean( false ); // $ExpectError + incrwmean( null ); // $ExpectError + incrwmean( undefined ); // $ExpectError + incrwmean( [] ); // $ExpectError + incrwmean( {} ); // $ExpectError + incrwmean( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrwmean(); + + acc(); // $ExpectType number | null + acc( 3.14, 1.0 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrwmean(); + + 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 +} + From 2523ca330413203dde421e464f47195be2c1b199 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 13:23:22 +0530 Subject: [PATCH 05/11] feat: add /examples/index.js --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanwmean/examples/index.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js new file mode 100644 index 000000000000..6707465164d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanwmean = require( './../lib' ); + +var accumulator; +var mu; +var x; +var w; +var i; + +// Initialize an accumulator: +accumulator = incrnanwmean(); + +// For each simulated datum, update the weighted mean... +console.log( '\nValue\tWeight\tWeighted Mean\n' ); +for ( i = 0; i < 100; i++ ) { + x = randu() * 100.0; + w = randu() * 100.0; + mu = accumulator( x, w ); + console.log( '%d\t%d\t%d', x.toFixed( 4 ), w.toFixed( 4 ), mu.toFixed( 4 ) ); +} +console.log( '\nFinal weighted mean: %d\n', accumulator() ); From 46965a0d4c91cd8387ebfb938832858533b73397 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 13:26:12 +0530 Subject: [PATCH 06/11] feat: add repl.txt --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanwmean/docs/repl.txt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/docs/repl.txt diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/repl.txt new file mode 100644 index 000000000000..9bd20c5c64ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/repl.txt @@ -0,0 +1,37 @@ +{{alias}}() + Returns an accumulator function which incrementally computes a weighted + arithmetic mean, ignoring `NaN` values. + + If provided arguments, the accumulator function returns an updated weighted + mean. If not provided arguments, the accumulator function returns the + current weighted mean. + + If a value is `NaN`, the accumulator function ignores the value and + maintains the current state. + + The accumulator function accepts two arguments: + + - x: value. + - w: weight. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var mu = accumulator() + null + > mu = accumulator( 2.0, 1.0 ) + 2.0 + > mu = accumulator( NaN, 1.0 ) + 2.0 + > mu = accumulator( 3.0, 1.0 ) + 2.5 + > mu = accumulator() + 2.5 + + See Also + -------- From 5d4e04c17e1b49662f391ca145f099a05e81aef1 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 22 Jul 2026 13:50:54 +0530 Subject: [PATCH 07/11] feat: add /test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: missing_dependencies - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../nanwmean/test/fixtures/python/data.json | 1 + .../nanwmean/test/fixtures/python/runner.py | 88 +++++++++++++ .../@stdlib/stats/incr/nanwmean/test/test.js | 120 ++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/data.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/runner.py create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/data.json b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/data.json new file mode 100644 index 000000000000..9a1cc4fb45a4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/data.json @@ -0,0 +1 @@ +[{"step": 1, "x": 3.0471707975443136, "w": 3.9559294497604784, "mean": 3.0471707975443136}, {"step": 2, "x": -10.399841062404956, "w": 3.3577691973009576, "mean": -3.126444550583255}, {"step": 3, "x": 7.5045119580645725, "w": 3.555310355269042, "mean": 0.3509975744077484}, {"step": 4, "x": 9.405647163912139, "w": 3.925572252007643, "mean": 2.753544869877046}, {"step": 5, "x": -19.510351886538363, "w": 2.348687300137866, "mean": -0.2966862687887889}, {"step": 6, "x": -13.021795068623181, "w": 2.88683186016918, "mean": -2.1306885327326004}, {"step": 7, "x": 1.2784040316728538, "w": 0.7850052908255215, "mean": -2.0021205716643617}, {"step": 8, "x": -3.162425923435822, "w": 0.6611973603262699, "mean": -2.0378432392675006}, {"step": 9, "x": -0.16801157504288794, "w": 3.3751745127733113, "mean": -1.7838942273298977}, {"step": 10, "x": -8.5304392757358, "w": 2.4083714101013496, "mean": -2.379942511320534}, {"step": 11, "x": 8.793979748628285, "w": 2.8696569217578256, "mean": -1.3156926211374218}, {"step": 12, "x": 7.777919354289483, "w": 3.8484944013385256, "mean": -0.28571103145409305}, {"step": 13, "x": 0.6603069756121605, "w": 3.2101197680028952, "mean": -0.2040497079223875}, {"step": 14, "x": 11.272412069680328, "w": 2.81253906322418, "mean": 0.6028869213396181}, {"step": 15, "x": 4.675093422520456, "w": 2.8401150876525265, "mean": 0.872852516773853}, {"step": 16, "x": -8.592924628832382, "w": 1.5893554805068, "mean": 0.5342425491363226}, {"step": 17, "x": 3.6875078408249884, "w": 0.2510073893829031, "mean": 0.5519568003899903}, {"step": 18, "x": -9.588826008289988, "w": 2.239915207238576, "mean": 0.0678565402877354}, {"step": 19, "x": 8.784503013072726, "w": 1.1514648968156933, "mean": 0.2766434525404932}, {"step": 20, "x": -0.49925910986252897, "w": 2.1017903542507175, "mean": 0.2441410703285499}, {"step": 21, "x": -1.8486236354526056, "w": 4.281675059014014, "mean": 0.07959462355871812}, {"step": 22, "x": -6.809295444039414, "w": 1.2463034807401698, "mean": -0.07453994202242903}, {"step": 23, "x": 12.225413386740303, "w": 0.3856834342764235, "mean": 0.010039483490497911}, {"step": 24, "x": -1.5452948206880215, "w": 1.4787810709077833, "mean": -0.029914116527385744}, {"step": 25, "x": -4.283278221631072, "w": 1.5386094130567498, "mean": -0.14063615675192645}, {"step": 26, "x": -3.5213355048822956, "w": 3.343390922161786, "mean": -0.32163256326353584}, {"step": 27, "x": 5.323091855533487, "w": 2.829457546472264, "mean": -0.07696426621497057}, {"step": 28, "x": 3.6544406436407835, "w": 3.9411012246214265, "mean": 0.13548865366219276}, {"step": 29, "x": 4.1273261159598835, "w": 3.355136347604199, "mean": 0.3200323834598058}, {"step": 30, "x": 4.308210030078827, "w": 2.0912956210563456, "mean": 0.4317363357791127}, {"step": 31, "x": 21.416476008704613, "w": 4.08869988486357, "mean": 1.5212025421425204}, {"step": 32, "x": -4.064150163846156, "w": 0.9181673075477492, "mean": 1.4568355240616275}, {"step": 33, "x": -5.122427290715374, "w": 0.21128915835591636, "mean": 1.4394336829268486}, {"step": 34, "x": -8.137727282478778, "w": 0.5412345178006446, "mean": 1.3749825600895866}, {"step": 35, "x": 6.159794225754957, "w": 3.639560817922607, "mean": 1.582139838161509}, {"step": 36, "x": 11.289722927208917, "w": 2.3631984282317986, "mean": 1.8475743480392357}, {"step": 37, "x": -1.1394745765487508, "w": 0.8902317172646488, "mean": 1.8171205821224452}, {"step": 38, "x": -8.401564769625281, "w": 2.5551193980064815, "mean": 1.5266007308371616}, {"step": 39, "x": -8.244812156912396, "w": 0.8463293032945253, "mean": 1.435442529141028}, {"step": 40, "x": 6.505927878247011, "w": 3.511969837880907, "mean": 1.6244173800465052}, {"step": 41, "x": 7.432541712034423, "w": 2.2861657503127506, "mean": 1.761991460740914}, {"step": 42, "x": 5.4315426830519495, "w": 1.9670040078727644, "mean": 1.8352822469844088}, {"step": 43, "x": -6.655097072886943, "w": 1.577409236824595, "mean": 1.7014373651904717}, {"step": 44, "x": 2.3216132306671975, "w": 3.188384706282554, "mean": 1.7205884505077298}, {"step": 45, "x": 1.1668580914072821, "w": 1.8728817917116134, "mean": 1.7107231718926006}, {"step": 46, "x": 2.1868859672901295, "w": 0.5294846046488949, "mean": 1.7131094853391238}, {"step": 47, "x": 8.714287779481898, "w": 0.6782289203905251, "mean": 1.7577662372038756}, {"step": 48, "x": 2.2359554877468226, "w": 4.813298556292621, "mean": 1.7784750415795718}, {"step": 49, "x": 6.789135630718949, "w": 4.552045384467275, "mean": 1.9756181293054198}, {"step": 50, "x": 0.6757906948889146, "w": 3.5285649556726733, "mean": 1.9371486375865798}] diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/runner.py b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/runner.py new file mode 100644 index 000000000000..2540b53c5af5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/fixtures/python/runner.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# 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. + +"""Generate fixtures.""" + +import os +import json +import numpy as np + +# Get the file path: +FILE = os.path.realpath(__file__) + +# Extract the directory in which this file resides: +DIR = os.path.dirname(FILE) + + +def gen(n, seed, name): + """Generate fixture data and write to file. + + # Arguments + + * `n`: number of samples + * `seed`: random number generator seed + * `name::str`: output filename + + # Examples + + ``` python + python> gen(50, 42, './data.json') + ``` + """ + # Initialize random number generator for reproducibility: + rng = np.random.default_rng(seed) + + # Generate data: + x = rng.normal(loc=0.0, scale=10.0, size=n) + w = rng.uniform(0.1, 5.0, size=n) + + # Store data to be written to file as a list of records: + records = [] + + for k in range(1, n + 1): + x_vals = x[:k] + w_vals = w[:k] + + weighted_mean = np.average(x_vals, weights=w_vals) + + records.append({ + "step": k, + "x": float(x[k - 1]), + "w": float(w[k - 1]), + "mean": float(weighted_mean) + }) + + # Based on the script directory, create an output filepath: + filepath = os.path.join(DIR, name) + + # Write the data to the output filepath as JSON: + with open(filepath, "w", encoding="utf-8") as outfile: + json.dump(records, outfile) + + # Include trailing newline: + with open(filepath, "a", encoding="utf-8") as outfile: + outfile.write("\n") + + +def main(): + """Generate fixture data.""" + gen(50, 42, "data.json") + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js new file mode 100644 index 000000000000..97affe57155c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js @@ -0,0 +1,120 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var incrnanwmean = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/python/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanwmean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanwmean(), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanwmean(); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a weighted arithmetic mean', function test( t ) { + var expected; + var actual; + var acc; + var N; + var x; + var w; + var i; + + N = data.length; + + acc = incrnanwmean(); + + for ( i = 0; i < N; i++ ) { + x = data[ i ].x; + w = data[ i ].w; + expected = data[ i ].mean; + actual = acc( x, w ); + t.strictEqual( isAlmostSameValue( actual, expected, 150.0 ), true, 'within tolerance. x: ' + x + '. w: ' + w + '. Value: ' + actual + '. Expected: ' + expected + '.' ); + } + t.end(); +}); + +tape( 'if not provided arguments, the accumulator function returns the current weighted mean', function test( t ) { + var acc; + var N; + var i; + + N = data.length; + acc = incrnanwmean(); + for ( i = 0; i < N; i++ ) { + acc( data[ i ].x, data[ i ].w ); + } + t.strictEqual( isAlmostSameValue( acc(), data[ N - 1 ].mean, 150.0 ), true, 'returns the current accumulated mean' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a weighted arithmetic mean, ignoring NaN values', function test( t ) { + var acc = incrnanwmean(); + + t.strictEqual( acc( 2.0, 1.0 ), 2.0, 'returns 2.0' ); + t.strictEqual( acc( NaN, 1.0 ), 2.0, 'ignores NaN, returns 2.0' ); + t.strictEqual( acc( 3.0, 1.0 ), 2.5, 'returns 2.5' ); + t.strictEqual( acc(), 2.5, 'returns 2.5' ); + t.end(); +}); + +tape( 'if not provided a weight, the accumulator function returns `NaN`', function test( t ) { + var acc = incrnanwmean(); + t.strictEqual( isnan( acc( 2.0 ) ), true, 'returns expected value' ); + t.strictEqual( isnan( acc( 3.14 ) ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for either a value or a weight, the accumulator function returns `NaN`', function test( t ) { + var acc = incrnanwmean(); + t.strictEqual( acc( 2.0, NaN ), null, 'returns expected value' ); + t.strictEqual( acc( 3.14, NaN ), null, 'returns expected value' ); + + acc = incrnanwmean(); + t.strictEqual( acc( NaN, 1.0 ), null, 'returns expected value' ); + t.strictEqual( acc( NaN, 1.0 ), null, 'returns expected value' ); + + acc = incrnanwmean(); + t.strictEqual( acc( NaN, NaN ), null, 'returns expected value' ); + t.strictEqual( acc( NaN, NaN ), null, 'returns expected value' ); + t.end(); +}); From 16b52d2ad9620cc695e14c6e0826cc9b6d8e6f11 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:44:25 +0000 Subject: [PATCH 08/11] chore: update copyright years --- .../@stdlib/stats/incr/nanwmean/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanwmean/docs/types/index.d.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js index e50f87db610b..decb24624bbc 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts index 3cf9249c18c0..7d2319a96aa0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts index a6d405af525f..dae0781125ee 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js index 6707465164d2..38c24ffffb39 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js index 60b564920f27..32dfbd250786 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js index bb582a4d5022..f37417640620 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js index 97affe57155c..e5e330d22f39 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From c884131f8339c4dc01256d4a2fe3af7129c2a900 Mon Sep 17 00:00:00 2001 From: Arjan Date: Thu, 23 Jul 2026 18:35:15 +0530 Subject: [PATCH 09/11] fix: apply suggested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/incr/nanwmean/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanwmean/lib/main.js | 47 ++----------------- 2 files changed, 4 insertions(+), 45 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts index 7d2319a96aa0..4dc4ac1c2f56 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/docs/types/index.d.ts @@ -25,7 +25,7 @@ * * ## Notes * -* - If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for all future invocations. +* - If provided `NaN` values, accumulator returns current weighted arithmetic mean ignoring `NaN` value. * * @param x - value * @param w - weight diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js index f37417640620..e4d0b537f5b7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/lib/main.js @@ -27,48 +27,7 @@ var incrwmean = require( '@stdlib/stats/incr/wmean' ); // MAIN // /** -* Returns an accumulator function which incrementally computes a weighted arithmetic mean, ignoring `NaN` parameters. -* -* ## Method -* -* - The weighted arithmetic mean is defined as -* -* ```tex -* \mu = \frac{\sum_{i=0}^{n-1} w_i x_i}{\sum_{i=0}^{n-1} w_i} -* ``` -* -* where \\( w_i \\) are the weights. -* -* - The weighted arithmetic mean is equivalent to the simple arithmetic mean when all weights are equal. -* -* ```tex -* \begin{align*} -* \mu &= \frac{\sum_{i=0}^{n-1} w x_i}{\sum_{i=0}^{n-1} w} \\ -* &= \frac{w\sum_{i=0}^{n-1} x_i}{nw} \\ -* &= \frac{1}{n} \sum_{i=0}^{n-1} -* \end{align*} -* ``` -* -* - If the weights are different, then one can view weights either as sample frequencies or as a means to calculate probabilities where \\( p_i = w_i / \sum w_i \\). -* -* - To derive an incremental formula for computing a weighted arithmetic mean, let -* -* ```tex -* W_n = \sum_{i=1}^{n} w_i -* ``` -* -* - Accordingly, -* -* ```tex -* \begin{align*} -* \mu_n &= \frac{1}{W_n} \sum_{i=1}^{n} w_i x_i \\ -* &= \frac{1}{W_n} \biggl(w_n x_n + \sum_{i=1}^{n-1} w_i x_i \biggr) \\ -* &= \frac{1}{W_n} (w_n x_n + W_{n-1} \mu_{n-1}) \\ -* &= \frac{1}{W_n} (w_n x_n + (W_n - w_n) \mu_{n-1}) \\ -* &= \frac{1}{W_n} (W_n \mu_{n-1} + w_n x_n - w_n\mu_{n-1}) \\ -* &= \mu_{n-1} + \frac{w_n}{W_n} (x_n - \mu_{n-1}) -* \end{align*} -* ``` +* Returns an accumulator function which incrementally computes a weighted arithmetic mean, ignoring `NaN` values. * * @returns {Function} accumulator function * @@ -96,7 +55,7 @@ function incrnanwmean() { return accumulator; /** - * If provided arguments, the accumulator function returns an updated weighted mean. If not provided arguments, the accumulator function returns the current weighted mean. + * If provided arguments, the accumulator function returns an updated weighted mean. If not provided arguments or provided `NaN` values, the accumulator function returns the current weighted mean. * * @private * @param {number} [x] - value @@ -107,7 +66,7 @@ function incrnanwmean() { if ( arguments.length === 0 ) { return acc(); } - if ( isnan( x ) || isnan( w ) ) { + if ( arguments.length < 2 || isnan( x ) || isnan( w ) ) { return acc(); } return acc( x, w ); From 5390d0593687544d34e5efed3ecdc0d70f8b7dfd Mon Sep 17 00:00:00 2001 From: Arjan Date: Thu, 23 Jul 2026 18:57:45 +0530 Subject: [PATCH 10/11] docs: add README.md --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanwmean/README.md | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanwmean/README.md diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanwmean/README.md new file mode 100644 index 000000000000..544f0633f63b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/README.md @@ -0,0 +1,145 @@ + + +# incrnanwmean + +> Compute a [weighted arithmetic mean][weighted-arithmetic-mean] incrementally, ignoring `NaN` values. + +
+ +The [weighted arithmetic mean][weighted-arithmetic-mean] is defined as + + + +```math +\bar{x} = \frac{\displaystyle\sum_{i=0}^{n-1} w_{i} x_{i}}{\displaystyle\sum_{i=0}^{n-1} w_{i}} +``` + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanwmean = require( '@stdlib/stats/incr/nanwmean' ); +``` + +#### incrnanwmean() + +Returns an accumulator `function` which incrementally computes a [weighted arithmetic mean][weighted-arithmetic-mean], ignoring `NaN` values. + +```javascript +var accumulator = incrnanwmean(); +``` + +#### accumulator( \[x, w] ) + +If provided an input value `x` and a weight `w`, the accumulator function returns an updated weighted mean. If not provided any input values or provided `NaN` values, the accumulator function returns the current mean. + +```javascript +var accumulator = incrnanwmean(); + +var mu = accumulator( 2.0, 1.0 ); +// returns 2.0 + +mu = accumulator( 2.0, 0.5 ); +// returns 2.0 + +mu = accumulator( NaN, 1.0 ); +// returns 2.0 + +mu = accumulator( 3.0, 1.5 ); +// returns 2.5 + +mu = accumulator(); +// returns 2.5 +``` + +
+ + + +
+ +## 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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanwmean = require( '@stdlib/stats/incr/nanwmean' ); + +var accumulator; +var v; +var w; +var i; + +// Initialize an accumulator: +accumulator = incrnanwmean(); + +// For each simulated datum, update the weighted mean... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + w = randu() * 100.0; + accumulator( v, w ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + From ace6315953a50c42b5f83ad18f32801ff0066133 Mon Sep 17 00:00:00 2001 From: Arjan Date: Fri, 24 Jul 2026 10:39:56 +0530 Subject: [PATCH 11/11] fix: missing weight test, `NaN` args test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanwmean/test/test.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js index e5e330d22f39..5f2cf6b9b175 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanwmean/test/test.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var incrnanwmean = require( './../lib' ); @@ -97,14 +96,14 @@ tape( 'the accumulator function incrementally computes a weighted arithmetic mea t.end(); }); -tape( 'if not provided a weight, the accumulator function returns `NaN`', function test( t ) { +tape( 'if not provided a weight, the accumulator function returns currently accumulated weighted mean', function test( t ) { var acc = incrnanwmean(); - t.strictEqual( isnan( acc( 2.0 ) ), true, 'returns expected value' ); - t.strictEqual( isnan( acc( 3.14 ) ), true, 'returns expected value' ); + t.strictEqual( acc( 2.0 ), null, 'returns expected value, the initial accumulated value `null`' ); + t.strictEqual( acc( 3.14 ), null, 'returns expected value, the initial accumulated value `null`' ); t.end(); }); -tape( 'if provided `NaN` for either a value or a weight, the accumulator function returns `NaN`', function test( t ) { +tape( 'if provided `NaN` for either a value or a weight, the accumulator function returns currently accumulated weighted mean', function test( t ) { var acc = incrnanwmean(); t.strictEqual( acc( 2.0, NaN ), null, 'returns expected value' ); t.strictEqual( acc( 3.14, NaN ), null, 'returns expected value' );