I am trying to fit data using a mixture of two Beta distributions (I do not know the weights of each distribution) using Mixture
from PyMC3. Here is the code:
model=pm.Model()
with model:
alpha1=pm.Uniform("alpha1",lower=0,upper=20)
beta1=pm.Uniform("beta1",lower=0,upper=20)
alpha2=pm.Uniform("alpha2",lower=0,upper=20)
beta2=pm.Uniform("beta2",lower=0,upper=20)
w=pm.Uniform("w",lower=0,upper=1)
b1=pm.Beta("B1",alpha=alpha1,beta=beta1)
b2=pm.Beta("B2",alpha=alpha2,beta=beta2)
mix=pm.Mixture("mix",w=[1.0,w],comp_dists=[b1,b2])
After run this code I get the following error: AttributeError: 'list' object has no attribute 'mean'
. Any suggestions?
PyMC3 comes with a
pymc3.tests
module which contains useful examples. By searching that directory for the word "mixture" I came upon this example:Notice that the classmethod
dist
is called. Googling "pymc3 dist classmethod" leads to this doc page which explainsBeyond this I'm not entirely clear why the stripped-down distribution is what is required here, but it seems to work:
Note that when using the
dist
classmethod, the name string is omitted.