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

Work around compiler bug - Julia issue 34232 #152

Merged
merged 4 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/trajectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,29 @@ find_good_eps(
max_n_iters::Int=100
) where {T<:AbstractFloat} = find_good_eps(GLOBAL_RNG, h, θ; max_n_iters=max_n_iters)

_rand(rng::AbstractRNG) = rand(rng)
_rand(rng::AbstractVector{<:AbstractRNG}) = rand.(rng)

"""
Perform MH acceptance based on energy, i.e. negative log probability.
"""
function mh_accept_ratio(
rng::Union{AbstractRNG,AbstractVector{<:AbstractRNG}},
Horiginal::AbstractScalarOrVec{<:T},
Hproposal::AbstractScalarOrVec{<:T}
rng::AbstractRNG,
Horiginal::T,
Hproposal::T,
mohamed82008 marked this conversation as resolved.
Show resolved Hide resolved
) where {T <: AbstractFloat}
α = min(1.0, exp(Horiginal - Hproposal))
accept = rand(rng) < α
return accept, α
end
function mh_accept_ratio(
rng::Union{AbstractRNG, AbstractVector{<:AbstractRNG}},
Horiginal::AbstractVector{<:T},
Hproposal::AbstractVector{<:T},
) where {T<:AbstractFloat}
α = min.(1.0, exp.(Horiginal .- Hproposal))
accept = _rand(rng) .< α
return accept, α
end
_rand(rng::AbstractRNG) = rand(rng)
_rand(rng::AbstractVector{<:AbstractRNG}) = rand.(rng)

####
#### Adaption
Expand Down
4 changes: 2 additions & 2 deletions test/adaptation/precond.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ let D=10
return ℓπ, ∂ℓπ∂θ
end

function runnuts(ℓπ, ∂ℓπ∂θ, metric; n_samples=2_000)
n_adapts = 1_000
function runnuts(ℓπ, ∂ℓπ∂θ, metric; n_samples=3_000)
n_adapts = 1_500

θ_init = rand(D)

Expand Down