math.statistics: fix calculation of the harmonic mean
parent
423181c867
commit
0701902122
|
@ -12,7 +12,7 @@ HELP: harmonic-mean
|
|||
{ $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
|
||||
|
@ -24,7 +24,8 @@ HELP: mean
|
|||
{ $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" } }
|
||||
|
|
|
@ -13,7 +13,10 @@ IN: math.statistics.tests
|
|||
{ 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
|
||||
|
|
|
@ -35,7 +35,7 @@ IN: math.statistics
|
|||
[ [ 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
|
||||
|
|
Loading…
Reference in New Issue