-
Notifications
You must be signed in to change notification settings - Fork 48
Minimal refactor of #439 for merging RHMC implementation into main #484
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?
Conversation
| - `premetric`: a function which, for a given posterior position `pos`, computes either | ||
| a) a symmetric, **positive definite** matrix acting as the position dependent Riemannian metric (if `metric_map = IdentityMap()`), or | ||
| b) a symmetric, **not necessarily positive definite** matrix acting as the position dependent Riemannian metric after being passed through the `metric_map` argument, which will have to ensure that its return value *is* positive definite (like `metric_map = SoftAbsMap(alpha)`), |
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.
[JuliaFormatter] reported by reviewdog 🐶
| - `premetric`: a function which, for a given posterior position `pos`, computes either | |
| a) a symmetric, **positive definite** matrix acting as the position dependent Riemannian metric (if `metric_map = IdentityMap()`), or | |
| b) a symmetric, **not necessarily positive definite** matrix acting as the position dependent Riemannian metric after being passed through the `metric_map` argument, which will have to ensure that its return value *is* positive definite (like `metric_map = SoftAbsMap(alpha)`), | |
| - `premetric`: a function which, for a given posterior position `pos`, computes either | |
| a) a symmetric, **positive definite** matrix acting as the position dependent Riemannian metric (if `metric_map = IdentityMap()`), or | |
| b) a symmetric, **not necessarily positive definite** matrix acting as the position dependent Riemannian metric after being passed through the `metric_map` argument, which will have to ensure that its return value *is* positive definite (like `metric_map = SoftAbsMap(alpha)`), |
|
|
||
| ϵ = fwd ? step_size(lf) : -step_size(lf) | ||
| ϵ = ϵ' | ||
|
|
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.
[JuliaFormatter] reported by reviewdog 🐶
| h::Hamiltonian{<:DenseRiemannianMetric{T,<:IdentityMap},<:GaussianKinetic}, | ||
| θ::AbstractVector{T}, | ||
| r::AbstractVector{T}; | ||
| cache=nothing |
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.
[JuliaFormatter] reported by reviewdog 🐶
| cache=nothing | |
| cache=nothing, |
| r::AbstractVector{T}; | ||
| cache=nothing | ||
| ) where {T} | ||
| cache = @something cache begin |
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.
[JuliaFormatter] reported by reviewdog 🐶
| cache = @something cache begin | |
| cache = @something cache begin |
| rv1 = map(eachindex(log_density_gradient)) do i | ||
| -log_density_gradient[i] + .5 * tr_product(inv_metric, metric_sensitivities[:, :, i]) |
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.
[JuliaFormatter] reported by reviewdog 🐶
| rv1 = map(eachindex(log_density_gradient)) do i | |
| -log_density_gradient[i] + .5 * tr_product(inv_metric, metric_sensitivities[:, :, i]) | |
| rv1 = map(eachindex(log_density_gradient)) do i | |
| -log_density_gradient[i] + | |
| 0.5 * tr_product(inv_metric, metric_sensitivities[:, :, i]) |
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | ||
| .5 * tr_product(cache.metric_sensitivities[:, :, i], inv_metric_r) | ||
| end | ||
| #! Eq (18) of Girolami & Calderhead (2011) | ||
| (; value, gradient) = ∂H∂θ(h, θ_full, r_half) | ||
| r_full = r_half - ϵ / 2 * gradient | ||
| # println("r_full: ", r_full) | ||
| # Tempering | ||
| #r = temper(lf, r, (i=i, is_half=false), n_steps) | ||
| # Create a new phase point by caching the logdensity and gradient | ||
| z = phasepoint(h, θ_full, r_full; ℓπ=DualValue(value, gradient)) | ||
| # Update result | ||
| if FullTraj | ||
| res[i] = z | ||
| ), cache |
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.
[JuliaFormatter] reported by reviewdog 🐶
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | |
| .5 * tr_product(cache.metric_sensitivities[:, :, i], inv_metric_r) | |
| end | |
| #! Eq (18) of Girolami & Calderhead (2011) | |
| (; value, gradient) = ∂H∂θ(h, θ_full, r_half) | |
| r_full = r_half - ϵ / 2 * gradient | |
| # println("r_full: ", r_full) | |
| # Tempering | |
| #r = temper(lf, r, (i=i, is_half=false), n_steps) | |
| # Create a new phase point by caching the logdensity and gradient | |
| z = phasepoint(h, θ_full, r_full; ℓπ=DualValue(value, gradient)) | |
| # Update result | |
| if FullTraj | |
| res[i] = z | |
| ), cache | |
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | |
| 0.5 * tr_product(cache.metric_sensitivities[:, :, i], inv_metric_r) | |
| end, | |
| ), | |
| cache |
| r::AbstractVector{T}; | ||
| cache=nothing, | ||
| ) where {T} | ||
| cache = @something cache begin |
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.
[JuliaFormatter] reported by reviewdog 🐶
| cache = @something cache begin | |
| cache = @something cache begin |
| rv1 = map(eachindex(log_density_gradient)) do i | ||
| -log_density_gradient[i] + .5 * tr_product(tmpm, premetric_sensitivities[:, :, i]) |
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.
[JuliaFormatter] reported by reviewdog 🐶
| rv1 = map(eachindex(log_density_gradient)) do i | |
| -log_density_gradient[i] + .5 * tr_product(tmpm, premetric_sensitivities[:, :, i]) | |
| rv1 = map(eachindex(log_density_gradient)) do i | |
| -log_density_gradient[i] + 0.5 * tr_product(tmpm, premetric_sensitivities[:, :, i]) |
| rv1 = map(eachindex(log_density_gradient)) do i | ||
| -log_density_gradient[i] + .5 * tr_product(tmpm, premetric_sensitivities[:, :, i]) | ||
| end | ||
| (;log_density, Q, softabsλ, tmpv, tmpm, rv1) |
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.
[JuliaFormatter] reported by reviewdog 🐶
| (;log_density, Q, softabsλ, tmpv, tmpm, rv1) | |
| (; log_density, Q, softabsλ, tmpv, tmpm, rv1) |
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | ||
| .5 * tr_product(cache.tmpm, cache.premetric_sensitivities[:, :, i]) | ||
| end | ||
| ), cache |
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.
[JuliaFormatter] reported by reviewdog 🐶
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | |
| .5 * tr_product(cache.tmpm, cache.premetric_sensitivities[:, :, i]) | |
| end | |
| ), cache | |
| cache.rv1 .- Base.broadcasted(eachindex(cache.rv1)) do i | |
| 0.5 * tr_product(cache.tmpm, cache.premetric_sensitivities[:, :, i]) | |
| end, | |
| ), | |
| cache |
|
AdvancedHMC.jl documentation for PR #484 is available at: |
Thinks were to messy for my tastes to merge as is or with small changes. Supersedes #439.