Add harmonic mean and geometric mean
lulunac27a opened this issue · comments
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 =
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 =
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/
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