Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Harasim dharasim

View GitHub Profile
View compounds.jl
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 Mar 22, 2018
generic unzip function in julia
View unzip_in_julia.jl
"""
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