Merge branch 'master' of git://factorcode.org/git/factor
commit
0240427ab3
|
@ -4,21 +4,21 @@ IN: math.statistics
|
||||||
|
|
||||||
: mean ( seq -- n )
|
: mean ( seq -- n )
|
||||||
#! arithmetic mean, sum divided by length
|
#! arithmetic mean, sum divided by length
|
||||||
[ sum ] keep length / ;
|
[ sum ] [ length ] bi / ;
|
||||||
|
|
||||||
: geometric-mean ( seq -- n )
|
: geometric-mean ( seq -- n )
|
||||||
#! geometric mean, nth root of product
|
#! geometric mean, nth root of product
|
||||||
[ product ] keep length swap nth-root ;
|
[ length ] [ product ] bi nth-root ;
|
||||||
|
|
||||||
: harmonic-mean ( seq -- n )
|
: harmonic-mean ( seq -- n )
|
||||||
#! harmonic mean, reciprocal of sum of reciprocals.
|
#! harmonic mean, reciprocal of sum of reciprocals.
|
||||||
#! positive reals only
|
#! positive reals only
|
||||||
0 [ recip + ] reduce recip ;
|
[ recip ] sigma recip ;
|
||||||
|
|
||||||
: median ( seq -- n )
|
: median ( seq -- n )
|
||||||
#! middle number if odd, avg of two middle numbers if even
|
#! middle number if odd, avg of two middle numbers if even
|
||||||
natural-sort dup length dup even? [
|
natural-sort dup length dup even? [
|
||||||
1- 2 / swap [ nth ] 2keep >r 1+ r> nth + 2 /
|
1- 2 / swap [ nth ] [ >r 1+ r> nth ] 2bi + 2 /
|
||||||
] [
|
] [
|
||||||
2 / swap nth
|
2 / swap nth
|
||||||
] if ;
|
] if ;
|
||||||
|
|
Loading…
Reference in New Issue