-
Notifications
You must be signed in to change notification settings - Fork 46
Make ∂H∂r consistent with ∂H∂θ #458
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -72,9 +72,10 @@ | |||
end | ||||
#! Eq (17) of Girolami & Calderhead (2011) | ||||
θ_full = copy(θ_init) | ||||
term_1 = ∂H∂r(h, θ_init, r_half) # unchanged across the loop | ||||
term_1 = ∂H∂r(h, θ_init, r_half).gradient # unchanged across the loop | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This computes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh, I suddenly realize the riemannian manifold HMC is not included in AdvancedHMC yet, this file is not included in the package, see AdvancedHMC.jl/src/AdvancedHMC.jl Line 50 in 5a562e0
I think we might start with #439, which is ready to get in now. |
||||
for j in 1:(lf.n) | ||||
θ_full = θ_init + ϵ / 2 * (term_1 + ∂H∂r(h, θ_full, r_half)) | ||||
grad_r = ∂H∂r(h, θ_full, r_half).gradient | ||||
θ_full = θ_init + ϵ / 2 * (term_1 + grad_r) | ||||
# println("θ_full :", θ_full) | ||||
end | ||||
#! Eq (18) of Girolami & Calderhead (2011) | ||||
|
@@ -103,7 +104,6 @@ | |||
return res | ||||
end | ||||
|
||||
# TODO Make the order of θ and r consistent with neg_energy | ||||
∂H∂θ(h::Hamiltonian, θ::AbstractVecOrMat, r::AbstractVecOrMat) = ∂H∂θ(h, θ) | ||||
∂H∂r(h::Hamiltonian, θ::AbstractVecOrMat, r::AbstractVecOrMat) = ∂H∂r(h, r) | ||||
|
||||
|
@@ -227,19 +227,15 @@ | |||
# QUES Do we want to change everything to position dependent by default? | ||||
# Add θ to ∂H∂r for DenseRiemannianMetric | ||||
function phasepoint( | ||||
h::Hamiltonian{<:DenseRiemannianMetric}, | ||||
θ::T, | ||||
r::T; | ||||
ℓπ=∂H∂θ(h, θ), | ||||
ℓκ=DualValue(neg_energy(h, r, θ), ∂H∂r(h, θ, r)), | ||||
h::Hamiltonian{<:DenseRiemannianMetric}, θ::T, r::T; ℓπ=∂H∂θ(h, θ), ℓκ=∂H∂r(h, θ, r) | ||||
) where {T<:AbstractVecOrMat} | ||||
return PhasePoint(θ, r, ℓπ, ℓκ) | ||||
end | ||||
|
||||
# Negative kinetic energy | ||||
#! Eq (13) of Girolami & Calderhead (2011) | ||||
function neg_energy( | ||||
h::Hamiltonian{<:DenseRiemannianMetric}, r::T, θ::T | ||||
h::Hamiltonian{<:DenseRiemannianMetric}, θ::T, r::T | ||||
) where {T<:AbstractVecOrMat} | ||||
G = h.metric.map(h.metric.G(θ)) | ||||
D = size(G, 1) | ||||
|
@@ -347,12 +343,6 @@ | |||
h::Hamiltonian{<:DenseRiemannianMetric}, θ::AbstractVecOrMat, r::AbstractVecOrMat | ||||
) | ||||
H = h.metric.G(θ) | ||||
# if !all(isfinite, H) | ||||
# println("θ: ", θ) | ||||
# println("H: ", H) | ||||
# end | ||||
G = h.metric.map(H) | ||||
# return inv(G) * r | ||||
# println("G \ r: ", G \ r) | ||||
return G \ r # NOTE it's actually pretty weird that ∂H∂θ returns DualValue but ∂H∂r doesn't | ||||
return DualValue(neg_energy(h, θ, r), G \ r) | ||||
end |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remove these too.
AdvancedHMC.jl/src/riemannian/hamiltonian.jl
Lines 106 to 108 in 5a562e0