az.utils.Dask.enable_dask(**kwargs)
xr.apply_ufunc
which makes it very easy to back the same computation with numpy or with dask, however, none of the conversion routines have support for it yet
.sel(chain=0, draw=0)
whereas I myself have problems understanding my own code months later if what I'm using is [:, 0, 0, :]
sample.posterior.sel(chain=0, draw=0).to_dataframe()
(or to_array
) doesn't do the right thing for me as it put a vector variable in an when I want the value for each entry.
items()
, keys()
and values()
methods. IIUC, you can't change the function and need a dictionary of {var_name: numpy array} so ...sel(...).items()
is already very close to what you want, should be closer than the .to_dict
method which includes coords, dims, attributes... in the generated dict
{k: da.values for k, da in sample.posterior.sel(chain=0, draw=0).items()}
Hi, I'm running the linear regression example from the pymc3 getting started documentation, but I'm swapping out the Normal distribution with DensityDist and my own implementation of the normal distribution.
# Expected value of outcome
mu = alpha + beta[0] * X1 + beta[1] * X2
# Likelihood (sampling distribution) of observations
Y_obs = pm.DensityDist("Y_obs", logp, observed=dict(value=Y, mu_logp=mu, sigma_logp=sigma))
But when I do the az.plot_trace(trace) I get the following error:
raise MissingInputError(error_msg, variable=var)
theano.graph.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute Subtensor{int64}(beta, Constant{1}), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
Is this a known problem?
Hi all, I am new to Arviz and I am trying to generate a prior predictive check plot from PyMC3. My goal is to generate the same plot made by plot_ppc from a posterior using the prior to check if the prior is reasonable. I am using the plot_ppc() function passing group="prior". I generate prior predictive samples from a PyMC3 model via
with model:
prior_pred = pm.sample_prior_predictive(samples=200)
az.concat(idata, az.from_pymc3(prior=prior_pred), inplace=True)
However, when I run
as.plot_ppc(idata, ax=ax, group="prior")
I get an error saying "data" argument must have the group "prior_predictive" for ppcplot
. The from_pymc3 does not have a prior_predictive kwarg.
The PyMC3 example (https://docs.pymc.io/en/v3/pymc-examples/examples/diagnostics_and_criticism/posterior_predictive.html) for prior/posterior predictive only uses Arviz for the posterior check.
Is there a way to generate the prior distribution from plot_ppc?
az.plot_ppc(az.from_pymc3(prior=prior_pred))
under the with model:
context. Does that mean that it will evaluate the likelihood using the model on the fly? If that is the case it works differently than the posterior case where samples are used?
pm.sample_prior_predictive
function samples both prior and prior predictive and returns a dictionary with all the variables there. Without the model ArviZ can't know which variables correspond to each quantity and we decided to add everything to the prior instead of erroring out. You should get a warning however whenever you call from_pymc3 without the model info
az.from_pymc3(prior=prior_pred)
the model is only used to know which variables are prior and which prior predictive and to retrieve the observed_data, nothing else
Hello there. I started with PyMC3 + arviz recently and got stuck with dims and coords. I define an additional coord on an unpooled model but it never shows up in the InferenceData. I use arviz 0.12.0 and the current pymc3. I have the following model:
with Model() as deltas_unpooled_model:
# how many users do we have?
mu_c = Normal("mu", mu=10.0, sigma=10, shape=len(selectCd))
sigma_c = Normal("sigma", mu=10.0, sigma=10, shape=len(selectCd))
delta_customer = LogNormal("deltas", mu=mu_c[selectCd.customer_idx.values], sigma=sigma_c[selectCd.customer_idx.values], observed=selectCd['delta'])
trace_unpooled = sample(random_seed=2412, chains=4, draws=2000, return_inferencedata=False)
prior_unpooled = sample_prior_predictive()
posterior_predictive_unpooled = sample_posterior_predictive(trace_unpooled)
and construct the InferenceData like this:
# with deltas_unpooled_model:
unpooled_data = az.from_pymc3(
trace=trace_unpooled,
model=deltas_unpooled_model,
prior=prior_unpooled,
posterior_predictive=posterior_predictive_unpooled,
coords={"customerId": selectedCustomers},
dims={"mu_c": ["customerId"], "sigma_c": ["customerId"]},
)
The InferenceData posterior contains Coordinates:
chain
draw
mu_dim_0
sigma_dim_0
Not what I expected. Any idea, where I take the wrong turn?