}
} ;
+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" } "." }
[ { 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 }
[
-! 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
: 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