Skip to content

Commit a7edfa9

Browse files
JaimeRZPgithub-actions[bot]torfjelde
authored
Convinience constructors (#325)
* Lab * first draft * cleaning Lab a lil * Coded interface in * Coded interface in * working on no glue code from the other end * trying stuff * no glue code abstract mcmc * AbstractMCMC working * constructors + moving stuff to init_step * Scaling things * axing hmc * HMC + HMCDA * return sampler to master * getmodel * small step forward * big step forward * huge step forward * fixed constructors * constructors reworked * linking * constructors for tors PR * constructors for tors PR * no sampling needed anymore * no Dynamic PPL * convinience constructors consensus * kwargs --> args * bring back sample * Update src/abstractmcmc.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/abstractmcmc.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/constructors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * format * fixing tests * legacy sample * load order * formatting locally * HMCSampler * Taking in some of David s advince * HMCSampler outside of Sample * formatted + some new tests * make functions not exported * remove mentions to old constructors * formatting * save rng in state * demo test * specific tests for constructors * remove mention of old constructors in tests * integrator definition missing from test * LeapFrong --> leapfrong * leapfrog --> leapfrong(0.0) for correct type in default * better typing * bug * dummy integrator * bug * forgot to change old sample signature * bug * forgot old sample signature * retest is broken * docs * readme * rm Lab * bump vers * move docs to file * remove sample * Apply Tor's suggestions Co-authored-by: Tor Erlend Fjelde <[email protected]> * move exports * Fields in docs * docs * no rng in state * metric type and integration method can be symbols * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * kwargs * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * bug * format * David s latest * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update test/sampler.jl Co-authored-by: Tor Erlend Fjelde <[email protected]> * Apply suggestions from code review Co-authored-by: Tor Erlend Fjelde <[email protected]> * Tor s latest * 0 means * bug + float32 init test * disentangle steps * return of kappa * more tests * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * no kwdef on HMCSampler * better get type + get_step_size * format * bug * metric tweak * integrator tweaks * not needed --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tor Erlend Fjelde <[email protected]>
1 parent 4b2bee0 commit a7edfa9

15 files changed

+504
-169
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.4.6"
3+
version = "0.5.0"
44

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

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ If you are interested in using AdvancedHMC.jl through a probabilistic programmin
1717
- 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))
1818

1919
**API CHANGES**
20+
- [v0.5.0] **Breaking!** Convinience constructors for common samplers changed to:
21+
- `HMC(init_ϵ::Float64=init_ϵ, n_leapfrog::Int=n_leapfrog)`
22+
- `NUTS(n_adapts::Int=n_adapts, δ::Float64=δ)`
23+
- `HMCDA(n_adapts::Int=n_adapts, δ::Float64=δ, λ::Float64=λ)`
2024
- [v0.2.22] Three functions are renamed.
2125
- `Preconditioner(metric::AbstractMetric)` -> `MassMatrixAdaptor(metric)` and
2226
- `NesterovDualAveraging(δ, integrator::AbstractIntegrator)` -> `StepSizeAdaptor(δ, integrator)`

docs/src/api.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ Documentation for AdvancedHMC.jl
88
## Structs
99
```@docs
1010
ClassicNoUTurn
11+
HMCSampler
12+
HMC
13+
NUTS
14+
HMCDA
1115
```
1216

1317
## Functions
1418

1519
```@docs
1620
sample
17-
```
18-
19-
## Index
20-
21-
```@index
2221
```

src/AdvancedHMC.jl

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,6 @@ export Trajectory,
6666

6767
# Useful defaults
6868

69-
struct NUTS{TS,TC} end
70-
71-
"""
72-
$(SIGNATURES)
73-
74-
Convenient constructor for the no-U-turn sampler (NUTS).
75-
This falls back to `HMCKernel(Trajectory{TS}(int, TC(args...; kwargs...)))` where
76-
77-
- `TS<:Union{MultinomialTS, SliceTS}` is the type for trajectory sampler
78-
- `TC<:Union{ClassicNoUTurn, GeneralisedNoUTurn, StrictGeneralisedNoUTurn}` is the type for termination criterion.
79-
80-
See [`ClassicNoUTurn`](@ref), [`GeneralisedNoUTurn`](@ref) and [`StrictGeneralisedNoUTurn`](@ref) for details in parameters.
81-
"""
82-
NUTS{TS,TC}(int::AbstractIntegrator, args...; kwargs...) where {TS,TC} =
83-
HMCKernel(Trajectory{TS}(int, TC(args...; kwargs...)))
84-
NUTS(int::AbstractIntegrator, args...; kwargs...) =
85-
HMCKernel(Trajectory{MultinomialTS}(int, GeneralisedNoUTurn(args...; kwargs...)))
86-
NUTS::AbstractScalarOrVec{<:Real}) =
87-
HMCKernel(Trajectory{MultinomialTS}(Leapfrog(ϵ), GeneralisedNoUTurn()))
88-
89-
export NUTS
90-
9169
# Deprecations for trajectory.jl
9270

9371
abstract type AbstractTrajectory end
@@ -103,25 +81,14 @@ struct StaticTrajectory{TS} end
10381
Trajectory{EndPointTS}(Leapfrog(ϵ), FixedNSteps(L)),
10482
)
10583

106-
struct HMCDA{TS} end
107-
@deprecate HMCDA{TS}(int::AbstractIntegrator, λ) where {TS} HMCKernel(
108-
Trajectory{TS}(int, FixedIntegrationTime(λ)),
109-
)
110-
@deprecate HMCDA(int::AbstractIntegrator, λ) HMCKernel(
111-
Trajectory{EndPointTS}(int, FixedIntegrationTime(λ)),
112-
)
113-
@deprecate HMCDA::AbstractScalarOrVec{<:Real}, λ) HMCKernel(
114-
Trajectory{EndPointTS}(Leapfrog(ϵ), FixedIntegrationTime(λ)),
115-
)
116-
11784
@deprecate find_good_eps find_good_stepsize
11885

119-
export StaticTrajectory, HMCDA, find_good_eps
86+
export StaticTrajectory, find_good_eps
12087

12188
include("adaptation/Adaptation.jl")
12289
using .Adaptation
12390
import .Adaptation:
124-
StepSizeAdaptor, MassMatrixAdaptor, StanHMCAdaptor, NesterovDualAveraging
91+
StepSizeAdaptor, MassMatrixAdaptor, StanHMCAdaptor, NesterovDualAveraging, NoAdaptation
12592

12693
# Helpers for initializing adaptors via AHMC structs
12794

@@ -161,13 +128,17 @@ export StepSizeAdaptor,
161128
WelfordVar,
162129
WelfordCov,
163130
NaiveHMCAdaptor,
164-
StanHMCAdaptor
131+
StanHMCAdaptor,
132+
NoAdaptation
165133

166134
include("diagnosis.jl")
167135

168136
include("sampler.jl")
169137
export sample
170138

139+
include("constructors.jl")
140+
export HMCSampler, HMC, NUTS, HMCDA
141+
171142
include("abstractmcmc.jl")
172143

173144
## Without explicit AD backend

0 commit comments

Comments
 (0)