Hello, I am trying to convert this notebook to PyMC v5 (from v3). I am stuck on code block 16.7. I read the updated DensityDist documentation and believe this is this should be the correct way to use that API.
def logp(value, p, majority_first):
phi = [None] * 5
# Probability of data
phi[0] = pt.switch(pt.eq(value, 2), 1, 0)
phi[1] = pt.switch(pt.eq(value, 3), 1, 0)
phi[2] = pt.switch(pt.eq(value, 1), 1, 0)
phi[3] = pt.ones_like(value) * 1 / 3
phi[4] = pt.switch(
pt.eq(majority_first, 1), pt.switch(pt.eq(value, 2), 1, 0), pt.switch(pt.eq(value, 3), 1, 0)
)
# Compute log ( p_s * Pr(y_i|s) )
for i in range(5):
phi[i] = pt.log(phi[i]) + pt.log(p[i])
# Compute average log-probability of y_i
return pt.sum(pm.math.logsumexp(phi, axis=0))
with pm.Model() as m16_2:
# prior
p = pm.Dirichlet("p", np.array([4, 4, 4, 4, 4]))
# majority first data
majority_first = pm.Data("majority_first", df["majority_first"].values)
# likelihood
y = pm.DensityDist("y", p, majority_first, logp=logp, observed=df["y"].values)
However, this code block returns this error:
ValueError: Could not broadcast dimensions. Incompatible shapes were [(ScalarConstant(ScalarType(int64), data=5),), (ScalarConstant(ScalarType(int64), data=629),)].
It should be noted that the shape of df["y"].values
is (629,)
Last updated: Tue Jan 09 2024
Python implementation: CPython
Python version : 3.11.7
IPython version : 8.19.0
numpy : 1.26.3
pytensor : 2.18.4
arviz : 0.17.0
seaborn : 0.12.2
pymc : 5.10.3
pandas : 2.1.4
matplotlib: 3.8.2
Watermark: 2.4.3
Thank you in advance for any direction on this!