From c0c58677461038bfc03c8fed3382ba2400e8729f Mon Sep 17 00:00:00 2001 From: hans Date: Thu, 20 Mar 2025 22:45:04 -0400 Subject: [PATCH 1/5] feat(stats): add nanmgmean package --- 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 status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanmgmean/README.md | 174 ++++++++++++++++++ .../incr/nanmgmean/benchmark/benchmark.js | 69 +++++++ .../docs/img/equation_geometric_mean.svg | 68 +++++++ .../stats/incr/nanmgmean/docs/repl.txt | 43 +++++ .../incr/nanmgmean/docs/types/index.d.ts | 74 ++++++++ .../stats/incr/nanmgmean/docs/types/test.ts | 66 +++++++ .../stats/incr/nanmgmean/examples/index.js | 42 +++++ .../@stdlib/stats/incr/nanmgmean/lib/index.js | 60 ++++++ .../@stdlib/stats/incr/nanmgmean/lib/main.js | 84 +++++++++ .../@stdlib/stats/incr/nanmgmean/package.json | 75 ++++++++ .../@stdlib/stats/incr/nanmgmean/test/test.js | 140 ++++++++++++++ 11 files changed, 895 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/img/equation_geometric_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md new file mode 100644 index 000000000000..0b6a17023944 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md @@ -0,0 +1,174 @@ + + +# incrnanmgmean + +> Compute a moving [geometric mean][geometric-mean] incrementally, ignoring `NaN` value . + +
+ +The [geometric mean][geometric-mean] is defined as the nth root of a product of _n_ numbers. + + + +```math +\biggl( \prod_{i=0}^{n-1} \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}} +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmgmean = require( '@stdlib/stats/incr/nanmgmean' ); +``` + +#### incrnanmgmean( window ) + +Returns an accumulator `function` which incrementally computes a moving [geometric mean][geometric-mean]. The `window` parameter defines the number of values over which to compute the moving [geometric mean][geometric-mean]. + +```javascript +var accumulator = incrnanmgmean( 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated [geometric mean][geometric-mean]. If not provided an input value `x`, the accumulator function returns the current [geometric-mean][geometric-mean]. + +```javascript +var accumulator = incrnanmgmean( 3 ); + +var v = accumulator(); +// returns null + +// Fill the window... +v = accumulator( 2.0 ); // [2.0] +// returns 2.0 + +v = accumulator( 1.0 ); // [2.0, 1.0] +// returns ~1.41 + +v = accumulator( 3.0 ); // [2.0, 1.0, 3.0] +// returns ~1.82 + +v = accumulator( NaN ); // [2.0, 1.0, 3.0] +// returns ~1.82 + +// Window begins sliding... +v = accumulator( 7.0 ); // [1.0, 3.0, 7.0] +// returns ~2.76 + +v = accumulator( 5.0 ); // [3.0, 7.0, 5.0] +// returns ~4.72 + +v = accumulator(); +// returns ~4.72 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If a NaN value is provided, the accumulator skips the update and continues to return the previous state. 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` 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. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmgmean = require( '@stdlib/stats/incr/nanmgmean' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmgmean( 5 ); + +// For each simulated datum, update the moving geometric mean... +for ( i = 0; i < 100; i++ ) { + v = randu() * 100.0; + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js new file mode 100644 index 000000000000..4cb57bca8d41 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/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 incrnanmgmean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmgmean( (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 = incrnanmgmean( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu() ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/img/equation_geometric_mean.svg b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/img/equation_geometric_mean.svg new file mode 100644 index 000000000000..09660f01bb97 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/img/equation_geometric_mean.svg @@ -0,0 +1,68 @@ + +left-parenthesis product Underscript i equals 0 Overscript n minus 1 Endscripts right-parenthesis Superscript StartFraction 1 Over n EndFraction Baseline equals RootIndex n StartRoot x 0 x 1 midline-horizontal-ellipsis x Subscript n minus 1 Baseline EndRoot + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt new file mode 100644 index 000000000000..074fa5005e80 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving + geometric mean, ignoring `NaN` value. + + The `W` parameter defines the number of values over which to compute the + moving geometric mean. + + If provided a value, the accumulator function returns an updated moving + geometric mean. If not provided a value, the accumulator function returns + the current moving geometric mean. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var v = accumulator() + null + > v = accumulator( 2.0 ) + 2.0 + > v = accumulator( 5.0 ) + ~3.16 + > v = accumulator( 3.0 ) + ~3.11 + > v = accumulator( NaN ) + ~3.11 + > v = accumulator( 5.0 ) + ~4.22 + > v = accumulator() + ~4.22 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts new file mode 100644 index 000000000000..dce368f6c021 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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 a value, returns an updated geometric mean; otherwise, returns the current geometric 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. +* - If provided a negative value, the accumulated value is `NaN` for all future invocations. +* +* @param x - value +* @returns geometric mean +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving geometric mean. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving geometric mean. +* - 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 = incrmgmean( 3 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator( 3.0 ); +* // returns ~3.11 +* +* v = accumulator( 5.0 ); +* // returns ~4.22 +* +* v = accumulator(); +* // returns ~4.22 +*/ +declare function incrmgmean( W: number ): accumulator; + + +// EXPORTS // + +export = incrmgmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts new file mode 100644 index 000000000000..fa30e0c3eea6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @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 incrmgmean = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrmgmean( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrmgmean( '5' ); // $ExpectError + incrmgmean( true ); // $ExpectError + incrmgmean( false ); // $ExpectError + incrmgmean( null ); // $ExpectError + incrmgmean( undefined ); // $ExpectError + incrmgmean( [] ); // $ExpectError + incrmgmean( {} ); // $ExpectError + incrmgmean( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + incrmgmean(); // $ExpectError + incrmgmean( 5, 3 ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrmgmean( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrmgmean( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js new file mode 100644 index 000000000000..5951d6282515 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmgmean = require( './../lib' ); + +var accumulator; +var m; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmgmean( 5 ); + +// For each simulated datum, update the moving geometric mean... +console.log( '\nValue\tGeometric Mean\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.1 ) { + v = NaN; + } else { + v = randu() * 100.0; + } + m = accumulator( v ); + console.log( '%d\t%d', v.toFixed( 4 ), m.toFixed( 4 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js new file mode 100644 index 000000000000..1edc278cc890 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a moving geometric mean incrementally, ignoring `NaN` value. +* +* @module @stdlib/stats/incr/nanmgmean +* +* @example +* var incrnanmgmean = require( '@stdlib/stats/incr/nanmgmean' ); +* +* var accumulator = incrnanmgmean( 3 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator( 3.0 ); +* // returns ~3.11 +* +* v = accumulator( NaN ); +* // returns ~3.11 +* +* v = accumulator( 5.0 ); +* // returns ~4.22 +* +* v = accumulator(); +* // returns ~4.22 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js new file mode 100644 index 000000000000..b04e48f89034 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js @@ -0,0 +1,84 @@ +/** +* @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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var incrmgmean = require( '@stdlib/stats/incr/mgmean' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` value. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmgmean( 3 ); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator( 3.0 ); +* // returns ~3.11 +* +* v = accumulator( NaN ); +* // returns ~3.11 +* +* v = accumulator( 5.0 ); +* // returns ~4.22 +* +* v = accumulator(); +* // returns ~4.22 +*/ +function incrnanmgmean( W ) { + var acc = incrmgmean( W ); + + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated geometric mean. If not provided a value, the accumulator function returns the current geometric mean. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} geometric mean or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) || !isNumber( x ) ) { + return acc(); + } + return acc( x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmgmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json new file mode 100644 index 000000000000..96965f3c3248 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/stats/incr/nanmgmean", + "version": "0.0.0", + "description": "Compute a moving geometric mean incrementally.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "geometric", + "mean", + "geometric mean", + "product", + "prod", + "central tendency", + "incremental", + "accumulator", + "moving mean", + "moving average", + "sliding window", + "sliding", + "window", + "moving" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js new file mode 100644 index 000000000000..35b6a4d57f21 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js @@ -0,0 +1,140 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var EPSILON = require( '@stdlib/constants/float64/eps' ); +var incrnanmgmean = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmgmean, '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() { + incrnanmgmean( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmgmean( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving geometric mean incrementally', function test( t ) { + var expected; + var actual; + var delta; + var data; + var tol; + var acc; + var N; + var i; + + data = [ 2.0, 3.0, NaN, 2.0, 4.0, 3.0, 4.0 ]; + N = data.length; + + acc = incrnanmgmean( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + // Note: computed by hand using textbook formula: + expected = [ + 2.0, + 2.449489742783178, + 2.449489742783178, + 2.2894284851066637, + 2.8844991406148166, + 2.8844991406148166, + 3.634241185664279 + ]; + + for ( i = 0; i < N; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.equal( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( expected[ i ] - actual[ i ] ); + tol = 1.2 * EPSILON * abs( expected[ i ] ); + t.equal( delta <= tol, true, 'within tolerance. Expected: '+expected[ i ]+'. Actual: '+actual[ i ]+'. Delta: '+delta+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current geometric mean', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ 2.0, NaN, 3.0, 5.0 ]; + acc = incrnanmgmean( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + actual = acc(); + expected = 3.872983346207417; // Note: computed by hand using textbook formula + delta = abs( expected - actual ); + tol = 1.0 * EPSILON * abs( expected ); + t.equal( delta <= tol, true, 'within tolerance. Expected: '+expected+'. Actual: '+actual+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmgmean( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); From 9455568fc27753c67e3d7b56490a8424ee9a0c2f Mon Sep 17 00:00:00 2001 From: hans Date: Thu, 20 Mar 2025 22:56:43 -0400 Subject: [PATCH 2/5] fix(readme): udpate example --- 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 status: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md | 6 +++++- lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md index 0b6a17023944..b3dc1f305cb4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md @@ -127,7 +127,11 @@ accumulator = incrnanmgmean( 5 ); // For each simulated datum, update the moving geometric mean... for ( i = 0; i < 100; i++ ) { - v = randu() * 100.0; + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = randu() * 100.0; + } accumulator( v ); } console.log( accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js index b04e48f89034..0f98c6b7d863 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js @@ -60,7 +60,6 @@ var incrmgmean = require( '@stdlib/stats/incr/mgmean' ); */ function incrnanmgmean( W ) { var acc = incrmgmean( W ); - return accumulator; /** From 0e47274ec4c26b12b1bed07dd1cbe18d95bb24f5 Mon Sep 17 00:00:00 2001 From: hans Date: Sat, 22 Mar 2025 10:55:22 -0400 Subject: [PATCH 3/5] fix(types): update careless mistakes --- 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 status: na - task: lint_package_json status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../incr/nanmgmean/benchmark/benchmark.js | 2 +- .../incr/nanmgmean/docs/types/index.d.ts | 18 +++++------ .../stats/incr/nanmgmean/docs/types/test.ts | 30 +++++++++---------- .../@stdlib/stats/incr/nanmgmean/package.json | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js index 4cb57bca8d41..6e5817a518af 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js @@ -33,7 +33,7 @@ bench( pkg, function benchmark( b ) { var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - f = incrnanmgmean( (i%5)+1 ); + f = incrnanmgmean( ( i%5 )+1 ); if ( typeof f !== 'function' ) { b.fail( 'should return a function' ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts index dce368f6c021..6e07bc6241a9 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,13 @@ /** * If provided a value, returns an updated geometric mean; otherwise, returns the current geometric 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. -* - If provided a negative value, the accumulated value is `NaN` for all future invocations. -* * @param x - value * @returns geometric mean */ type accumulator = ( x?: number ) => number | null; /** -* Returns an accumulator function which incrementally computes a moving geometric mean. +* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` value. * * ## Notes * @@ -46,7 +41,7 @@ type accumulator = ( x?: number ) => number | null; * @returns accumulator function * * @example -* var accumulator = incrmgmean( 3 ); +* var accumulator = incrnanmgmean( 3 ); * * var v = accumulator(); * // returns null @@ -60,15 +55,18 @@ type accumulator = ( x?: number ) => number | null; * v = accumulator( 3.0 ); * // returns ~3.11 * +* v = accumulator( NaN ); +* // returns ~3.11 +* * v = accumulator( 5.0 ); * // returns ~4.22 * * v = accumulator(); * // returns ~4.22 */ -declare function incrmgmean( W: number ): accumulator; +declare function incrnanmgmean( W: number ): accumulator; // EXPORTS // -export = incrmgmean; +export = incrnanmgmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts index fa30e0c3eea6..8899f0f49192 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,37 +16,37 @@ * limitations under the License. */ -import incrmgmean = require( './index' ); +import incrnanmgmean = require( './index' ); // TESTS // // The function returns an accumulator function... { - incrmgmean( 3 ); // $ExpectType accumulator + incrnanmgmean( 3 ); // $ExpectType accumulator } // The compiler throws an error if the function is provided an argument that is not a number... { - incrmgmean( '5' ); // $ExpectError - incrmgmean( true ); // $ExpectError - incrmgmean( false ); // $ExpectError - incrmgmean( null ); // $ExpectError - incrmgmean( undefined ); // $ExpectError - incrmgmean( [] ); // $ExpectError - incrmgmean( {} ); // $ExpectError - incrmgmean( ( x: number ): number => x ); // $ExpectError + incrnanmgmean( '5' ); // $ExpectError + incrnanmgmean( true ); // $ExpectError + incrnanmgmean( false ); // $ExpectError + incrnanmgmean( null ); // $ExpectError + incrnanmgmean( undefined ); // $ExpectError + incrnanmgmean( [] ); // $ExpectError + incrnanmgmean( {} ); // $ExpectError + incrnanmgmean( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an invalid number of arguments... { - incrmgmean(); // $ExpectError - incrmgmean( 5, 3 ); // $ExpectError + incrnanmgmean(); // $ExpectError + incrnanmgmean( 5, 3 ); // $ExpectError } // The function returns an accumulator function which returns an accumulated result... { - const acc = incrmgmean( 3 ); + const acc = incrnanmgmean( 3 ); acc(); // $ExpectType number | null acc( 3.14 ); // $ExpectType number | null @@ -54,7 +54,7 @@ import incrmgmean = require( './index' ); // The compiler throws an error if the returned accumulator function is provided invalid arguments... { - const acc = incrmgmean( 3 ); + const acc = incrnanmgmean( 3 ); acc( '5' ); // $ExpectError acc( true ); // $ExpectError diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json index 96965f3c3248..20785c0c5066 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nanmgmean", "version": "0.0.0", - "description": "Compute a moving geometric mean incrementally.", + "description": "Compute a moving geometric mean incrementally, ignoring `NaN` value.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From 252f215ea559cf0f3de972c43af638a9a8070c8a Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 11 Jul 2026 23:07:18 -0500 Subject: [PATCH 4/5] chore: update copyright years --- lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md | 2 +- .../@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts | 2 +- .../@stdlib/stats/incr/nanmgmean/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md index b3dc1f305cb4..991876fe2329 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2026 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js index 6e5817a518af..70eb9a37bca2 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts index 6e07bc6241a9..0f768179e9bd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts index 8899f0f49192..73ab0a9ddd0b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js index 5951d6282515..acf745275015 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js index 1edc278cc890..b855ae40fe0b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js index 0f98c6b7d863..15ca46cdd8a4 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js index 35b6a4d57f21..b963cf96b463 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 7432c1493e2f3562a9e5a4b3dcf3607a7f9ea312 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 11 Jul 2026 23:22:36 -0500 Subject: [PATCH 5/5] fix: address additional review feedback --- .../@stdlib/stats/incr/nanmgmean/README.md | 22 ++----------------- .../incr/nanmgmean/benchmark/benchmark.js | 3 ++- .../stats/incr/nanmgmean/docs/repl.txt | 2 +- .../incr/nanmgmean/docs/types/index.d.ts | 2 +- .../stats/incr/nanmgmean/examples/index.js | 2 +- .../@stdlib/stats/incr/nanmgmean/lib/index.js | 2 +- .../@stdlib/stats/incr/nanmgmean/lib/main.js | 5 ++--- .../@stdlib/stats/incr/nanmgmean/package.json | 2 +- 8 files changed, 11 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md index 991876fe2329..d2cf0fb5082e 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/README.md @@ -20,7 +20,7 @@ limitations under the License. # incrnanmgmean -> Compute a moving [geometric mean][geometric-mean] incrementally, ignoring `NaN` value . +> Compute a moving [geometric mean][geometric-mean] incrementally, ignoring `NaN` values.
@@ -61,7 +61,7 @@ var accumulator = incrnanmgmean( 3 ); #### accumulator( \[x] ) -If provided an input value `x`, the accumulator function returns an updated [geometric mean][geometric-mean]. If not provided an input value `x`, the accumulator function returns the current [geometric-mean][geometric-mean]. +If provided an input value `x`, the accumulator function returns an updated [geometric mean][geometric-mean]. If not provided an input value `x`, the accumulator function returns the current [geometric mean][geometric-mean]. ```javascript var accumulator = incrnanmgmean( 3 ); @@ -145,14 +145,6 @@ console.log( accumulator() ); @@ -163,16 +155,6 @@ console.log( accumulator() ); [geometric-mean]: https://en.wikipedia.org/wiki/Geometric_mean - - -[@stdlib/stats/incr/gmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/gmean - -[@stdlib/stats/incr/mhmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mhmean - -[@stdlib/stats/incr/mmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mmean - - -
diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js index 70eb9a37bca2..c82d4bae372b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/benchmark/benchmark.js @@ -22,6 +22,7 @@ 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 incrnanmgmean = require( './../lib' ); @@ -46,7 +47,7 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::accumulator', function benchmark( b ) { +bench( format( '%s::accumulator', pkg ), function benchmark( b ) { var acc; var v; var i; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt index 074fa5005e80..0af26f0e67d7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( W ) Returns an accumulator function which incrementally computes a moving - geometric mean, ignoring `NaN` value. + geometric mean, ignoring `NaN` values. The `W` parameter defines the number of values over which to compute the moving geometric mean. diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts index 0f768179e9bd..e6f431263b86 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/docs/types/index.d.ts @@ -29,7 +29,7 @@ type accumulator = ( x?: number ) => number | null; /** -* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` value. +* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` values. * * ## Notes * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js index acf745275015..0c4da638571c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/examples/index.js @@ -38,5 +38,5 @@ for ( i = 0; i < 100; i++ ) { v = randu() * 100.0; } m = accumulator( v ); - console.log( '%d\t%d', v.toFixed( 4 ), m.toFixed( 4 ) ); + console.log( '%d\t%d', v.toFixed( 4 ), ( m === null ) ? NaN : m.toFixed( 4 ) ); } diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js index b855ae40fe0b..839b390602d8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute a moving geometric mean incrementally, ignoring `NaN` value. +* Compute a moving geometric mean incrementally, ignoring `NaN` values. * * @module @stdlib/stats/incr/nanmgmean * diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js index 15ca46cdd8a4..0dde34a96c07 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/lib/main.js @@ -20,7 +20,6 @@ // MODULES // -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isnan = require( '@stdlib/math/base/assert/is-nan' ); var incrmgmean = require( '@stdlib/stats/incr/mgmean' ); @@ -28,7 +27,7 @@ var incrmgmean = require( '@stdlib/stats/incr/mgmean' ); // MAIN // /** -* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` value. +* Returns an accumulator function which incrementally computes a moving geometric mean, ignoring `NaN` values. * * @param {PositiveInteger} W - window size * @throws {TypeError} must provide a positive integer @@ -70,7 +69,7 @@ function incrnanmgmean( W ) { * @returns {(number|null)} geometric mean or null */ function accumulator( x ) { - if ( arguments.length === 0 || isnan( x ) || !isNumber( x ) ) { + if ( arguments.length === 0 || isnan( x ) ) { return acc(); } return acc( x ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json index 20785c0c5066..fcda85da227c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanmgmean/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/incr/nanmgmean", "version": "0.0.0", - "description": "Compute a moving geometric mean incrementally, ignoring `NaN` value.", + "description": "Compute a moving geometric mean incrementally, ignoring NaN values.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors",