{ $values { "seq" sequence } { "x" "a non-negative real number" } }
{ $description "Computes the harmonic mean of the elements in " { $snippet "seq" } ". The harmonic mean is appropriate when the average of rates is desired." }
{ $notes "Positive reals only." }
-{ $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "6/11" } }
+{ $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } harmonic-mean ." "18/11" } }
{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
HELP: kth-smallest
{ $values { "seq" sequence } { "x" "a non-negative real number" } }
{ $description "Computes the arithmetic mean of the elements in " { $snippet "seq" } "." }
{ $examples { $example "USING: math.statistics prettyprint ;" "{ 1 2 3 } mean ." "2" } }
-{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." } ;
+{ $errors "Throws a " { $link signal-error. } " (divide by zero) if the sequence is empty." }
+{ $see-also geometric-mean harmonic-mean } ;
HELP: median
{ $values { "seq" sequence } { "x" "a non-negative real number" } }
{ 1.0 } [ { 1 1 1 } geometric-mean ] unit-test
{ t } [ 1000 1000 <array> geometric-mean 1000 .01 ~ ] unit-test
{ t } [ 100000 100000 <array> geometric-mean 100000 .01 ~ ] unit-test
-{ 1/3 } [ { 1 1 1 } harmonic-mean ] unit-test
+
+{ 1 } [ { 1 1 1 } harmonic-mean ] unit-test
+{ 12/7 } [ { 1 2 4 } harmonic-mean ] unit-test
+
{ 5+1/4 } [ { 1 3 5 7 } contraharmonic-mean ] unit-test
{ 18 } [ { 4 8 15 16 23 42 } 0 trimmed-mean ] unit-test
{ 15+1/2 } [ { 4 8 15 16 23 42 } 0.2 trimmed-mean ] unit-test
[ [ log ] map-sum ] [ length ] bi /f e^ ; inline
: harmonic-mean ( seq -- x )
- [ recip ] map-sum recip ; inline
+ [ [ recip ] map-sum ] [ length swap / ] bi ; inline
: contraharmonic-mean ( seq -- x )
[ sum-of-squares ] [ sum ] bi / ; inline