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

sample_posterior_predictive from InferenceData? #3828

Closed
michaelosthege opened this issue Mar 8, 2020 · 1 comment
Closed

sample_posterior_predictive from InferenceData? #3828

michaelosthege opened this issue Mar 8, 2020 · 1 comment

Comments

@michaelosthege
Copy link
Member

Description of your problem

In some scenarios, sampling and prediction do not happen at the same time or even in the same process.
sample_posterior_predictive can be fed with a MultiTrace, but in many scenarios, the trace is saved via arviz.to_netcdf and only the arviz.InferenceData is kept.

With this small function, one can convert an xarray.Dataset (the InferenceData.posterior) to a list of points that may be consumed by sample_posterior_predictive.

def _to_points(posterior:xarray.Dataset) -> typing.List[dict]:
    samples = {
        vn : posterior[vn].values
        for vn in posterior.keys()
    }
    points = []
    for c in posterior.chain:
        for d in posterior.draw:
            points.append({
                vn : s[c, d]
                for vn, s in samples.items()
            })
    return points

The list of points is probably not the most performant option. Maybe sample_posterior_predictive could be modified to consume the InferenceData object directly?

@michaelosthege michaelosthege changed the title Support xarray.Dataset with sample_posterior_predictive? sample_posterior_predictive from InferenceData? Mar 8, 2020
@rpgoldman
Copy link
Contributor

The list of points is probably not the most performant option. Maybe sample_posterior_predictive could be modified to consume the InferenceData object directly?

Yes, for the vectorized version, I am already redoing the input away from being a set of points.

We could definitely consume the InferenceData object more directly, but sample_posterior_predictive needs access to the pm.Model object, so it's not sufficient to have a save and restore solution that is limited to the posterior trace alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants