This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using StatsFuns.RFunctions: betarand, gammarand | |
using LogProbs | |
function categorical_sample(tokens, weights) | |
x = rand() * sum(weights) | |
cum_weights = zero(eltype(weights)) | |
for (t, w) in zip(tokens, weights) | |
cum_weights += w | |
if cum_weights > x | |
return t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
unzip(iter) | |
unzip an iterable object of indexable objects | |
""" | |
function unzip(iter) | |
ntuple(length(first(iter))) do i | |
map(iter) do indexable | |
getindex(indexable, i) | |
end |
NewerOlder