Skip to content

Commit

Permalink
Add back the HMC(eps, n_leapfrog) as a convenience constructor (#341)
Browse files Browse the repository at this point in the history
* Update constructors.jl

* Update Project.toml

* Update README.md

* Update constructors.jl
  • Loading branch information
yebai authored Jul 27, 2023
1 parent 8429077 commit 762e55f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AdvancedHMC"
uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d"
version = "0.5.0"
version = "0.5.1"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ If you are interested in using AdvancedHMC.jl through a probabilistic programmin

**API CHANGES**
- [v0.5.0] **Breaking!** Convenience constructors for common samplers changed to:
- `HMC(n_leapfrog)`
- `NUTS(target_acceptance)`
- `HMCDA(target_acceptance, integration_time)`
- `HMC(leapfrog_stepsize::Real, n_leapfrog::Int)`
- `NUTS(target_acceptance::Real)`
- `HMCDA(target_acceptance::Real, integration_time::Real)`
- [v0.2.22] Three functions are renamed.
- `Preconditioner(metric::AbstractMetric)` -> `MassMatrixAdaptor(metric)` and
- `NesterovDualAveraging(δ, integrator::AbstractIntegrator)` -> `StepSizeAdaptor(δ, integrator)`
Expand Down Expand Up @@ -153,8 +153,8 @@ In the previous examples, we built the sampler by manually specifying the integr
```julia
# HMC Sampler
# step size, number of leapfrog steps
n_leapfrog, lf_integrator = 25, Leapfrog(0.1)
hmc = HMC(n_leapfrog, integrator = lf_integrator)
n_leapfrog, ϵ = 25, 0.1
hmc = HMC(ϵ, n_leapfrog)
```

Equivalent to:
Expand Down
1 change: 1 addition & 0 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct HMC{I<:Union{Symbol,AbstractIntegrator},M<:Union{Symbol,AbstractMetric}}
metric::M
end

HMC::Real, n_leapfrog::Int) = HMC(n_leapfrog, Leapfrog(ϵ), :diagonal)
HMC(n_leapfrog; integrator = :leapfrog, metric = :diagonal) =
HMC(n_leapfrog, integrator, metric)

Expand Down
8 changes: 8 additions & 0 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ include("common.jl")

@testset "$T" for T in [Float32, Float64]
@testset "$(nameof(typeof(sampler)))" for (sampler, expected) in [
(
HMC(T(0.1), 25),
(
adaptor_type = NoAdaptation,
metric_type = DiagEuclideanMetric{T},
integrator_type = Leapfrog{T},
),
),
(
HMC(25, integrator = Leapfrog(T(0.1))),
(
Expand Down

2 comments on commit 762e55f

@yebai
Copy link
Member Author

@yebai yebai commented on 762e55f Jul 27, 2023

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/88465

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" 762e55f894d142495a41a6eba0eed9201da0a600
git push origin v0.5.1

Please sign in to comment.