Skip to content

Commit

Permalink
Bump package, docs, and test compats (#134)
Browse files Browse the repository at this point in the history
* Use MCMCDiagnosticTools in tests

* Bump IrrationalConstants compat

* Bump TransformVariables compat

* Increment patch number
  • Loading branch information
sethaxen authored Feb 28, 2023
1 parent 1e596a4 commit 7bc83fb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Pathfinder"
uuid = "b1d3bc72-d0e7-4279-b92f-7fa5d6d2d454"
authors = ["Seth Axen <[email protected]> and contributors"]
version = "0.7.1"
version = "0.7.2"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down Expand Up @@ -41,7 +41,7 @@ Distributions = "0.25"
DynamicPPL = "0.20, 0.21"
Folds = "0.2"
ForwardDiff = "0.10"
IrrationalConstants = "0.1.1"
IrrationalConstants = "0.1.1, 0.2"
LogDensityProblems = "2"
MCMCChains = "5"
Optim = "1.4"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ LogDensityProblemsAD = "1, 2"
Pathfinder = "0.7"
StatsFuns = "0.9, 1"
StatsPlots = "0.14, 0.15"
TransformVariables = "0.6, 0.7"
TransformVariables = "0.6, 0.7, 0.8"
TransformedLogDensities = "1"
Turing = "0.21, 0.22, 0.23, 0.24"
4 changes: 2 additions & 2 deletions test/integration/AdvancedHMC/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Distributions = "0.25"
ForwardDiff = "0.10"
LogDensityProblems = "1, 2"
LogDensityProblemsAD = "1"
MCMCDiagnosticTools = "0.1.3, 0.2"
MCMCDiagnosticTools = "0.3"
Optim = "1.4"
Pathfinder = "0.7"
StatsFuns = "0.9, 1"
TransformVariables = "0.6, 0.7"
TransformVariables = "0.6, 0.7, 0.8"
TransformedLogDensities = "1"
julia = "1.6"
29 changes: 16 additions & 13 deletions test/integration/AdvancedHMC/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ function (prob::RegressionProblem)(θ)
return lp
end

function mean_and_mcse(f, θs)
zs = map(f, θs)
ms = mean(zs)
ses = map(mcse, eachrow(reduce(hcat, zs)))
function as_draw_array(θs)
draw_param_mat = transpose(reduce(hcat, θs))
return reshape(draw_param_mat, size(draw_param_mat, 1), 1, size(draw_param_mat, 2))
end

function mean_and_mcse(θs)
ms = dropdims(mean(θs; dims=(1, 2)); dims=(1, 2))
ses = mcse(θs)
return ms, ses
end

function compare_estimates(f, xs1, xs2, α=0.05)
function compare_estimates(xs1, xs2, α=0.05)
nparams = length(first(xs1))
α /= nparams # bonferroni correction
p = α / 2
m1, s1 = mean_and_mcse(f, xs1)
m2, s2 = mean_and_mcse(f, xs2)
m1, s1 = mean_and_mcse(xs1)
m2, s2 = mean_and_mcse(xs2)
zs = @. (m1 - m2) / sqrt(s1^2 + s2^2)
@test all(norminvcdf(p) .< zs .< norminvccdf(p))
end
Expand Down Expand Up @@ -96,9 +100,8 @@ end
@test AdvancedHMC.∂H∂r(h, r) AdvancedHMC.∂H∂r(h_dense, r)
kinetic = AdvancedHMC.GaussianKinetic()
compare_estimates(
identity,
[rand(metric, kinetic) for _ in 1:10_000],
[rand(metric_dense, kinetic) for _ in 1:10_000],
as_draw_array([rand(metric, kinetic) for _ in 1:10_000]),
as_draw_array([rand(metric_dense, kinetic) for _ in 1:10_000]),
)
end

Expand Down Expand Up @@ -153,7 +156,7 @@ end
drop_warmup=true,
progress=false,
)
compare_estimates(identity, samples2, samples1)
compare_estimates(as_draw_array(samples2), as_draw_array(samples1))
end

@testset "Initial point and metric" begin
Expand All @@ -173,7 +176,7 @@ end
drop_warmup=true,
progress=false,
)
compare_estimates(identity, samples3, samples1)
compare_estimates(as_draw_array(samples3), as_draw_array(samples1))
end

@testset "Initial point and final metric" begin
Expand All @@ -193,7 +196,7 @@ end
drop_warmup=true,
progress=false,
)
compare_estimates(identity, samples4, samples1)
compare_estimates(as_draw_array(samples4), as_draw_array(samples1))
end
end
end
4 changes: 2 additions & 2 deletions test/integration/DynamicHMC/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ TransformedLogDensities = "f9bc47f6-f3f8-4f3b-ab21-f8bc73906f26"
DynamicHMC = "3"
LogDensityProblems = "1, 2"
LogDensityProblemsAD = "1"
MCMCDiagnosticTools = "0.1.3, 0.2"
MCMCDiagnosticTools = "0.3"
Optim = "1.4"
Pathfinder = "0.7"
StatsFuns = "0.9, 1"
TransformVariables = "0.6, 0.7"
TransformVariables = "0.6, 0.7, 0.8"
TransformedLogDensities = "1"
julia = "1.6"
22 changes: 12 additions & 10 deletions test/integration/DynamicHMC/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ function (prob::RegressionProblem)(θ)
return lp
end

function mean_and_mcse(f, θs)
zs = map(f, θs)
ms = mean(zs; dims=2)
ses = map(mcse, eachrow(zs))
function mean_and_mcse(θs)
ms = dropdims(mean(θs; dims=(1, 2)); dims=(1, 2))
ses = mcse(θs)
return ms, ses
end

function compare_estimates(f, xs1, xs2, α=0.05)
function compare_estimates(xs1, xs2, α=0.05)
nparams = first(size(xs1))
α /= nparams # bonferroni correction
p = α / 2
m1, s1 = mean_and_mcse(f, xs1)
m2, s2 = mean_and_mcse(f, xs2)
m1, s1 = mean_and_mcse(xs1)
m2, s2 = mean_and_mcse(xs2)
zs = @. (m1 - m2) / sqrt(s1^2 + s2^2)
@test all(norminvcdf(p) .< zs .< norminvccdf(p))
end
Expand Down Expand Up @@ -101,7 +100,8 @@ end
)
@test result_hmc2.κ.M⁻¹ isa Diagonal
compare_estimates(
identity, result_hmc2.posterior_matrix, result_hmc1.posterior_matrix
DynamicHMC.stack_posterior_matrices([result_hmc2]),
DynamicHMC.stack_posterior_matrices([result_hmc1]),
)
end

Expand All @@ -119,7 +119,8 @@ end
)
@test result_hmc3.κ.M⁻¹ isa Symmetric
compare_estimates(
identity, result_hmc3.posterior_matrix, result_hmc1.posterior_matrix
DynamicHMC.stack_posterior_matrices([result_hmc3]),
DynamicHMC.stack_posterior_matrices([result_hmc1]),
)
end

Expand All @@ -137,7 +138,8 @@ end
)
@test result_hmc4.κ.M⁻¹ === result_pf.fit_distribution.Σ
compare_estimates(
identity, result_hmc4.posterior_matrix, result_hmc1.posterior_matrix
DynamicHMC.stack_posterior_matrices([result_hmc4]),
DynamicHMC.stack_posterior_matrices([result_hmc1]),
)
end
end
Expand Down

2 comments on commit 7bc83fb

@sethaxen
Copy link
Member Author

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/78670

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.7.2 -m "<description of version>" 7bc83fb25b53fad2d5aacea2c1e724c6e71f5c74
git push origin v0.7.2

Please sign in to comment.