I went back to the example that started me down this path (Isaac Slavitt: Dirichlet-multinomial model for Skittle proportions) and I tried to duplicate his work line by line.
When I get to the first modeling block I hit an error:
color_names = df.columns
with pm.Model() as model:
# make the Dirichlet an uninformative prior
alpha = np.ones(len(color_names))
# choose true proportions
p = pm.Dirichlet("p", a=alpha)
# choose a bag size
n = pm.DiscreteUniform("n", lower=40, upper=100, observed=df.sum(axis=1).values)
# choose how many of each color to put in that bag adding up to n based on proportions p
k = pm.Multinomial("k", n=n, p=p, observed=df)
trace = pm.sample(2500)
fit = az.from_pymc3(trace=trace, coords={"p_dim_0": color_names})
color_names = df.columns
with pm.Model() as model:
# make the Dirichlet an uninformative prior
alpha = np.ones(len(color_names))
# choose true proportions
p = pm.Dirichlet("p", a=alpha)
# choose a bag size
n = pm.DiscreteUniform("n", lower=40, upper=100, observed=df.sum(axis=1).values)
# choose how many of each color to put in that bag adding up to n based on proportions p
k = pm.Multinomial("k", n=n, p=p, observed=df)
trace = pm.sample(2500)
fit = az.from_pymc3(trace=trace, coords={"p_dim_0": color_names})
color_names = df.columns
with pm.Model() as model:
# make the Dirichlet an uninformative prior
alpha = np.ones(len(color_names))
# choose true proportions
p = pm.Dirichlet("p", a=alpha)
# choose a bag size
n = pm.DiscreteUniform("n", lower=40, upper=100, observed=df.sum(axis=1).values)
# choose how many of each color to put in that bag adding up to n based on proportions p
k = pm.Multinomial("k", n=n, p=p, observed=df)
trace = pm.sample(2500)
fit = az.from_pymc3(trace=trace, coords={"p_dim_0": color_names})
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_148063/2250084870.py in <module>
9 n = pm.DiscreteUniform("n", lower=40, upper=100, observed=df.sum(axis=1).values)
10 # choose how many of each color to put in that bag adding up to n based on proportions p
---> 11 k = pm.Multinomial("k", n=n, p=p, observed=df)
12
13 trace = pm.sample(2500)
~/miniconda3/envs/pymc/lib/python3.8/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
119 dist = cls.dist(*args, **kwargs, shape=shape)
120 else:
--> 121 dist = cls.dist(*args, **kwargs)
122 return model.Var(name, dist, data, total_size, dims=dims)
123
~/miniconda3/envs/pymc/lib/python3.8/site-packages/pymc3/distributions/distribution.py in dist(cls, *args, **kwargs)
128 def dist(cls, *args, **kwargs):
129 dist = object.__new__(cls)
--> 130 dist.__init__(*args, **kwargs)
131 return dist
132
~/miniconda3/envs/pymc/lib/python3.8/site-packages/pymc3/distributions/multivariate.py in __init__(self, n, p, *args, **kwargs)
577 self.p = tt.as_tensor_variable(p)
578
--> 579 self.mean = self.n * self.p
580 mode = tt.cast(tt.round(self.mean), "int32")
581 diff = self.n - tt.sum(mode, axis=-1, keepdims=True)
~/miniconda3/envs/pymc/lib/python3.8/site-packages/theano/tensor/var.py in __mul__(self, other)
126 # and the return value in that case
127 try:
--> 128 return theano.tensor.mul(self, other)
129 except (NotImplementedError, TypeError):
130 return NotImplemented
~/miniconda3/envs/pymc/lib/python3.8/site-packages/theano/graph/op.py in __call__(self, *inputs, **kwargs)
251
252 if config.compute_test_value != "off":
--> 253 compute_test_value(node)
254
255 if self.default_output is not None:
~/miniconda3/envs/pymc/lib/python3.8/site-packages/theano/graph/op.py in compute_test_value(node)
128 thunk.outputs = [storage_map[v] for v in node.outputs]
129
--> 130 required = thunk()
131 assert not required # We provided all inputs
132
~/miniconda3/envs/pymc/lib/python3.8/site-packages/theano/graph/op.py in rval()
604
605 def rval():
--> 606 thunk()
607 for o in node.outputs:
608 compute_map[o][0] = True
~/miniconda3/envs/pymc/lib/python3.8/site-packages/theano/link/c/basic.py in __call__(self)
1769 print(self.error_storage, file=sys.stderr)
1770 raise
-> 1771 raise exc_value.with_traceback(exc_trace)
1772
1773
ValueError: Input dimension mis-match. (input[0].shape[0] = 468, input[1].shape[0] = 5)
Maybe related?
Intel / Conda
python 3.8.12
arviz==0.11.4
pymc3==3.11.2
theano-pymc==121.2