Skip to content

#5 - Root mean square #25

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 2 commits into
base: master
Choose a base branch
from

Conversation

thomasfoster
Copy link
Contributor

The description of root mean square may be lacking. Let me know if anything needs updating. Thanks!

@@ -21,6 +21,7 @@ npm i stat-methods
- [mean](#mean)
- [harmonicMean](#harmonicMean)
- [geometricMean](#geometricMean)
- [rootMeanSquare](#rootMeanSquare)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please rename the method to rms as set in #5 ?

#### rootMeanSquare

```js
rootMeanSquare(arr);
Copy link
Owner

Choose a reason for hiding this comment

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

Please rename to rms throughout all files.

* @returns {Number} the arithmetic mean of the data array
*/
export function rootMeanSquare(arr) {
if (min(arr) === undefined) return undefined;
Copy link
Owner

Choose a reason for hiding this comment

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

I understand what you are checking here but it is a bit counter-intuitive. It is not necessary to compute the min of the array when calculating its rms. Could you please use this check instead ?

if (!Array.isArray(arr) || arr.length === 0) return undefined;

for (let i = 0; i < arr.length; i += 1) {
arrSquareSum += arr[i] ** 2;
}
return Math.sqrt((arrSquareSum / arr.length));
Copy link
Owner

Choose a reason for hiding this comment

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

Although this approach solves the problem, it does not make use of previously defined methods in the library. We could use the literal definition of the rms:

  • Compute the mean of the squared values of the elements of the array;
  • Compute its square root if it exists.

This would give something like this:

function rms(arr) {
  const xBar = mean(arr.map(elt => elt ** 2));
  return xBar === undefined ? undefined : Math.sqrt(xBar);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants