ArviZ.jl icon indicating copy to clipboard operation
ArviZ.jl copied to clipboard

Add converter from Turing using both Chains and Model

Open sethaxen opened this issue 4 years ago • 3 comments
trafficstars

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

  1. I'm not 100% convinced we should do this.
  2. the exact interface may change
  3. 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)?
  4. I need to add an option for user to pass false to a group name if they don't want it to be generated.
  5. Needs a test suite

sethaxen avatar May 19 '21 19:05 sethaxen

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.

sethaxen avatar May 20 '21 11:05 sethaxen

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!

torfjelde avatar May 21 '21 18:05 torfjelde

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!

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!

sethaxen avatar May 22 '21 10:05 sethaxen