From 787645a8e07f6d094f8cbec1c12c22a210df0ae5 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 15:30:13 +0530 Subject: [PATCH 1/5] feat feat: add stats/incr/nangmean --- .../@stdlib/stats/incr/nangmean/README.md | 169 ++++++++++++++++++ .../incr/nangmean/benchmark/benchmark.js | 69 +++++++ .../docs/img/equation_geometric_mean.svg | 68 +++++++ .../@stdlib/stats/incr/nangmean/docs/repl.txt | 34 ++++ .../stats/incr/nangmean/docs/types/index.d.ts | 60 +++++++ .../stats/incr/nangmean/docs/types/test.ts | 61 +++++++ .../stats/incr/nangmean/examples/index.js | 43 +++++ .../@stdlib/stats/incr/nangmean/lib/index.js | 54 ++++++ .../@stdlib/stats/incr/nangmean/lib/main.js | 74 ++++++++ .../@stdlib/stats/incr/nangmean/package.json | 68 +++++++ .../@stdlib/stats/incr/nangmean/test/test.js | 150 ++++++++++++++++ 11 files changed, 850 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/docs/img/equation_geometric_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/README.md b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md new file mode 100644 index 000000000000..98dc9c6460ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md @@ -0,0 +1,169 @@ + + +# incrnangmean + +> Compute a [geometric mean][geometric-mean] incrementally, ignoring `NaN` values. + +
+ +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 incrnangmean = require( '@stdlib/stats/incr/gmean' ); +``` + +#### incrnangmean() + +Returns an accumulator `function` which incrementally computes a [geometric mean][geometric-mean], ignoring `NaN` values. + +```javascript +var accumulator = incrnangmean(); +``` + +#### 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 = incrnangmean(); + +var prod = accumulator( 2.0 ); +// returns 2.0 + +prod = accumulator( 1.0 ); +// returns ~1.414 + +prod = accumulator( NaN ); +// returns ~1.414 + +prod = accumulator( 3.0 ); +// returns ~1.817 + +prod = accumulator(); +// returns ~1.817 +``` + +
+ + + +
+ +## 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 incrnangmean = require( '@stdlib/stats/incr/nangmean' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnangmean(); + +// For each simulated value, update the geometric mean... +for ( i = 0; i < 100; i++ ) { + 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/nangmean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nangmean/benchmark/benchmark.js new file mode 100644 index 000000000000..3462392366f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/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 incrnangmean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnangmean(); + 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 = incrnangmean(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()*10.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(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/docs/img/equation_geometric_mean.svg b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/img/equation_geometric_mean.svg new file mode 100644 index 000000000000..09660f01bb97 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/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/nangmean/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/repl.txt new file mode 100644 index 000000000000..21d21fa2b667 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}() + Returns an accumulator function which incrementally computes a geometric + mean, ignoring `NaN` values. + + 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. + + If provided a negative value, the accumulated value is `NaN` for all future + invocations. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var v = accumulator() + null + > v = accumulator( 2.0 ) + 2.0 + > v = accumulator( NaN ) + 2.0 + > v = accumulator( 5.0 ) + ~3.16 + > v = accumulator() + ~3.16 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts new file mode 100644 index 000000000000..080d7197d540 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, returns an updated geometric mean; otherwise, returns the current geometric mean. +* +* +* @param x - value +* @returns geometric mean +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a geometric mean, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnangmean(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator(); +* // returns ~3.16 +*/ +declare function incrnangmean(): accumulator; + + +// EXPORTS // + +export = incrnangmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/test.ts new file mode 100644 index 000000000000..7fe1b490faf0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/test.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import incrnangmean = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnangmean(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnangmean( '5' ); // $ExpectError + incrnangmean( 5 ); // $ExpectError + incrnangmean( true ); // $ExpectError + incrnangmean( false ); // $ExpectError + incrnangmean( null ); // $ExpectError + incrnangmean( undefined ); // $ExpectError + incrnangmean( [] ); // $ExpectError + incrnangmean( {} ); // $ExpectError + incrnangmean( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnangmean(); + + 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 = incrnangmean(); + + 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/nangmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js new file mode 100644 index 000000000000..f74f48faf8e9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnangmean = require( './../lib' ); + +var accumulator; +var prod; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnangmean(); + +// For each simulated value, update the geometric mean... +console.log( '\nValue\tGeometric Mean\n' ); +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = ( randu()*100.0 ); + } + prod = accumulator( v ); + console.log( '%d\t%d', ( v === null) ? NaN : v.toFixed( 4 ), ( prod === null) ? NaN : prod.toFixed( 4 ) ); +} +console.log( '\nFinal geometric mean: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js new file mode 100644 index 000000000000..fdcc2df66960 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute a geometric mean incrementally. +* +* @module @stdlib/stats/incr/nangmean +* +* @example +* var incrgmean = require( '@stdlib/stats/incr/nangmean' ); +* +* var accumulator = incrnangmean(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator(); +* // returns ~3.16 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js new file mode 100644 index 000000000000..f91ba5fcdf54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js @@ -0,0 +1,74 @@ +/** +* @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 incrgmean = require( '@stdlib/stats/incr/gmean' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a geometric mean. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrgmean(); +* +* var v = accumulator(); +* // returns null +* +* v = accumulator( 2.0 ); +* // returns 2.0 +* +* v = accumulator( NaN ); +* // returns 2.0 +* +* v = accumulator( 5.0 ); +* // returns ~3.16 +* +* v = accumulator(); +* // returns ~3.16 +*/ +function incrnangmean() { + var gmean = incrgmean(); + 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] - new value + * @returns {(number|null)} geometric mean or null + */ + function accumulator( x ) { + if ( arguments.length === 0 || isnan( x ) ) { + return gmean(); + } + return gmean(x); + } +} + + +// EXPORTS // + +module.exports = incrnangmean; diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/package.json b/lib/node_modules/@stdlib/stats/incr/nangmean/package.json new file mode 100644 index 000000000000..423550a338a8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/stats/incr/nangmean", + "version": "0.0.0", + "description": "Compute a geometric 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.git", + "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", + "geometric", + "mean", + "average", + "avg", + "central tendency", + "product", + "prod", + "incremental", + "accumulator" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js new file mode 100644 index 000000000000..6c3564418e38 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js @@ -0,0 +1,150 @@ +/** +* @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 ln = require( '@stdlib/math/base/special/ln' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var isnan = require( '@stdlib/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var EPSILON = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var incrnangmean = require( '@stdlib/stats/incr/nangmean/lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnangmean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnangmean(), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes a geometric mean', function test( t ) { + var expected; + var actual; + var delta; + var data; + var prod; + var tol; + var acc; + var N; + var d; + var i; + var j; + + data = [ 2.0, 3.0, NaN, 2.0, 4.0, NaN, 3.0, 4.0 ]; + N = data.length; + + acc = incrnangmean(); + + prod = 1.0; + j = 0; + for ( i = 0; i < N; i++ ) { + d = data[ i ]; + if ( !isnan( d ) ) { + prod *= d; + expected = pow( prod, 1.0/(j+1) ); + j+=1; + } + actual = acc( d ); + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value. d: '+d+'.' ); + } else { + delta = abs( expected - actual ); + tol = 1.5 * EPSILON * abs( expected ); + t.strictEqual( delta <= tol, true, 'within tolerance. d: '+d+'. Expected: '+expected+'. Actual: '+actual+'. 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 delta; + var data; + var acc; + var tol; + var i; + + data = [ 2.0, NaN, 3.0, 1.0 ]; + + acc = incrnangmean(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + expected = 1.8171205928321397; + delta = abs( expected - acc() ); + tol = EPSILON * abs( expected ); + + t.strictEqual( delta <= tol, true, 'within tolerance. Expected: '+expected+'. Actual: '+acc()+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); + +tape( 'the accumulator function can return a result which overflows', function test( t ) { + var acc = incrnangmean(); + var i; + + for ( i = 0; i < 10000; i++ ) { + acc( 1.7976931348623157e+308 ); + } + t.strictEqual( acc(), PINF, 'returns infinity' ); + t.end(); +}); + +tape( 'the accumulator function can return a result which underflows', function test( t ) { + var acc = incrnangmean(); + var i; + + for ( i = 0; i < 10000; i++ ) { + acc( 5.0e-324 ); + } + t.strictEqual( acc(), 0.0, 'returns 0' ); + t.end(); +}); + +tape( 'if provided a `NaN`, the accumulator function ignores it', function test( t ) { + var acc; + + acc = incrnangmean(); + acc( 5.0 ); + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + + acc( NaN ); + t.strictEqual( isnan( acc() ), false, 'does not returns NaN' ); + + acc( 3.14 ); + t.strictEqual( acc(), exp( ( ln( 5.0 ) + ln( 3.14 ) ) / 2 ), 'correctly updates after NaN'); + t.end(); +}); + +tape( 'if the accumulator function has not been provided any data, the accumulator function returns `null`', function test( t ) { + var acc = incrnangmean(); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); From 9ae2150416dcb35ee5b53faca0bb22d70c9448f0 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 15:39:06 +0530 Subject: [PATCH 2/5] update licensing years and documentation --- lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js | 2 +- lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js index f74f48faf8e9..d5f16841bb4c 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js index fdcc2df66960..4684632956dd 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute a geometric mean incrementally. +* Compute a geometric mean incrementally, ignoring `NaN` values. * * @module @stdlib/stats/incr/nangmean * diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js index f91ba5fcdf54..7a91d5555c40 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js @@ -27,7 +27,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); // MAIN // /** -* Returns an accumulator function which incrementally computes a geometric mean. +* Returns an accumulator function which incrementally computes a geometric mean, ignoring `NaN` values. * * @returns {Function} accumulator function * From c1ea2b819a87ef2d5758c6d4807598c6ce90ff80 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 19:58:42 +0530 Subject: [PATCH 3/5] update examples in main.js --- lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js index 7a91d5555c40..0d26b8b06edf 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js @@ -32,7 +32,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * @returns {Function} accumulator function * * @example -* var accumulator = incrgmean(); +* var accumulator = incrnangmean(); * * var v = accumulator(); * // returns null From 2895b9cacd6e5af24eb8264276b210d184d720f8 Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Thu, 13 Mar 2025 20:08:09 +0530 Subject: [PATCH 4/5] update README.md --- lib/node_modules/@stdlib/stats/incr/nangmean/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/README.md b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md index 98dc9c6460ed..3015a5549ce8 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md @@ -48,7 +48,7 @@ The [geometric mean][geometric-mean] is defined as the nth root of a product of ## Usage ```javascript -var incrnangmean = require( '@stdlib/stats/incr/gmean' ); +var incrnangmean = require( '@stdlib/stats/incr/nangmean' ); ``` #### incrnangmean() From 7b7d44cd3fb2540491f51886c58874cf00c4298f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 27 Sep 2025 14:34:48 -0500 Subject: [PATCH 5/5] chore: minor clean-up --- 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: na - 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: 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/nangmean/README.md | 32 ++++--------------- .../stats/incr/nangmean/docs/types/index.d.ts | 1 - .../stats/incr/nangmean/examples/index.js | 23 ++++++------- .../@stdlib/stats/incr/nangmean/lib/index.js | 2 +- .../@stdlib/stats/incr/nangmean/lib/main.js | 2 +- .../@stdlib/stats/incr/nangmean/package.json | 6 ++-- .../@stdlib/stats/incr/nangmean/test/test.js | 8 ++--- 7 files changed, 25 insertions(+), 49 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/README.md b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md index 3015a5549ce8..f2a8deb08ac0 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/README.md +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/README.md @@ -26,16 +26,12 @@ limitations under the License. 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}} +\biggl( \prod_{i=0}^{n-1} x_i \biggr)^{\frac{1}{n}} = \sqrt[n]{x_0 x_1 \cdots x_{n-1}} ``` - @@ -103,7 +99,8 @@ prod = accumulator(); ```javascript -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var uniform = require( '@stdlib/random/base/uniform' ); var incrnangmean = require( '@stdlib/stats/incr/nangmean' ); var accumulator; @@ -115,10 +112,10 @@ accumulator = incrnangmean(); // For each simulated value, update the geometric mean... for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { + if ( bernoulli( 0.2 ) ) { v = NaN; } else { - v = ( randu()*100.0 ); + v = uniform( 0.0, 100.0 ); } accumulator( v ); } @@ -133,15 +130,6 @@ console.log( accumulator() ); @@ -154,14 +142,6 @@ console.log( accumulator() ); -[@stdlib/stats/incr/hmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/hmean - -[@stdlib/stats/incr/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mean - -[@stdlib/stats/incr/mgmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/mgmean - -[@stdlib/stats/incr/summary]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/summary - diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts index 080d7197d540..1841ab45e572 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/docs/types/index.d.ts @@ -23,7 +23,6 @@ /** * If provided a value, returns an updated geometric mean; otherwise, returns the current geometric mean. * -* * @param x - value * @returns geometric mean */ diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js index d5f16841bb4c..bf7a20fc3d5f 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/examples/index.js @@ -18,26 +18,21 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var uniform = require( '@stdlib/random/base/uniform' ); var incrnangmean = require( './../lib' ); -var accumulator; -var prod; -var v; -var i; - // Initialize an accumulator: -accumulator = incrnangmean(); +var accumulator = incrnangmean(); // For each simulated value, update the geometric mean... -console.log( '\nValue\tGeometric Mean\n' ); +console.log( '\nValue\tGeometric mean\n' ); +var prod; +var v; +var i; for ( i = 0; i < 100; i++ ) { - if ( randu() < 0.2 ) { - v = NaN; - } else { - v = ( randu()*100.0 ); - } + v = ( bernoulli( 0.2 ) ) ? NaN : uniform( 0.0, 100.0 ); prod = accumulator( v ); - console.log( '%d\t%d', ( v === null) ? NaN : v.toFixed( 4 ), ( prod === null) ? NaN : prod.toFixed( 4 ) ); + console.log( '%s\t%s', ( v === v ) ? v.toFixed( 4 ) : 'NaN', ( prod === null ) ? 'null' : prod.toFixed( 4 ) ); } console.log( '\nFinal geometric mean: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js index 4684632956dd..8e4abf172d0a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/index.js @@ -24,7 +24,7 @@ * @module @stdlib/stats/incr/nangmean * * @example -* var incrgmean = require( '@stdlib/stats/incr/nangmean' ); +* var incrnangmean = require( '@stdlib/stats/incr/nangmean' ); * * var accumulator = incrnangmean(); * diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js index 0d26b8b06edf..496206308bed 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/lib/main.js @@ -64,7 +64,7 @@ function incrnangmean() { if ( arguments.length === 0 || isnan( x ) ) { return gmean(); } - return gmean(x); + return gmean( x ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/package.json b/lib/node_modules/@stdlib/stats/incr/nangmean/package.json index 423550a338a8..e28f7a0e591a 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/package.json @@ -23,7 +23,7 @@ }, "types": "./docs/types", "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib.git", + "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", "url": "git://github.com/stdlib-js/stdlib.git" @@ -63,6 +63,8 @@ "product", "prod", "incremental", - "accumulator" + "accumulator", + "nan", + "ignore" ] } diff --git a/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js b/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js index 6c3564418e38..b4d942a1915b 100644 --- a/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nangmean/test/test.js @@ -23,12 +23,12 @@ var tape = require( 'tape' ); var ln = require( '@stdlib/math/base/special/ln' ); var exp = require( '@stdlib/math/base/special/exp' ); -var isnan = require( '@stdlib/assert/is-nan' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var abs = require( '@stdlib/math/base/special/abs' ); var EPSILON = require( '@stdlib/constants/float64/eps' ); var PINF = require( '@stdlib/constants/float64/pinf' ); -var incrnangmean = require( '@stdlib/stats/incr/nangmean/lib' ); +var incrnangmean = require( './../lib' ); // TESTS // @@ -69,7 +69,7 @@ tape( 'the accumulator function incrementally computes a geometric mean', functi if ( !isnan( d ) ) { prod *= d; expected = pow( prod, 1.0/(j+1) ); - j+=1; + j += 1; } actual = acc( d ); if ( actual === expected ) { @@ -136,7 +136,7 @@ tape( 'if provided a `NaN`, the accumulator function ignores it', function test( t.strictEqual( acc(), 5.0, 'returns expected value' ); acc( NaN ); - t.strictEqual( isnan( acc() ), false, 'does not returns NaN' ); + t.strictEqual( isnan( acc() ), false, 'does not return NaN' ); acc( 3.14 ); t.strictEqual( acc(), exp( ( ln( 5.0 ) + ln( 3.14 ) ) / 2 ), 'correctly updates after NaN');