math.extras: Faster gini. Leaving this as a separate patch for comparison.
parent
59e97e1587
commit
d5e26ee76d
|
@ -4,7 +4,7 @@
|
||||||
USING: combinators.short-circuit grouping kernel locals math
|
USING: combinators.short-circuit grouping kernel locals math
|
||||||
math.combinatorics math.constants math.functions math.order
|
math.combinatorics math.constants math.functions math.order
|
||||||
math.primes math.ranges math.statistics math.vectors memoize
|
math.primes math.ranges math.statistics math.vectors memoize
|
||||||
sequences sequences.extras sorting assocs ;
|
sequences sequences.extras sorting assocs fry ;
|
||||||
|
|
||||||
IN: math.extras
|
IN: math.extras
|
||||||
|
|
||||||
|
@ -160,9 +160,11 @@ PRIVATE>
|
||||||
:: (gini) ( seq -- x )
|
:: (gini) ( seq -- x )
|
||||||
seq natural-sort :> sorted
|
seq natural-sort :> sorted
|
||||||
seq length :> len
|
seq length :> len
|
||||||
len [1,b] sorted zip 0 [ * + ] assoc-reduce :> sum0
|
0 0 sorted [
|
||||||
2 sum0 * sorted sum len * / :> G
|
'[ _ + ] dip dupd +
|
||||||
G 1 - 1 len / - ; inline
|
] each :> ( a b )
|
||||||
|
b len a * / :> B
|
||||||
|
1 len recip + 2 B * - ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue