Hello!
I am just getting started with PyMC and am having some issues understanding how the dimensions of observations get used in a mixture.
I started by making a super basic binomial model to make sure it runs as expected:
dummy_data = pd.DataFrame([3, 4, 7, 4, 2, 1, 2, 1, 3, 4, 3],columns=["counts"])
coords = {"observation": dummy_data.index.values}
binomial_dummy = pm.Model(coords=coords)
with binomial_dummy:
p_norm = pm.Uniform("p_norm")
normal_component = pm.Binomial("normal_component",n = 10, p = p_norm, observed = dummy_data["counts"], dims="observation")
display(pm.model_to_graphviz(binomial_dummy))
with binomial_dummy:
idata = pm.sample()
with binomial_dummy:
pm.sample_posterior_predictive(idata, extend_inferencedata=True)
idata.posterior_predictive.normal_component[0][0]
This runs fine and it generates 11 observations in each step in the posterior prediction (which, side question, why does it make 11 data each time, shouldn’t this be independent of how much data I use to do the parameter estimation).
Next I tried to change this to just a mixture of 1 distribution to make sure I understand how the dimensions work.
dummy_data = pd.DataFrame([3, 4, 7, 4, 2, 1, 2, 1, 3, 4, 3],columns=["counts"])
coords = {"observation": dummy_data.index.values}
binomial_dummy = pm.Model(coords=coords)
with binomial_dummy:
p_norm = pm.Uniform("p_norm")
normal_component = pm.Binomial.dist(n = 10, p = p_norm)
observed_counts = pm.Mixture(
"observed_counts",
w = [1],
comp_dists = [
normal_component,
],
observed = dummy_data["counts"],
dims="observation"
)
display(pm.model_to_graphviz(binomial_dummy))
with binomial_dummy:
idata = pm.sample()
with binomial_dummy:
pm.sample_posterior_predictive(idata, extend_inferencedata=True)
idata.posterior_predictive.normal_component[0][0]
However, I get index out of bounds errors. I have tried more complex code (not shown) and it gives me dimensions do not agree
type of errors which I why I boiled it down here; I assume the index out of bounds errors are due to the same issue?
Any help would be great. Thank you!