-
-
Notifications
You must be signed in to change notification settings - Fork 908
feat: add stats/incr/wstdev
#3088
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hi there! 👋
And thank you for opening your first pull request! We will review it shortly. 🏃 💨
@Planeshifter ready for review !! |
0116e3e
to
66b5efc
Compare
@@ -0,0 +1,31 @@ | |||
{{alias}}( [mean] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file does not follow our REPL text conventions and should be updated accordingly. See the REPL text style guide.
> s = accumulator( 2.0, 1.5 ) | ||
0.0 | ||
> s = accumulator( -5.0, 2.0 ) | ||
updated weighted standard deviation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a valid return annotation.
* var accumulator = incrwstdev( 3.14 ); | ||
*/ | ||
function incrwstdev( mean ) { | ||
var delta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use TAB indentation, not space. Please ensure you have EditorConfig setup in your IDE.
if ( W === 0 ) { | ||
return null; | ||
} | ||
return Math.sqrt( M2 / W ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the stdlib package equivalent @stdlib/math/base/special/sqrt
.
return Math.sqrt( M2 / W ); | ||
} | ||
if ( !isNumber( x ) || !isNumber( w ) || w < 0 ) { | ||
throw new TypeError( 'Both value and non-negative weight are required' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message does not follow our error message conventions.
* // returns 0.0 | ||
* | ||
* s = accumulator( -5.0, 2.0 ); | ||
* // returns updated weighted standard deviation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a valid return annotation.
* Returns an accumulator function which incrementally computes a weighted standard deviation. | ||
* | ||
* @param {number} [mean] - known mean value | ||
* @throws {TypeError} must provide a number primitive for mean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @throws {TypeError} must provide a number primitive for mean | |
* @throws {TypeError} must provide a number for mean |
return Math.sqrt( M2 / W ); | ||
} | ||
if ( !isNumber( x ) || !isNumber( w ) || w < 0 ) { | ||
throw new TypeError( 'Both value and non-negative weight are required' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
This function provides an incremental approach to calculating the weighted standard deviation. It computes the value iteratively, updating the result with each new data point and weight, which is useful for scenarios where data is streamed or updated over time. | ||
|
||
<!-- /.intro --> | ||
<section class="usage> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<section class="usage> | |
<section class="usage> |
throw new TypeError( 'Both value and non-negative weight are required' ); | ||
} | ||
W += w; | ||
N += 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is N
needed in this implementation?
*/ | ||
function accumulatorWithoutMean( x, w ) { | ||
if ( arguments.length < 2 ) { | ||
if ( W === 0 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if I provide all weights equal to 0
? Should the output standard deviation be null
or 0
?
* @returns {(number|null)} weighted standard deviation or null | ||
*/ | ||
function accumulatorWithoutMean( x, w ) { | ||
if ( arguments.length < 2 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I provide only x
? That seems like a user error. Did they forget to provide a weight or did they erroneously provide an x
?
* @returns {(number|null)} weighted standard deviation or null | ||
*/ | ||
function accumulatorWithMean( x, w ) { | ||
if ( arguments.length < 2 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as above.
stats/incr/wstdev
This pull request has been automatically closed because it has been inactive for an extended period after changes were requested. If you still wish to pursue this contribution, feel free to reopen the pull request or submit a new one. We appreciate your interest in contributing to stdlib! |
Resolves #47
Description
This pull request:
@stdlib/stats/incr/wstdev
to support efficient, real-time computation of weighted standard deviations.Related Issues
This pull request:
stats/incr/wstdev
#47 [RFC]: addstats/incr/wstdev
#47Questions
No.
Other
No.
Checklist
Read, understood, and followed the contributing guidelines.
@stdlib-js/reviewers