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

Add harmonic mean and geometric mean #3778

Closed
lulunac27a opened this issue Oct 9, 2023 · 1 comment
Closed

Add harmonic mean and geometric mean #3778

lulunac27a opened this issue Oct 9, 2023 · 1 comment

Comments

@lulunac27a
Copy link

Harmonic mean is the sum of all reciprocals (which is one divided by a number), and the geometric mean is the product of numbers raised to one divided by number of items in a list.
Harmonic mean = $\dfrac{n}{x_{1} + x_{2} + x_{3} + ... + x_{n}}$
For example, the harmonic mean of 2, 3, and 5 is 3/(1/2+1/3+1/5) = 3/(15/30+10/30+6/30) = 3/(31/30) = 3*30/31 = 90/31 = 2 28/30 = 2 14/15
Geometric mean = $\sqrt[n]{{x_{1} \times x_{2} \times x_{3} \times ... \times x_{n}}}$

For example, the geometric mean of 2, 3, and 5 is (235)^(1/3)=30^(1/3)=3.1072

Sources:
https://byjus.com/maths/harmonic-mean/
https://www.scribbr.com/statistics/geometric-mean/

@Fil
Copy link
Member

Fil commented Oct 9, 2023

For an harmonic mean I don't think there is much more to do than X => 1 / d3.mean(X, d => 1/d).

For a geometric mean, see https://observablehq.com/@fil/d3-gmdn (the notebook is not only about the gmdn “joke”, it contains a solid implementation of the geometric mean). Task tracked at d3/d3-array#194

@Fil Fil closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants