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 passing prior_predictive without prior to from_mcmcchains #152

Merged
merged 3 commits into from
Jan 18, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArviZ"
uuid = "131c737c-5715-5e2e-ad31-c244f01c1dc7"
authors = ["Seth Axen <[email protected]>"]
version = "0.5.10"
version = "0.5.11"

[deps]
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
Expand Down
8 changes: 8 additions & 0 deletions src/mcmcchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ function from_mcmcchains(
),
)
concat!(all_idata, prior_idata)
elseif prior_predictive !== nothing
pre_prior_predictive_idata = convert_to_inference_data(
prior_predictive; eltypes=eltypes, kwargs...
)
concat!(
all_idata,
InferenceData(; prior_predictive=pre_prior_predictive_idata.posterior),
)
end

for (group, group_data) in [
Expand Down
11 changes: 11 additions & 0 deletions test/test_mcmcchains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ end
@test "z" ∈ keys(dimdict(idata.predictions_constant_data))
end

# https://github.com/arviz-devs/ArviZ.jl/issues/146
@testset "prior predictive w/o prior" begin
nvars, nchains, ndraws = 2, 4, 20
chns = makechains(nvars, ndraws, nchains)
prior_predictive = randn(nchains, ndraws, 1)
idata = from_mcmcchains(chns; prior_predictive=prior_predictive)
test_chains_data(chns, idata, :posterior, names(chns))
@test :prior_predictive ∈ ArviZ.groupnames(idata)
@test idata.prior_predictive.x.values ≈ prior_predictive
end

@testset "missing -> NaN" begin
rng = MersenneTwister(42)
nvars, nchains, ndraws = 2, 4, 20
Expand Down