Skip to content

Commit 762e55f

Browse files
authored
Add back the HMC(eps, n_leapfrog) as a convenience constructor (#341)
* Update constructors.jl * Update Project.toml * Update README.md * Update constructors.jl
1 parent 8429077 commit 762e55f

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AdvancedHMC"
22
uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d"
3-
version = "0.5.0"
3+
version = "0.5.1"
44

55
[deps]
66
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ If you are interested in using AdvancedHMC.jl through a probabilistic programmin
1818

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

160160
Equivalent to:

src/constructors.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct HMC{I<:Union{Symbol,AbstractIntegrator},M<:Union{Symbol,AbstractMetric}}
130130
metric::M
131131
end
132132

133+
HMC::Real, n_leapfrog::Int) = HMC(n_leapfrog, Leapfrog(ϵ), :diagonal)
133134
HMC(n_leapfrog; integrator = :leapfrog, metric = :diagonal) =
134135
HMC(n_leapfrog, integrator, metric)
135136

test/constructors.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ include("common.jl")
88

99
@testset "$T" for T in [Float32, Float64]
1010
@testset "$(nameof(typeof(sampler)))" for (sampler, expected) in [
11+
(
12+
HMC(T(0.1), 25),
13+
(
14+
adaptor_type = NoAdaptation,
15+
metric_type = DiagEuclideanMetric{T},
16+
integrator_type = Leapfrog{T},
17+
),
18+
),
1119
(
1220
HMC(25, integrator = Leapfrog(T(0.1))),
1321
(

0 commit comments

Comments
 (0)