From 35bd1a4bbc5ccc0e12e3312bfbadc4ce99638234 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 26 Sep 2012 15:11:41 -0700 Subject: [PATCH] math.extras: invent "cum-reduce" concept for gini. --- extra/math/extras/extras.factor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/math/extras/extras.factor b/extra/math/extras/extras.factor index d8ee57d69d..bdc92c300b 100644 --- a/extra/math/extras/extras.factor +++ b/extra/math/extras/extras.factor @@ -155,15 +155,15 @@ PRIVATE> : until-zero ( n quot -- ) [ dup zero? ] swap until drop ; inline -: sum-cum-sum ( seq -- sum sum-of-cumulative-sum-of-seq ) - [ 0 0 ] dip [ '[ _ + ] dip dupd + ] each ; inline +: cum-reduce ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... result cum-result ) + [ dup rot ] dip dup '[ _ curry dip dupd @ ] each ; inline sorted seq length :> len - sorted sum-cum-sum :> ( a b ) + sorted 0 [ + ] cum-reduce :> ( a b ) b len a * / :> B 1 len recip + 2 B * - ;