Skip to content

Commit

Permalink
change stacked ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp committed Dec 13, 2022
1 parent 9253328 commit eebe8f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DocStringExtensions = "0.8, 0.9"
FillArrays = "0.13"
LogDensityProblems = "1, 2"
LogExpFunctions = "0.3"
MCMCDiagnosticTools = "0.2"
Parameters = "0.11, 0.12"
ProgressMeter = "1"
TensorCast = "0.4"
Expand Down
7 changes: 5 additions & 2 deletions src/mcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,15 @@ $(SIGNATURES)
Given a vector of `results`, each containing a property `posterior_matrix` (eg obtained from
[`mcmc_with_warmup`](@ref) with the same sample length), return a lazy view as an array
indexed by `[draw_index, parameter_index, chain_index]`.
indexed by `[draw_index, chain_index, parameter_index]`.
This is useful as an input for eg `MCMCDiagnosticTools.ess_rhat`.
!!! note
The ordering is not compatible with MCMCDiagnostictools version < 0.2.
"""
function stack_posterior_matrices(results)
@cast _[i, j, k]:= results[k].posterior_matrix[j, i]
@cast _[i, k, j]:= results[k].posterior_matrix[j, i]
end

"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_mcmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end
D, N, K = 5, 100, 7
= multivariate_normal(ones(5))
results = fill(mcmc_with_warmup(RNG, ℓ, N; reporter = NoProgressReport()), K)
@test size(stack_posterior_matrices(results)) == (N, D, K)
@test size(stack_posterior_matrices(results)) == (N, K, D)
@test size(pool_posterior_matrices(results)) == (D, N * K)
end

Expand Down

0 comments on commit eebe8f5

Please sign in to comment.