Skip to content

feat: add stats/incr/nanmmean #6185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

satansin123
Copy link
Contributor

@satansin123 satansin123 commented Mar 19, 2025


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 ---

Resolves #5588.

Description

What is the purpose of this pull request?

This pull request:

  • Adds the @stdlib/stats/incr/nanmmean package, which computes an incremental mean while handling NaN values by skipping them.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

test -
image

benchmark -
image

examples -
image

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

---
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-bot
Copy link
Contributor

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

@stdlib-bot stdlib-bot added Good First PR A pull request resolving a Good First Issue. Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. and removed Good First PR A pull request resolving a Good First Issue. labels Mar 19, 2025
@stdlib-bot
Copy link
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/incr/nanmmean $\color{green}182/182$
$\color{green}+100.00\%$
$\color{green}14/14$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}182/182$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.


#### incrnanmmean( window )

Returns an accumulator `function` which incrementally computes a moving [arithmetic mean][arithmetic-mean]. The `window` parameter defines the number of values over which to compute the moving mean.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Returns an accumulator `function` which incrementally computes a moving [arithmetic mean][arithmetic-mean]. The `window` parameter defines the number of values over which to compute the moving mean.
Returns an accumulator function which incrementally computes a moving [arithmetic mean][arithmetic-mean], ignoring `NaN` values.. The `window` parameter defines the number of values over which to compute the moving mean.

Comment on lines +118 to +135
var randu = require( '@stdlib/random/base/randu' );
var incrnanmmean = require( '@stdlib/stats/incr/nanmmean' );

var accumulator;
var v;
var i;

// Initialize an accumulator:
accumulator = incrnanmmean( 5 );

// For each simulated datum, update the moving mean...
for ( i = 0; i < 100; i++ ) {
if ( randu() < 0.2 ) {
v = NaN;
} else {
v = randu() * 100.0;
}
accumulator( v );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var randu = require( '@stdlib/random/base/randu' );
var incrnanmmean = require( '@stdlib/stats/incr/nanmmean' );
var accumulator;
var v;
var i;
// Initialize an accumulator:
accumulator = incrnanmmean( 5 );
// For each simulated datum, update the moving mean...
for ( i = 0; i < 100; i++ ) {
if ( randu() < 0.2 ) {
v = NaN;
} else {
v = randu() * 100.0;
}
accumulator( v );
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var incrnanmmean = require( '@stdlib/stats/incr/nanmmean' );
// Initialize an accumulator:
var accumulator = incrnanmmean( 5 );
// For each simulated datum, update the moving mean...
var I;
for ( i = 0; i < 100; i++ ) {
accumulator( ( bernoulli( 0.8 ) < 1 ) ? NaN : uniform( 0.0, 100.0 ) );

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var randu = require( '@stdlib/random/base/randu' );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will be using iterations as the input


b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = acc( randu() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
v = acc( randu() );
v = acc( i );


'use strict';

var randu = require( '@stdlib/random/base/randu' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as mentioned in the markdown file

// MODULES //

var tape = require( 'tape' );
var incrnanmmean = require( '@stdlib/stats/incr/nanmmean/lib' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var incrnanmmean = require( '@stdlib/stats/incr/nanmmean/lib' );
var incrnanmmean = require( './../lib' );

@ShabiShett07
Copy link
Contributor

@satansin123, the PR looks good, left some comments to make some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First PR A pull request resolving a Good First Issue. Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add stats/incr/nanmmean
3 participants