pm.Dirichlet does not work with sample()

Hi, I am currently doing Gaussian mixture examples. I found a part of the problem occurs in pm.Dirichlet, so I want to ask your ideas and perspective on this error… Sampling does not work at all… even though I did not add anything except pm.Dirichlet…

    model_mixture = pm.Model()
    with model_mixture:
        pi = pm.Dirichlet('pi', a = np.ones(2))
        trace = pm.sample()

Error:

ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (aesara.graph.rewriting.basic): node: SpecifyShape(TensorConstant{(3,) of 0.0}, TensorConstant{2})
ERROR (aesara.graph.rewriting.basic): TRACEBACK:
ERROR (aesara.graph.rewriting.basic): Traceback (most recent call last):
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1933, in process_node
replacements = node_rewriter.transform(fgraph, node)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/graph/rewriting/basic.py”, line 1092, in transform
return self.fn(fgraph, node)
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/tensor/rewriting/basic.py”, line 1142, in constant_folding
if r_shape is None and other_shape:
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/link/c/op.py”, line 103, in rval
thunk()
File “/Users/jinyoungko/anaconda3/lib/python3.9/site-packages/aesara/link/c/basic.py”, line 1788, in call
raise exc_value.with_traceback(exc_trace)
AssertionError: SpecifyShape: dim 0 of input has shape 3, expected 2.

If I increase the dimension of pm.Dirichlet by increasing np.ones(2) to np.ones(3), the error message just returns “AssertionError: SpecifyShape: dim 0 of input has shape 4, expected 3.”

It seems that the problem of pm.Dirichlet itself. Could you provide your perspectives?

You are likely using a version of Aesara that’s incompatible with your version of PyMC.

The easiest solution is update your version of PyMC.

1 Like

Actually, I downgraded my Aesara package. I may need to update PyMC and Aseara together, thanks.