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

Convinience constructors #325

Merged
merged 109 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
43cfe65
Lab
JaimeRZP Mar 9, 2023
3158bb6
first draft
JaimeRZP Mar 9, 2023
37d6831
cleaning Lab a lil
JaimeRZP Mar 9, 2023
6fe6436
Coded interface in
JaimeRZP Mar 10, 2023
304d401
Coded interface in
JaimeRZP Mar 10, 2023
46f0803
Merge branch 'master' into no_glue_code
JaimeRZP Mar 10, 2023
2f6f2c1
working on no glue code from the other end
JaimeRZP May 30, 2023
dfd5e74
trying stuff
JaimeRZP May 30, 2023
3038441
no glue code abstract mcmc
JaimeRZP May 31, 2023
deb0555
Merge branch 'master' into no_glue_code
JaimeRZP Jun 1, 2023
00b837a
AbstractMCMC working
JaimeRZP Jun 1, 2023
ce96cac
constructors + moving stuff to init_step
JaimeRZP Jun 2, 2023
1f8c5a7
Scaling things
JaimeRZP Jun 5, 2023
612e10b
axing hmc
JaimeRZP Jun 5, 2023
3bbc668
HMC + HMCDA
JaimeRZP Jun 6, 2023
1bffe99
return sampler to master
JaimeRZP Jun 7, 2023
b941529
getmodel
JaimeRZP Jun 8, 2023
8b1f962
small step forward
JaimeRZP Jun 8, 2023
0f45cc8
big step forward
JaimeRZP Jun 8, 2023
3e1c403
huge step forward
JaimeRZP Jun 8, 2023
8fa9fcb
fixed constructors
JaimeRZP Jun 8, 2023
c582abf
constructors reworked
JaimeRZP Jun 9, 2023
39941fd
linking
JaimeRZP Jun 12, 2023
3684a1e
constructors for tors PR
JaimeRZP Jun 20, 2023
62c2096
constructors for tors PR
JaimeRZP Jun 20, 2023
1893e3f
no sampling needed anymore
JaimeRZP Jun 21, 2023
1af622c
no Dynamic PPL
JaimeRZP Jun 21, 2023
acaa289
convinience constructors consensus
JaimeRZP Jun 27, 2023
80f0d8d
kwargs --> args
JaimeRZP Jun 27, 2023
e5f7ead
bring back sample
JaimeRZP Jun 28, 2023
3cb5b07
Update src/abstractmcmc.jl
JaimeRZP Jun 28, 2023
94ebc2b
Update src/constructors.jl
JaimeRZP Jun 28, 2023
4e0ba22
Update src/constructors.jl
JaimeRZP Jun 28, 2023
18c01b0
Update src/abstractmcmc.jl
JaimeRZP Jun 28, 2023
372d384
Update src/constructors.jl
JaimeRZP Jun 28, 2023
fccdcb0
Update src/constructors.jl
JaimeRZP Jun 28, 2023
3d42a21
Update src/constructors.jl
JaimeRZP Jun 28, 2023
9730db2
Update src/constructors.jl
JaimeRZP Jun 28, 2023
77c519a
Update src/constructors.jl
JaimeRZP Jun 28, 2023
9fca18e
Update src/constructors.jl
JaimeRZP Jun 28, 2023
bf3f9b2
Update src/constructors.jl
JaimeRZP Jun 28, 2023
8bd9df7
Update src/constructors.jl
JaimeRZP Jun 28, 2023
19d8f25
Update src/constructors.jl
JaimeRZP Jun 28, 2023
304f051
Update src/constructors.jl
JaimeRZP Jun 28, 2023
b90b2bd
Apply suggestions from code review
JaimeRZP Jun 28, 2023
7dfeb03
format
JaimeRZP Jun 28, 2023
932f296
fixing tests
JaimeRZP Jun 28, 2023
d46c928
legacy sample
JaimeRZP Jun 28, 2023
23bf2f1
load order
JaimeRZP Jun 28, 2023
5002cd9
formatting locally
JaimeRZP Jun 28, 2023
a879d24
HMCSampler
JaimeRZP Jun 28, 2023
7b5a1e9
Taking in some of David s advince
JaimeRZP Jun 28, 2023
5958087
HMCSampler outside of Sample
JaimeRZP Jun 28, 2023
aec0b21
formatted + some new tests
JaimeRZP Jun 29, 2023
217f721
make functions not exported
JaimeRZP Jun 29, 2023
260111e
remove mentions to old constructors
JaimeRZP Jun 29, 2023
737544e
formatting
JaimeRZP Jun 29, 2023
707cef9
save rng in state
JaimeRZP Jun 29, 2023
cd31cf5
demo test
JaimeRZP Jun 29, 2023
dc2382e
specific tests for constructors
JaimeRZP Jun 29, 2023
c307315
remove mention of old constructors in tests
JaimeRZP Jun 29, 2023
2b6bce9
integrator definition missing from test
JaimeRZP Jun 29, 2023
cf6aa31
LeapFrong --> leapfrong
JaimeRZP Jun 29, 2023
d72a3bc
leapfrog --> leapfrong(0.0) for correct type in default
JaimeRZP Jun 29, 2023
d2d2cc7
better typing
JaimeRZP Jun 29, 2023
77763b9
bug
JaimeRZP Jun 29, 2023
4475255
dummy integrator
JaimeRZP Jun 29, 2023
dcbd484
bug
JaimeRZP Jun 29, 2023
52584d0
forgot to change old sample signature
JaimeRZP Jun 29, 2023
0ba2ffc
bug
JaimeRZP Jun 29, 2023
ad1fde3
forgot old sample signature
JaimeRZP Jun 29, 2023
751b36f
retest is broken
JaimeRZP Jun 29, 2023
fc27f89
docs
JaimeRZP Jul 13, 2023
97be5d7
readme
JaimeRZP Jul 14, 2023
27b3747
rm Lab
JaimeRZP Jul 14, 2023
9f79b26
bump vers
JaimeRZP Jul 14, 2023
6fb28f0
move docs to file
JaimeRZP Jul 14, 2023
ce239e3
remove sample
JaimeRZP Jul 17, 2023
4660e5f
Apply Tor's suggestions
JaimeRZP Jul 18, 2023
caf791d
move exports
JaimeRZP Jul 18, 2023
915a92b
Fields in docs
JaimeRZP Jul 18, 2023
3455cab
docs
JaimeRZP Jul 18, 2023
46b6472
no rng in state
JaimeRZP Jul 18, 2023
8dae277
metric type and integration method can be symbols
JaimeRZP Jul 18, 2023
b685cb8
Apply suggestions from code review
JaimeRZP Jul 18, 2023
eda22cb
kwargs
JaimeRZP Jul 18, 2023
18dccc8
Apply suggestions from code review
JaimeRZP Jul 18, 2023
84ce062
bug
JaimeRZP Jul 18, 2023
d0976eb
bug
JaimeRZP Jul 18, 2023
461f842
format
JaimeRZP Jul 18, 2023
fc95e05
David s latest
JaimeRZP Jul 19, 2023
30ec416
Apply suggestions from code review
JaimeRZP Jul 19, 2023
9ac82d9
Update test/sampler.jl
JaimeRZP Jul 19, 2023
79f71e1
Apply suggestions from code review
JaimeRZP Jul 19, 2023
0099c89
Tor s latest
JaimeRZP Jul 19, 2023
fa1afe1
0 means
JaimeRZP Jul 19, 2023
a000b07
bug + float32 init test
JaimeRZP Jul 19, 2023
11c26ca
disentangle steps
JaimeRZP Jul 19, 2023
6d6874f
return of kappa
JaimeRZP Jul 19, 2023
b293dc7
more tests
JaimeRZP Jul 19, 2023
c383c9b
Apply suggestions from code review
JaimeRZP Jul 20, 2023
8ff2c8a
no kwdef on HMCSampler
JaimeRZP Jul 20, 2023
410617b
better get type + get_step_size
JaimeRZP Jul 20, 2023
9e574c6
Merge branch 'convinience_constructors' of https://github.com/TuringL…
JaimeRZP Jul 20, 2023
46b827f
format
JaimeRZP Jul 20, 2023
6eeb9d1
bug
JaimeRZP Jul 20, 2023
64f68bf
metric tweak
JaimeRZP Jul 20, 2023
ae6d5f6
integrator tweaks
JaimeRZP Jul 20, 2023
8320bb4
not needed
JaimeRZP Jul 20, 2023
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
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.4.6"
version = "0.5.0"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +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.2.22] Three functions are renamed.
- `Preconditioner(metric::AbstractMetric)` -> `MassMatrixAdaptor(metric)` and
- `NesterovDualAveraging(δ, integrator::AbstractIntegrator)` -> `StepSizeAdaptor(δ, integrator)`
Expand Down
9 changes: 4 additions & 5 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ Documentation for AdvancedHMC.jl
## Structs
```@docs
ClassicNoUTurn
HMCSampler
HMC
NUTS
HMCDA
```

## Functions

```@docs
sample
```

## Index

```@index
```
43 changes: 7 additions & 36 deletions src/AdvancedHMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,6 @@ export Trajectory,

# Useful defaults

struct NUTS{TS,TC} end

"""
$(SIGNATURES)

Convenient constructor for the no-U-turn sampler (NUTS).
This falls back to `HMCKernel(Trajectory{TS}(int, TC(args...; kwargs...)))` where

- `TS<:Union{MultinomialTS, SliceTS}` is the type for trajectory sampler
- `TC<:Union{ClassicNoUTurn, GeneralisedNoUTurn, StrictGeneralisedNoUTurn}` is the type for termination criterion.

See [`ClassicNoUTurn`](@ref), [`GeneralisedNoUTurn`](@ref) and [`StrictGeneralisedNoUTurn`](@ref) for details in parameters.
"""
NUTS{TS,TC}(int::AbstractIntegrator, args...; kwargs...) where {TS,TC} =
HMCKernel(Trajectory{TS}(int, TC(args...; kwargs...)))
NUTS(int::AbstractIntegrator, args...; kwargs...) =
HMCKernel(Trajectory{MultinomialTS}(int, GeneralisedNoUTurn(args...; kwargs...)))
NUTS(ϵ::AbstractScalarOrVec{<:Real}) =
HMCKernel(Trajectory{MultinomialTS}(Leapfrog(ϵ), GeneralisedNoUTurn()))

export NUTS

# Deprecations for trajectory.jl

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

struct HMCDA{TS} end
JaimeRZP marked this conversation as resolved.
Show resolved Hide resolved
@deprecate HMCDA{TS}(int::AbstractIntegrator, λ) where {TS} HMCKernel(
Trajectory{TS}(int, FixedIntegrationTime(λ)),
)
@deprecate HMCDA(int::AbstractIntegrator, λ) HMCKernel(
Trajectory{EndPointTS}(int, FixedIntegrationTime(λ)),
)
@deprecate HMCDA(ϵ::AbstractScalarOrVec{<:Real}, λ) HMCKernel(
Trajectory{EndPointTS}(Leapfrog(ϵ), FixedIntegrationTime(λ)),
)

@deprecate find_good_eps find_good_stepsize

export StaticTrajectory, HMCDA, find_good_eps
export StaticTrajectory, find_good_eps

include("adaptation/Adaptation.jl")
using .Adaptation
import .Adaptation:
StepSizeAdaptor, MassMatrixAdaptor, StanHMCAdaptor, NesterovDualAveraging
StepSizeAdaptor, MassMatrixAdaptor, StanHMCAdaptor, NesterovDualAveraging, NoAdaptation

# Helpers for initializing adaptors via AHMC structs

Expand Down Expand Up @@ -161,13 +128,17 @@ export StepSizeAdaptor,
WelfordVar,
WelfordCov,
NaiveHMCAdaptor,
StanHMCAdaptor
StanHMCAdaptor,
JaimeRZP marked this conversation as resolved.
Show resolved Hide resolved
NoAdaptation

include("diagnosis.jl")

include("sampler.jl")
export sample

include("constructors.jl")
export HMCSampler, HMC, NUTS, HMCDA

include("abstractmcmc.jl")

## Without explicit AD backend
Expand Down
Loading