arviz
arviz copied to clipboard
Broadcast Input Array Error
I ran this code, which worked perfectly yesterday.
fit_pz_hlm=pz_model_hlm.sampling(data=data_zip1_hlm, warmup=1000, iter=1000,
chains=4, thin=4, control=dict(max_treedepth=18
, adapt_delta=0.999))
az_fit_pz_hlm=az.from_pystan(posterior=fit_pz_hlm, posterior_predictive=['y_rep'],
observed_data=['y'],
log_likelihood='log_lik')
az.to_netcdf(az_fit_pz_hlm, 'fit_pz_hlm')
Today, I consistently receive this error message: ValueError: could not broadcast input array from shape (250,) into shape (0,).
The Traceback is below.
I believe that several packages in python were updated this morning. Thoughts?
thanks in advance.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-32-b19021399361> in <module>
2 chains=4, thin=4, control=dict(max_treedepth=18
3 , adapt_delta=0.999))
----> 4 az_fit_pz_hlm=az.from_pystan(posterior=fit_pz_hlm, posterior_predictive=['y_rep'],
5 observed_data=['y'],
6 log_likelihood='log_lik')
/usr/local/lib/python3.8/dist-packages/arviz/data/io_pystan.py in from_pystan(posterior, posterior_predictive, predictions, prior, prior_predictive, observed_data, constant_data, predictions_constant_data, log_likelihood, coords, dims, posterior_model, prior_model, save_warmup)
942 ).to_inference_data()
943 else:
--> 944 return PyStanConverter(
945 posterior=posterior,
946 posterior_predictive=posterior_predictive,
/usr/local/lib/python3.8/dist-packages/arviz/data/io_pystan.py in to_inference_data(self)
266 save_warmup=self.save_warmup,
267 **{
--> 268 "posterior": self.posterior_to_xarray(),
269 "sample_stats": self.sample_stats_to_xarray(),
270 "log_likelihood": self.log_likelihood_to_xarray(),
/usr/local/lib/python3.8/dist-packages/arviz/data/base.py in wrapped(cls, *args, **kwargs)
44 if all([getattr(cls, prop_i) is None for prop_i in prop]):
45 return None
---> 46 return func(cls, *args, **kwargs)
47
48 return wrapped
/usr/local/lib/python3.8/dist-packages/arviz/data/io_pystan.py in posterior_to_xarray(self)
84 ignore = posterior_predictive + predictions + log_likelihood + ["lp__"]
85
---> 86 data, data_warmup = get_draws(posterior, ignore=ignore, warmup=self.save_warmup)
87 attrs = get_attrs(posterior)
88 return (
/usr/local/lib/python3.8/dist-packages/arviz/data/io_pystan.py in get_draws(fit, variables, ignore, warmup)
615 for key, loc in keys_locs:
616 ary_slice = tuple(axes + loc)
--> 617 ary[ary_slice] = pyholder.chains[key][-ndraw:]
618 if warmup:
619 ary_warmup[ary_slice] = pyholder.chains[key][:ndraw_warmup]
ValueError: could not broadcast input array from shape (250,) into shape (0,)
Hmm, does that work with PyStan? What happens if you add iter=1001
Hmm, does that work with PyStan? What happens if you add
iter=1001
Of course. I should have looked at the code again. Changing the iter fixed it. Thanks for your help.
No problem, still a bug we need to fix in arviz.
@ahartikainen , would you guide me on how to proceed in solving this bug.
We need to figure out the components here
ary[ary_slice] = pyholder.chains[key][-ndraw:]
ary_slice
or
[-ndraw:]
fails.
We probably need to add 0 size check somewhere there.
Is there a test to check this function already or we need to add them to check how it is working?
I don't think there is a test for this.
Not sure if we need to add a test for this. It depends how we implement this.
Is this still an issue?
Probably, maybe we need to add a fix for this?