cum-mean
Added a word to calculate cumulative mean. Signed-off-by: lorynj <lorynj@gmail.com>db4
parent
0dc6240d4d
commit
ca7dd6a6a3
|
@ -204,6 +204,16 @@ HELP: cum-product
|
|||
}
|
||||
} ;
|
||||
|
||||
HELP: cum-mean
|
||||
{ $values { "seq" sequence } { "seq'" sequence } }
|
||||
{ $description "Returns the cumulative mean of " { $snippet "seq" } "." }
|
||||
{ $examples
|
||||
{ $example "USING: math.statistics prettyprint ;"
|
||||
"{ 1.0 2.0 3.0 } cum-mean ."
|
||||
"{ 1.0 1.5 2.0 }"
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: cum-min
|
||||
{ $values { "seq" sequence } { "seq'" sequence } }
|
||||
{ $description "Returns the cumulative min of " { $snippet "seq" } "." }
|
||||
|
|
|
@ -117,6 +117,7 @@ IN: math.statistics.tests
|
|||
[ { 1 1 2 6 } ] [ { 1 1 2 3 } cum-product ] unit-test
|
||||
[ { 5 3 3 1 } ] [ { 5 3 4 1 } cum-min ] unit-test
|
||||
[ { 1 3 3 5 } ] [ { 1 3 1 5 } cum-max ] unit-test
|
||||
[ { 1.0 1.5 2.0 } ] [ { 1.0 2.0 3.0 } cum-mean ] unit-test
|
||||
|
||||
{ t }
|
||||
[
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2008 Doug Coleman, Michael Judge.
|
||||
! Copyright (C) 2008 Doug Coleman, Michael Judge, Loryn Jenkins.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs combinators generalizations kernel locals math
|
||||
math.functions math.order math.vectors sequences
|
||||
math.functions math.order math.vectors math.ranges sequences
|
||||
sequences.private sorting fry arrays grouping sets
|
||||
splitting.monotonic ;
|
||||
IN: math.statistics
|
||||
|
@ -350,6 +350,9 @@ ALIAS: std sample-std
|
|||
|
||||
: cum-product ( seq -- seq' )
|
||||
1 [ * ] cum-map ;
|
||||
|
||||
: cum-mean ( seq -- seq' )
|
||||
[ cum-sum ] [ length [1,b] ] bi [ / ] 2map ;
|
||||
|
||||
: cum-count ( seq quot -- seq' )
|
||||
[ 0 ] dip '[ _ call [ 1 + ] when ] cum-map ; inline
|
||||
|
|
Loading…
Reference in New Issue