mschauer / ZigZagBoomerang.jl

Sleek implementations of the ZigZag, Boomerang and other assorted piecewise deterministic Markov processes for Markov Chain Monte Carlo including Sticky PDMPs for variable selection
MIT License
100 stars 7 forks source link

Discrete Samplers #79

Open ParadaCarleton opened 3 years ago

ParadaCarleton commented 3 years ago

Sampling from discrete variables, as shown here.

mschauer commented 3 years ago

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

ParadaCarleton commented 3 years ago

@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.

mschauer commented 3 years ago

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.