Skip to content

Instantly share code, notes, and snippets.

View dharasim's full-sized avatar

Daniel Harasim dharasim

View GitHub Profile
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
@dharasim
dharasim / unzip_in_julia.jl
Last active March 22, 2018 13:25
generic unzip function in julia
"""
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