Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Ranking-methods/Factor/ranking-methods.factor
Normal file
36
Task/Ranking-methods/Factor/ranking-methods.factor
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
USING: arrays assocs formatting fry generalizations io kernel
|
||||
math math.ranges math.statistics math.vectors sequences
|
||||
splitting.monotonic ;
|
||||
IN: rosetta-code.ranking
|
||||
|
||||
CONSTANT: ranks {
|
||||
{ 44 "Solomon" } { 42 "Jason" } { 42 "Errol" }
|
||||
{ 41 "Garry" } { 41 "Bernard" } { 41 "Barry" }
|
||||
{ 39 "Stephen" }
|
||||
}
|
||||
|
||||
: rank ( seq quot -- seq' )
|
||||
'[ [ = ] monotonic-split [ length ] map dup @ [ <array> ]
|
||||
2map concat ] call ; inline
|
||||
|
||||
: standard ( seq -- seq' ) [ cum-sum0 1 v+n ] rank ;
|
||||
: modified ( seq -- seq' ) [ cum-sum ] rank ;
|
||||
: dense ( seq -- seq' ) [ length [1,b] ] rank ;
|
||||
: ordinal ( seq -- seq' ) length [1,b] ;
|
||||
|
||||
: fractional ( seq -- seq' )
|
||||
[ dup cum-sum swap [ dupd - [a,b) mean ] 2map ] rank ;
|
||||
|
||||
: .rank ( quot -- )
|
||||
[ ranks dup keys ] dip call swap
|
||||
[ first2 "%5u %d %s\n" printf ] 2each ; inline
|
||||
|
||||
: ranking-demo ( -- )
|
||||
"Standard ranking" [ standard ]
|
||||
"Modified ranking" [ modified ]
|
||||
"Dense ranking" [ dense ]
|
||||
"Ordinal ranking" [ ordinal ]
|
||||
"Fractional ranking" [ fractional ]
|
||||
[ [ print ] [ .rank nl ] bi* ] 2 5 mnapply ;
|
||||
|
||||
MAIN: ranking-demo
|
||||
Loading…
Add table
Add a link
Reference in a new issue