diff --git a/Project.toml b/Project.toml index f3ba6d17..99b281d0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Pathfinder" uuid = "b1d3bc72-d0e7-4279-b92f-7fa5d6d2d454" authors = ["Seth Axen and contributors"] -version = "0.7.1" +version = "0.7.2" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" @@ -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" diff --git a/docs/Project.toml b/docs/Project.toml index fd53a4df..86683b27 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -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" diff --git a/test/integration/AdvancedHMC/Project.toml b/test/integration/AdvancedHMC/Project.toml index ffb2362e..5d7aeeb9 100644 --- a/test/integration/AdvancedHMC/Project.toml +++ b/test/integration/AdvancedHMC/Project.toml @@ -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" diff --git a/test/integration/AdvancedHMC/runtests.jl b/test/integration/AdvancedHMC/runtests.jl index 45621a16..6e713c55 100644 --- a/test/integration/AdvancedHMC/runtests.jl +++ b/test/integration/AdvancedHMC/runtests.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/integration/DynamicHMC/Project.toml b/test/integration/DynamicHMC/Project.toml index 0eeefe9d..b532c950 100644 --- a/test/integration/DynamicHMC/Project.toml +++ b/test/integration/DynamicHMC/Project.toml @@ -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" diff --git a/test/integration/DynamicHMC/runtests.jl b/test/integration/DynamicHMC/runtests.jl index b1960d66..71f7ce97 100644 --- a/test/integration/DynamicHMC/runtests.jl +++ b/test/integration/DynamicHMC/runtests.jl @@ -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 @@ -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 @@ -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 @@ -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