Arviz.summary() ValueError

Hello,
I’m trying to use the arviz summary method like
az.summary(idata.prior)
but keep getting:
ValueError: could not broadcast input array from shape (9,3) into shape (9,)

My prior has the following dimensions:
(chain: 1, draw: 500, aoa: 297, spline: 40)

Has anyone else encountered the same issue with arviz or knows how to fix it?
Thanks in advance.

This should work (although it’s more “clean” to select the prior group with az.summary(idata, group='prior').

Could you share a bit more of your model? This doesn’t seem like an error coming from az.summary, I would expect it instead from a shape issue in the model code.

I’m working with a quite simple cubic spline model (using patsy) that looks like that:

knot_list = np.arange(0, 360, 10)
B = dmatrix(
    "bs(ALPHA, knots=knots, degree=3, include_intercept=True) - 1",
    {"ALPHA": df['ALPHA'], "knots": knot_list},
)

with pm.Model() as model:

    model.add_coord('spline', length=B.shape[1], mutable=True)
    model.add_coord('aoa', df['ALPHA'], mutable=True)

    data_b = pm.MutableData('data_b', B, dims=('aoa', 'spline'))

    tau = pm.HalfCauchy('tau', 20) 
    beta = pm.Normal("beta", mu=0, sigma=tau, dims='spline')
    mu = pm.Deterministic("mu", pm.math.dot(data_b, beta), dims='aoa')
    sigma = pm.HalfNormal("sigma", 0.01)
    c_predict = pm.Normal("c_predict", mu, sigma, observed=df['CZ'], dims='aoa')

I copy-pasted your code, adding:

    idata = pm.sample_prior_predictive()
az.summary(idata, group='prior', var_names=['beta', 'tau', 'sigma'])

and it ran fine. How are you generating your prior draws?

1 Like

Apparently it was about the var_names parameter as it ran fine now after adding it. Thanks a lot!

var_names just selects a subset of variables to display in the results table. I did that to keep it from being too long, but it also worked fine without it. Does it not for you?

No, without var_names it still doesn’t work. I’m on arviz 0.16 and I also used pm.sample_prior_predictive().

@jan5 I was running into a similar issue and just diagnosed it, but judging from your comments it might have had a different cause.

My issue was I was using the coords argument to subset some of my fixed-effects parameters, but the set of coordinates I was passing included repeated values. This gave me a similar ValueError (though the shape it was trying to broadcast was (9, 2) rather than (9, 3) like you’re seeing).

Probably a different root cause as it seems like you weren’t using the coords argument, but sharing just in case it helps you diagnose your issue.

2 Likes