Range now uses minmax
parent
16454ccb99
commit
4b607b6b3e
|
@ -1,6 +1,8 @@
|
||||||
IN: math-contrib
|
IN: math-contrib
|
||||||
USING: kernel math sequences ;
|
USING: kernel math sequences ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
: mean ( seq -- n )
|
: mean ( seq -- n )
|
||||||
#! arithmetic mean, sum divided by length
|
#! arithmetic mean, sum divided by length
|
||||||
[ sum ] keep length / ;
|
[ sum ] keep length / ;
|
||||||
|
@ -21,9 +23,13 @@ USING: kernel math sequences ;
|
||||||
2 /i swap nth
|
2 /i swap nth
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: minmax ( seq -- min max )
|
||||||
|
#! find the min and max of a seq in one pass
|
||||||
|
inf -inf rot [ dup pick max -rot nip pick min -rot nip ] each ;
|
||||||
|
|
||||||
: range ( seq -- n )
|
: range ( seq -- n )
|
||||||
#! max - min
|
#! max - min
|
||||||
dup first 2dup [ min ] reduce >r [ max ] reduce r> - ;
|
minmax swap - ;
|
||||||
|
|
||||||
: var ( seq -- )
|
: var ( seq -- )
|
||||||
#! variance, normalize by N-1
|
#! variance, normalize by N-1
|
||||||
|
|
Loading…
Reference in New Issue