ArviZ.jl
ArviZ.jl copied to clipboard
Add converter from Turing using both Chains and Model
This PR is a working prototype of the Turing part of the proposal in #132. With this PR, we can compute the final full InferenceData from the Turing example in the quickstart in a single line:
julia> idata = from_turing(
turing_chns;
model=param_mod,
rng=rng,
observed_data=(y=y,),
dims=Dict("y" => ["school"], "σ" => ["school"], "θ" => ["school"]),
coords=Dict("school" => schools),
)
InferenceData with groups:
> posterior
> posterior_predictive
> log_likelihood
> sample_stats
> prior
> prior_predictive
> sample_stats_prior
> observed_data
> constant_data
It's marked draft because
- I'm not 100% convinced we should do this.
- the exact interface may change
- I have not yet tested this on more complex models; do I make assumptions that may be invalid? (@torfjelde, do you see any issues there)?
- I need to add an option for user to pass
falseto a group name if they don't want it to be generated. - Needs a test suite
Thanks, @torfjelde! I love that these changes both are more general and simplify the code quite a bit. Is it possible, given a DynamicPPL.Model, to determine what in its arguments are observed data (i.e. on the left-hand side of a tilde expression)? It'd be nice to extract that from the model instead of requiring the user to provide it.
Is it possible, given a DynamicPPL.Model, to determine what in its arguments are observed data (i.e. on the left-hand side of a tilde expression)?
You could just call pointwise_loglikelihoods once and then you have them as keys:)
Actually, did you figure this out on your own? Looking at _compute_log_likelihood it looks like it!
You could just call
pointwise_loglikelihoodsonce and then you have them as keys:)Actually, did you figure this out on your own? Looking at
_compute_log_likelihoodit looks like it!
Oh, you know, I didn't realize that all I had to do was sample from the prior, then compute the log likelihood, then I would have the observed data names. It's a little awkward, but it works now! Thanks!