]> gitweb.factorcode.org Git - factor.git/commitdiff
math.statistics: use "cumulative map" as base of all cumulative words.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Sep 2012 05:27:42 +0000 (22:27 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 26 Sep 2012 05:27:42 +0000 (22:27 -0700)
basis/math/statistics/statistics.factor

index 651b450185c190dd9fa067f10d53216f157f4077..5cf4e2b56c3903e0a63724603ccbdfb8eeb5e83c 100644 (file)
@@ -318,17 +318,20 @@ ALIAS: ste sample-ste
 
 ALIAS: corr sample-corr
 
+: cum-map ( seq identity quot -- seq' )
+    swapd [ dup ] compose map nip ; inline
+
 : cum-sum ( seq -- seq' )
-    0 swap [ + dup ] map nip ;
+    0 [ + ] cum-map ;
 
 : cum-product ( seq -- seq' )
-    1 swap [ * dup ] map nip ;
+    1 [ * ] cum-map ;
 
 : cum-min ( seq -- seq' )
-    [ ?first ] keep [ min dup ] map nip ;
+    dup ?first [ min ] cum-map ;
 
 : cum-max ( seq -- seq' )
-    [ ?first ] keep [ max dup ] map nip ;
+    dup ?first [ max ] cum-map ;
 
 : probabilities ( seq -- probabilities )
     [ histogram values ] [ length ] bi v/n ;