4d parameter array from PyJAGS into ArviZ?

Hi all,

Let me know if there is a better place to post this.

I’m trying to convert sample output from PyJAGS into an ArviZ InferenceData object using arviz.from_pyjags(), but this fails with ValueError: too many values to unpack (expected 3).

This is my call:

data = az.from_pyjags(
posterior=samples,
log_likelihood={“y”: “log_lik”
)

It clearly fails because one of my parameters is 4d while ArviZ expects 3. This is the parameter in question:

Variable: b.friend, Shape: (43, 43, 5000, 3), Type: <class ‘numpy.ndarray’>

The 4 items are (dimension1, dimension2, draws, chains)

Is there a way around this beyond coercing my 2 dimensions into 1?

ArviZ 0.21.0, pyjags 1.3.8

Thanks

Hi, @cjp!

While I have never used pyjags and this may be tedious, you can potentially create the InferenceData object manually. For example:

import arviz as az
import xarray as xr
import numpy as np

arr = np.random.normal(loc=0, scale=1, size=(43, 43, 5000, 3))

idata = az.InferenceData(
    posterior = xr.Dataset(
        {"b.friend": (['dimension1', 'dimension2', 'draw', 'chain'], arr)},
        coords={
            "dimension1": ("dimension1", np.arange(43)),
            "dimension2": ("dimension1", np.arange(43)),
            "draw": ("draw", np.arange(5000)),
            "chain": ("chain", np.arange(3)),
        }
    )
)