Conversation
This reverts commit 2020f2d.
|
AdvancedHMC.jl documentation for PR #481 is available at: |
… gradients, but not changing the schedule). (#473) * initial changes to get a working demo * fix tests, add new ones, and add documentation * fix type * fix some stray tests * delete tmp folder with demo * address review comments * reference interface refactor issue * refactor and fix test rng handling * improve docstring for NutpieVar * remove superfluous white space * fix JET tests * add entry to history, bump version * fix NutpieVar docstring * increase number of tests for mass matrix adaptation --------- Co-authored-by: Markus Hauru <markus@mhauru.org>
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | ||
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | ||
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | |
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | |
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. | |
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | |
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | |
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. |
|
|
||
| - Adapt the mass matrix `metric` of the Hamiltonian dynamics: `mma = MassMatrixAdaptor(metric)` | ||
|
|
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | ||
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | ||
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | |
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | |
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. | |
| currently to be initialized for a `metric` of type `DiagEuclideanMetric` | |
| via `mma = AdvancedHMC.NutpieVar(size(metric); var=copy(metric.M⁻¹))` | |
| until a new interface is introduced in an upcoming breaking release to specify the method of adaptation. |
|
|
||
| - Adapt the step size of the leapfrog integrator `integrator`: `ssa = StepSizeAdaptor(δ, integrator)` | ||
|
|
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
|
|
||
| - The randomness is controlled by `rng`. | ||
|
|
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| z = PhasePoint( | ||
| θ, θ, DualValue(0., θ), DualValue(0., θ) | ||
| ) |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| z = PhasePoint( | |
| θ, θ, DualValue(0., θ), DualValue(0., θ) | |
| ) | |
| z = PhasePoint(θ, θ, DualValue(0.0, θ), DualValue(0.0, θ)) |
| pc1 = MassMatrixAdaptor(UnitEuclideanMetric) # default dim = 2 | ||
| pc2 = MassMatrixAdaptor(DiagEuclideanMetric) | ||
| # Constructing like this until we've settled on a different interface | ||
| pc2_nutpie = NutpieVar{Float64}((2, )) |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| pc2_nutpie = NutpieVar{Float64}((2, )) | |
| pc2_nutpie = NutpieVar{Float64}((2,)) |
| ) | ||
| # Constructing like this until we've settled on a different interface | ||
| adaptor2_nutpie = StanHMCAdaptor( | ||
| NutpieVar{Float64}((2, )), NesterovDualAveraging(0.8, 0.5) |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| NutpieVar{Float64}((2, )), NesterovDualAveraging(0.8, 0.5) | |
| NutpieVar{Float64}((2,)), NesterovDualAveraging(0.8, 0.5) |
| # For this target, Nutpie (without regularization) will arrive at the true variances after two draws. | ||
| res_nutpie = runnuts_nutpie(ℓπ, DiagEuclideanMetric(D)) | ||
| @test res.adaptor.pc.var ≈ σ² rtol = 0.2 | ||
| @test preconditioned_cond(res_nutpie.adaptor.pc, Σ) < preconditioned_cond(res.adaptor.pc, Σ) |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| @test preconditioned_cond(res_nutpie.adaptor.pc, Σ) < preconditioned_cond(res.adaptor.pc, Σ) | |
| @test preconditioned_cond(res_nutpie.adaptor.pc, Σ) < | |
| preconditioned_cond(res.adaptor.pc, Σ) |
| # find the best preconditioner for the target. | ||
| # As these are statistical algorithms, superiority is not always guaranteed, hence this way of testing. | ||
| res_nutpie = runnuts_nutpie(ℓπ, DiagEuclideanMetric(D)) | ||
| n_nutpie_superior += preconditioned_cond(res_nutpie.adaptor.pc, Σ) < preconditioned_cond(res.adaptor.pc, Σ) |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| n_nutpie_superior += preconditioned_cond(res_nutpie.adaptor.pc, Σ) < preconditioned_cond(res.adaptor.pc, Σ) | |
| n_nutpie_superior += | |
| preconditioned_cond(res_nutpie.adaptor.pc, Σ) < | |
| preconditioned_cond(res.adaptor.pc, Σ) |
| return -logZ - dot(r, h.metric._temp) / 2 | ||
| #! Eq (14) of Girolami & Calderhead (2011) | ||
| function ∂H∂r( | ||
| h::Hamiltonian{<:AbstractRiemannianMetric}, θ::AbstractVecOrMat{T}, r::AbstractVecOrMat{T} |
There was a problem hiding this comment.
[JuliaFormatter] reported by reviewdog 🐶
| h::Hamiltonian{<:AbstractRiemannianMetric}, θ::AbstractVecOrMat{T}, r::AbstractVecOrMat{T} | |
| h::Hamiltonian{<:AbstractRiemannianMetric}, | |
| θ::AbstractVecOrMat{T}, | |
| r::AbstractVecOrMat{T}, |
| # println("θ: ", θ) | ||
| # println("H: ", H) | ||
| # end | ||
| G = h.metric.map(H) |
There was a problem hiding this comment.
map isn't defined for an arbitrary Riemannian metric. You'll need to introduce a layer of abstraction.
A abstract metric could have a get_G method which internally calls map if it is a Dense metric
|
This can be closed in favour of #485, right? |
Changes include:
We should consolidate all the RHMC changes so that there is one PR to the main branch.