<vose> ( dist -- vose )


Vocabulary
math.extras

Inputs
distan object


Outputs
vosean object


Definition


:: <vose> ( dist -- vose )
V{ } clone :> small
V{ } clone :> large dist assoc-size :> n n f <array>
:> alias dist unzip dup [ length ] [ sum ] bi /f v*n
:> ( items probs ) probs
[ swap 1.0 < small large ? push ] each-index
[ small empty? large empty? or ] [
small pop :> s large pop :> l l s alias set-nth
l dup probs [ s probs nth + 1 - dup ] change-nth 1.0 <
small large ? push
] until 1.0 large [ probs set-nth ] with each 1.0 small
[ probs set-nth ] with each n items probs alias vose boa ;