]> gitweb.factorcode.org Git - factor.git/commitdiff
cum-mean
authorlorynj <lorynj@gmail.com>
Sun, 5 May 2013 00:12:59 +0000 (10:12 +1000)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 May 2013 15:15:39 +0000 (08:15 -0700)
Added a word to calculate cumulative mean.

Signed-off-by: lorynj <lorynj@gmail.com>
basis/math/statistics/statistics-docs.factor
basis/math/statistics/statistics-tests.factor
basis/math/statistics/statistics.factor

index 7397b9f4f1361e627259c3b00ea0630a3e831626..bab07f71902e3346a0c205fa8f70c6eb3c260ff1 100644 (file)
@@ -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" } "." }
index 7e22222225bd1be7104103e967e2b157e1f0ca6f..65d347f5ed5472ac508dd4b8b6823a3d99f8e43a 100644 (file)
@@ -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 }
 [
index 30fbce55edc8120e6ca35dfc545602cf8ee7a946..65606c9e4642b391c3609919da824dd2691bfd4c 100644 (file)
@@ -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