From ca69afec318fef4ca8a68b6d118d8a63f9cf708b Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Tue, 25 Sep 2012 22:27:42 -0700 Subject: [PATCH] math.statistics: use "cumulative map" as base of all cumulative words. --- basis/math/statistics/statistics.factor | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/basis/math/statistics/statistics.factor b/basis/math/statistics/statistics.factor index 651b450185..5cf4e2b56c 100644 --- a/basis/math/statistics/statistics.factor +++ b/basis/math/statistics/statistics.factor @@ -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 ;