math.statistics: add rank-values
parent
8ed541b26b
commit
d2317c71f5
|
@ -157,3 +157,15 @@ IN: math.statistics.tests
|
|||
] unit-test
|
||||
|
||||
{ { 0 1/4 1/2 3/4 1 } } [ 5 iota rescale ] unit-test
|
||||
|
||||
|
||||
{
|
||||
{ 2 2 2 1 0 5 6 7 7 7 7 }
|
||||
} [
|
||||
{ 30 30 30 20 10 40 50 60 60 60 60 } rank-values
|
||||
] unit-test
|
||||
|
||||
{
|
||||
{ 1 0 2 3 4 }
|
||||
}
|
||||
[ { 3 1 4 15 92 } rank-values ] unit-test
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs combinators generalizations kernel locals math
|
||||
math.functions math.order math.vectors sequences
|
||||
sequences.private sorting fry arrays grouping sets ;
|
||||
sequences.private sorting fry arrays grouping sets
|
||||
splitting.monotonic ;
|
||||
IN: math.statistics
|
||||
|
||||
: power-mean ( seq p -- x )
|
||||
|
@ -343,3 +344,11 @@ ALIAS: corr sample-corr
|
|||
|
||||
: rescale ( u -- v )
|
||||
dup minmax over - [ v-n ] [ v/n ] bi* ;
|
||||
|
||||
: rank-values ( seq -- seq' )
|
||||
[
|
||||
[ ] [ length iota ] bi zip sort-keys
|
||||
[ [ first ] bi@ = ] monotonic-split
|
||||
[ values ] map [ 0 [ length + ] accumulate nip ] [ ] bi zip
|
||||
] [ length f <array> ] bi
|
||||
[ '[ first2 [ _ set-nth ] with each ] each ] keep ;
|
||||
|
|
Loading…
Reference in New Issue