ZigZagBoomerang.jl icon indicating copy to clipboard operation
ZigZagBoomerang.jl copied to clipboard

Discrete Samplers

Open ParadaCarleton opened this issue 4 years ago • 3 comments

Sampling from discrete variables, as shown here.

ParadaCarleton avatar May 23 '21 15:05 ParadaCarleton

Demo algorithm 3:

n = 6
Z = 1:n
p = rand(n-2)
p /= sum(p)
p = [0; p; 0]
z = 2
d = 1
zs = [z]
t = 0.0
ts = [t]
iterations = 10000
for iter in 1:iterations
    t += randexp()
    if p[z+d] > p[z] || rand() < p[z+d]/p[z]
        z += d
    else
        d *= -1
    end
    push!(zs, z)
    push!(ts, t)
end
push!(ts, t[end]+randexp())
using StatsBase
T = ts[end]
Δts = diff(ts)
p̂ = zero(p)
for (Δt, z) in zip(Δts, zs)
    p̂[z] += Δt/T
end
[p p̂]

@SebaGraz

mschauer avatar May 23 '21 16:05 mschauer

@mschauer Did this end up getting done? Someone on the Slack is looking for discrete mixed/continuous sampling and I want to know whether I should point them at this.

ParadaCarleton avatar Jul 11 '21 23:07 ParadaCarleton

No, we are working on it. Though we have an academic interest here: so while we can't offer an implementation ready to use we are looking for interesting use cases to try out.

mschauer avatar Jul 12 '21 09:07 mschauer