Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrete Samplers #79

Open
ParadaCarleton opened this issue May 23, 2021 · 3 comments
Open

Discrete Samplers #79

ParadaCarleton opened this issue May 23, 2021 · 3 comments

Comments

@ParadaCarleton
Copy link

Sampling from discrete variables, as shown here.

@mschauer
Copy link
Owner

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
Copy link
Author

@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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants