Skip to content

Commit

Permalink
Support passing prior_predictive without prior to from_mcmcchains (#152)
Browse files Browse the repository at this point in the history
* Convert prior predictive even if prior not provided

* Add test

* Increment version number
  • Loading branch information
sethaxen authored Jan 18, 2022
1 parent 5d52d66 commit f011ecc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

2 comments on commit f011ecc

@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/52721

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

Please sign in to comment.