]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics: faster cum-mean.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 May 2013 16:12:40 +0000 (09:12 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 6 May 2013 16:12:40 +0000 (09:12 -0700)
basis/math/statistics/statistics.factor

index 65606c9e4642b391c3609919da824dd2691bfd4c..c8f3de1fe63863afba55664eda1ea68a73bd6270 100644 (file)
@@ -339,7 +339,7 @@ ALIAS: std sample-std
 
 : sample-corr ( {x} {y} -- corr ) 1 corr-ddof ; inline
 
-: cum-map ( seq identity quot -- seq' )
+: cum-map ( seq identity quot: ( prev elt -- next ) -- seq' )
     swapd [ dup ] compose map nip ; inline
 
 : cum-sum ( seq -- seq' )
@@ -350,9 +350,9 @@ ALIAS: std sample-std
 
 : cum-product ( seq -- seq' )
     1 [ * ] cum-map ;
-    
+
 : cum-mean ( seq -- seq' )
-    [ cum-sum ] [ length [1,b] ] bi [ / ] 2map ;    
+    0 swap [ [ + dup ] dip 1 + / ] map-index nip ;
 
 : cum-count ( seq quot -- seq' )
     [ 0 ] dip '[ _ call [ 1 + ] when ] cum-map ; inline