Skip to content

Parallelization using Carlo.jl #12

@ohno

Description

@ohno

Please consider parallelizing this package using Carlo.jl. Should I change metropolis!?

# one-step x many-walkers
function metropolis!(f::Function, R::Vector{<:Vector}; type = typeof(first(first(R))), d::Real = one(type))
# initialize
half = type(1 // 2)
n_dim = length(first(R))
# Metropolis-walk
for i in keys(R)
# shift
Δr = d * (rand(type, n_dim) .- half) # [-d/2,d/2)ⁿ
r_old = R[i]
f_old = f(r_old)
r_new = r_old .+ Δr
f_new = f(r_new)
# accept
p = min(1, f_new / f_old)
if rand() < p
R[i] = r_new
end
end
return
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions