Skip to content

Fix issues found by David in #325 #328

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

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ If you are interested in using AdvancedHMC.jl through a probabilistic programmin
- We presented a poster for AdvancedHMC.jl at [StanCon 2019](https://mc-stan.org/events/stancon2019Cambridge/) in Cambridge, UK. ([pdf](https://github.com/TuringLang/AdvancedHMC.jl/files/3730367/StanCon-AHMC.pdf))

**API CHANGES**
- [v0.5.0] **Breaking!** Convinience constructors for common samplers changed to:
- `HMC(init_ϵ::Float64=init_ϵ, n_leapfrog::Int=n_leapfrog)`
- `NUTS(n_adapts::Int=n_adapts, δ::Float64=δ)`
- `HMCDA(n_adapts::Int=n_adapts, δ::Float64=δ, λ::Float64=λ)`
- [v0.5.0] **Breaking!** Convenience constructors for common samplers changed to:
- `HMC(init_ϵ, n_leapfrog)`
- `NUTS(n_adapts, target_acceptance)`
Copy link
Member Author

@yebai yebai Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if we want to hardcode n_adapts as part of the algorithm. Like the number of MCMC samples, the number of adaption steps should be an argument passed to the AbstractMCMC.sample function.

Related: abstract MCMC PR

- `HMCDA(n_adapts, target_acceptance, integration_time)`
- [v0.2.22] Three functions are renamed.
- `Preconditioner(metric::AbstractMetric)` -> `MassMatrixAdaptor(metric)` and
- `NesterovDualAveraging(δ, integrator::AbstractIntegrator)` -> `StepSizeAdaptor(δ, integrator)`
Expand Down Expand Up @@ -77,15 +77,15 @@ n_samples, n_adapts = 2_000, 1_000
metric = DiagEuclideanMetric(D)
hamiltonian = Hamiltonian(metric, ℓπ, ForwardDiff)

# Define a leapfrog solver, with initial step size chosen heuristically
# Define a leapfrog solver, with the initial step size chosen heuristically
initial_ϵ = find_good_stepsize(hamiltonian, initial_θ)
integrator = Leapfrog(initial_ϵ)

# Define an HMC sampler, with the following components
# Define an HMC sampler with the following components
# - multinomial sampling scheme,
# - generalised No-U-Turn criteria, and
# - windowed adaption for step-size and diagonal mass matrix
proposal = NUTS{MultinomialTS, GeneralisedNoUTurn}(integrator)
proposal = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StanHMCAdaptor(MassMatrixAdaptor(metric), StepSizeAdaptor(0.8, integrator))

# Run the sampler to draw samples from the specified Gaussian, where
Expand Down
5 changes: 2 additions & 3 deletions src/abstractmcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,15 @@ end
make_integrator(spl::HMCSampler, ϵ::Real) = spl.κ.τ.integrator
make_integrator(spl::AbstractHMCSampler, ϵ::Real) = make_integrator(spl.integrator, ϵ)
make_integrator(i::AbstractIntegrator, ϵ::Real) = i
make_integrator(i::Type{<:AbstractIntegrator}, ϵ::Real) = i
make_integrator(i::Symbol, ϵ::Real) = make_integrator(Val(i), ϵ)
make_integrator(i...) = error("Integrator $(typeof(i)) not supported.")
make_integrator(@nospecialize(i), ::Real) = error("Integrator $i not supported.")
make_integrator(i::Val{:leapfrog}, ϵ::Real) = Leapfrog(ϵ)
make_integrator(i::Val{:jitteredleapfrog}, ϵ::Real) = JitteredLeapfrog(ϵ)
make_integrator(i::Val{:temperedleapfrog}, ϵ::Real) = TemperedLeapfrog(ϵ)

#########

make_metric(i...) = error("Metric $(typeof(i)) not supported.")
make_metric(@nospecialize(i), T::Type, d::Int) = error("Metric $(typeof(i)) not supported.")
make_metric(i::Symbol, T::Type, d::Int) = make_metric(Val(i), T, d)
make_metric(i::AbstractMetric, T::Type, d::Int) = i
make_metric(i::Type{AbstractMetric}, T::Type, d::Int) = i
Expand Down