Skip to content
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

feat: Implement log average #556

Merged
merged 2 commits into from Mar 2, 2021
Merged

feat: Implement log average #556

merged 2 commits into from Mar 2, 2021

Conversation

dsaxton
Copy link
Contributor

@dsaxton dsaxton commented Mar 1, 2021

Closes #171

Adds a logAverage function as an equivalent way of calculating the geometric mean. Also fixes what's arguably a bug in geometricMean where it throws an error for inputs containing zero instead of returning zero. Interestingly logAverage still handles that case correctly because Math.log(0) becomes -Infinity, and Math.exp(-Infinity) turns out to be zero.

t.end();
});

t.test("does not overflow for large products", function (t) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also remove this and the underflow test as they're a tad on the trivial side for this function (would be more interesting for geometricMean)

Copy link
Member

@tmcw tmcw left a comment

Choose a reason for hiding this comment

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

👍 Great, and nice catch with that geometric mean bug

@tmcw tmcw merged commit aeda3c0 into simple-statistics:master Mar 2, 2021
@dsaxton dsaxton deleted the geometric-mean-log-average branch March 2, 2021 02:09
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.

Implement error-correcting geometric mean algorithm
2 participants