python - How to correctly defined mixture of Beta distributions in PyMC3 -
i trying fit data using mixture of 2 beta distributions (i not know weights of each distribution) using mixture
pymc3. here code:
model=pm.model() 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 code following error: attributeerror: 'list' object has no attribute 'mean'
. suggestions?
pymc3 comes pymc3.tests
module contains useful examples. searching directory word "mixture" came upon this example:
mixture('x_obs', w, [normal.dist(mu[0], tau=tau[0]), normal.dist(mu[1], tau=tau[1])], observed=self.norm_x)
notice classmethod dist
called. googling "pymc3 dist classmethod" leads doc page explains
... each
distribution
hasdist
class method returns stripped-down distribution object can used outside of pymc model.
beyond i'm not entirely clear why stripped-down distribution required here, seems work:
import pymc3 pm model = pm.model() 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.dist(alpha=alpha1, beta=beta1) b2 = pm.beta.dist(alpha=alpha2, beta=beta2) mix = pm.mixture("mix", w=[1.0, w], comp_dists=[b1, b2])
note when using dist
classmethod, name string omitted.
Comments
Post a Comment