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

Don't pass Hamiltonian around, but instead metric and DifferentiableDensityModel. #273

Open
torfjelde opened this issue Jul 15, 2021 · 0 comments

Comments

@torfjelde
Copy link
Member

A lot of the code in AHMC "unnecessarily" requires a Hamiltonian, i.e. a struct containing metric, ℓπ, and ∂ℓπ∂θ, to be passed around. This is a bit awkward for the following reasons:

  • Only the metric actually changes during sampling. ℓπ and ∂ℓπ∂θ are of course fixed. Hence it's a bit more natural to simply keep track of the metric rather than the full Hamiltonian object.
  • Even when using the AbstractMCMC-interface, we unnecessarily need to construct the Hamiltonian for to access certain functionality, e.g. find_good_stepsize.

IMO it's a more composable if we instead pass around metric and DifferentiableDensityModel (which contains the latter two), or, in more generality, a AbstractMCMC.AbstractModel, and the Hamiltonian should be constructed when needed e.g. at the call-site of AdvancedHMC.step or maybe even add a default impl for DifferentiableDensityModel

function step(int::AbstractIntegrator, model::DifferentiableDensityModel, metric::AbstractMetric, z::P, n_steps::Int=1; kwargs...)
    h = Hamiltonian(model, metric)
    return step(int, h, z, n_steps; kwargs...)
end

This would allow for futher extensions down the road, e.g. maybe it's useful to allow some other AbstractModel to be used, etc. But also it would mean that we can share more code between the impl of AbstractMCMC.jl-interface and the "standard" interface of AHMC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant