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

Support AdvancedHMC v0.5 and Turing v0.27 #169

Merged
merged 7 commits into from
Dec 1, 2023
Merged
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
[compat]
Accessors = "0.1"
Distributions = "0.25"
DynamicPPL = "0.20, 0.21, 0.22, 0.23"
DynamicPPL = "0.21, 0.22, 0.23, 0.24"
Folds = "0.2"
ForwardDiff = "0.10"
IrrationalConstants = "0.1.1, 0.2"
Expand All @@ -46,7 +46,7 @@ SciMLBase = "1.8.1"
Statistics = "1.6"
StatsBase = "0.33, 0.34"
Transducers = "0.4.5"
Turing = "0.24, 0.25, 0.26"
Turing = "0.24, 0.25, 0.26, 0.27"
UnPack = "1"
julia = "1.6"

Expand Down
4 changes: 2 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TransformedLogDensities = "f9bc47f6-f3f8-4f3b-ab21-f8bc73906f26"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"

[compat]
AdvancedHMC = "0.4"
AdvancedHMC = "0.4, 0.5"
Documenter = "1"
DynamicHMC = "3"
ForwardDiff = "0.10"
Expand All @@ -26,4 +26,4 @@ StatsFuns = "0.9, 1"
StatsPlots = "0.14, 0.15"
TransformVariables = "0.6, 0.7, 0.8"
TransformedLogDensities = "1"
Turing = "0.24, 0.25, 0.26"
Turing = "0.24, 0.25, 0.26, 0.27"
12 changes: 6 additions & 6 deletions docs/src/examples/initializing-hmc.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ metric = DiagEuclideanMetric(dim)
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, init_params)
integrator = Leapfrog(ϵ)
proposal = AdvancedHMC.NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples_ahmc1, stats_ahmc1 = sample(
hamiltonian,
proposal,
kernel,
init_params,
ndraws + nadapts,
adaptor,
Expand All @@ -196,11 +196,11 @@ metric = DenseEuclideanMetric(Matrix(inv_metric))
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, init_params)
integrator = Leapfrog(ϵ)
proposal = AdvancedHMC.NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples_ahmc2, stats_ahmc2 = sample(
hamiltonian,
proposal,
kernel,
init_params,
ndraws + nadapts,
adaptor,
Expand All @@ -220,11 +220,11 @@ metric = Pathfinder.RankUpdateEuclideanMetric(inv_metric)
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, init_params)
integrator = Leapfrog(ϵ)
proposal = AdvancedHMC.NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples_ahmc3, stats_ahmc3 = sample(
hamiltonian,
proposal,
kernel,
init_params,
ndraws + nadapts,
adaptor,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/turing.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ metric = Pathfinder.RankUpdateEuclideanMetric(inv_metric)
hamiltonian = Hamiltonian(metric, ℓπ, ∂ℓπ∂θ)
ϵ = find_good_stepsize(hamiltonian, init_params[1])
integrator = Leapfrog(ϵ)
proposal = AdvancedHMC.NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples, stats = sample(
hamiltonian,
proposal,
kernel,
init_params[1],
ndraws + nadapts,
adaptor,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/AdvancedHMC/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TransformVariables = "84d833dd-6860-57f9-a1a7-6da5db126cff"
TransformedLogDensities = "f9bc47f6-f3f8-4f3b-ab21-f8bc73906f26"

[compat]
AdvancedHMC = "0.4"
AdvancedHMC = "0.4, 0.5"
Distributions = "0.25"
ForwardDiff = "0.10"
LogDensityProblems = "1, 2"
Expand Down
30 changes: 15 additions & 15 deletions test/integration/AdvancedHMC/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using AdvancedHMC,
TransformVariables
using TransformedLogDensities: TransformedLogDensity

Random.seed!(0)
Random.seed!(2)

struct RegressionProblem{X,Y}
x::X
Expand Down Expand Up @@ -53,7 +53,7 @@ function compare_estimates(xs1, xs2, α=0.05)
p = α / 2
m1, s1 = mean_and_mcse(xs1)
m2, s2 = mean_and_mcse(xs2)
zs = @. (m1 - m2) / sqrt(s1^2 + s2^2)
zs = @. (m1 - m2) / hypot(s1, s2)
@test all(norminvcdf(p) .< zs .< norminvccdf(p))
end

Expand Down Expand Up @@ -106,7 +106,7 @@ end
end

@testset "sample" begin
ndraws = 1_000
ndraws = 10_000
nadapts = 500
nparams = 5
x = 0:0.01:1
Expand All @@ -122,15 +122,15 @@ end
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, θ₀)
integrator = Leapfrog(ϵ)
proposal = NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StanHMCAdaptor(
MassMatrixAdaptor(metric), StepSizeAdaptor(0.8, integrator)
)
samples1, stats1 = sample(
hamiltonian,
proposal,
kernel,
θ₀,
ndraws,
ndraws + nadapts,
adaptor,
nadapts;
drop_warmup=true,
Expand All @@ -144,13 +144,13 @@ end
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, θ₀)
integrator = Leapfrog(ϵ)
proposal = NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples2, stats2 = sample(
hamiltonian,
proposal,
kernel,
result_pf.draws[:, 1],
ndraws,
ndraws + nadapts,
adaptor,
nadapts;
drop_warmup=true,
Expand All @@ -164,13 +164,13 @@ end
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, θ₀)
integrator = Leapfrog(ϵ)
proposal = NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples3, stats3 = sample(
hamiltonian,
proposal,
kernel,
result_pf.draws[:, 1],
ndraws,
ndraws + nadapts,
adaptor,
nadapts;
drop_warmup=true,
Expand All @@ -184,13 +184,13 @@ end
hamiltonian = Hamiltonian(metric, ∇P)
ϵ = find_good_stepsize(hamiltonian, θ₀)
integrator = Leapfrog(ϵ)
proposal = NUTS{MultinomialTS,GeneralisedNoUTurn}(integrator)
kernel = HMCKernel(Trajectory{MultinomialTS}(integrator, GeneralisedNoUTurn()))
adaptor = StepSizeAdaptor(0.8, integrator)
samples4, stats4 = sample(
hamiltonian,
proposal,
kernel,
result_pf.draws[:, 1],
ndraws,
ndraws + nadapts,
adaptor,
nadapts;
drop_warmup=true,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/DynamicHMC/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function compare_estimates(xs1, xs2, α=0.05)
p = α / 2
m1, s1 = mean_and_mcse(xs1)
m2, s2 = mean_and_mcse(xs2)
zs = @. (m1 - m2) / sqrt(s1^2 + s2^2)
zs = @. (m1 - m2) / hypot(s1, s2)
@test all(norminvcdf(p) .< zs .< norminvccdf(p))
end

Expand Down Expand Up @@ -76,7 +76,7 @@ end
end

@testset "DynamicHMC.mcmc_with_warmup" begin
ndraws = 1_000
ndraws = 10_000
x = 0:0.01:1
y = sin.(x) .+ randn.() .* 0.2 .+ x
X = [x x .^ 2 x .^ 3]
Expand Down
2 changes: 1 addition & 1 deletion test/integration/Turing/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"

[compat]
Pathfinder = "0.5, 0.6, 0.7"
Turing = "0.24, 0.25, 0.26"
Turing = "0.24, 0.25, 0.26, 0.27"
julia = "1.6"
Loading