Trace.get_values in PyMC version 4.1.3

How do I modify trace.get_values(var) in PyMC4? I am running a code which worked in PyMC3 but
I am getting this error in PyMC4:

AttributeError                            Traceback (most recent call last)
Input In [59], in <cell line: 2>()
      2 for var in ['A', 'beta', 't0', 'gamma', 'trise', 'tfall', 'c', 'white_noise']:
      3     plt.figure(figsize=(10,4))
----> 4     vals = idata.get_values(var)
      5     if var != 'p0':
      6         mean, lower, upper = round(vals.mean(), 2), round(vals.mean()-vals.std(), 2), round(vals.mean()+vals.std(),2)

AttributeError: 'InferenceData' object has no attribute 'get_values'

You can read more about the InferenceData object here.

But to answer your question directly, what I do most often to replicate get_values is:

posterior = idata.posterior.stack(sample=['chain', 'draw'])
vals = posterior[var]

Also, already in the development version (will be available with ArviZ 0.13) you can also use:

posterior = az.extract(idata)

which defaults to this behaviour but it is also possible to request a random subset of the samples (for plotting without crowding the figure too much for example). There are also other examples of working with InferenceData in Working with InferenceData — ArviZ dev documentation. The schema doc linked above is more descriptive, depending on what you are searching for you should read one or the other. As first contact ever with InferenceData however, I’d recommend the “working with inferencedata” page or this other one: Introduction to xarray, InferenceData, and netCDF for ArviZ — ArviZ dev documentation

1 Like