The following code executes without problems.
import pymc3 as pm alpha1_, beta1_ = pm.Exponential.dist(0.1).random(size=2) alpha2_, beta2_ = pm.Exponential.dist(0.1).random(size=2) w_ = pm.Dirichlet.dist(a=np.ones(2), shape=2).random(size=1) p0 = pm.Gamma.dist([alpha1_, alpha2_], [beta1_, beta2_], shape=(n,2)) p_ = pm.Mixture.dist(w = w_, comp_dists = p0, shape=n).random(size=1)
But the same code with Beta instead of Gamma gives me
AttributeError: 'Beta' object has no attribute 'mode'.
I looked a bit at the code and the exception is thrown in
pymc3\distributions\mixture.py in _comp_modes(self) which is called from the constructor of Mixture. As a backup strat, it tries to compute the modes of the separate distributions as if it were an iterable of distributions. But that fails too, because p0 is not iterable and it throws
TypeError: 'Beta' object is not iterable . Then it goes back to the constructor of the class Mixture which catches AttributeError, ValueError and IndexError. But because the actual error is a TypeError is isn’t caught there and the exception halts the execution.
I guess for Gamma the mode is defined so this doesn’t happen. Is this a bug or is there a reason why this is a bad idea with Beta?
edit: was posted as https://github.com/pymc-devs/pymc3/issues/3126.