pymc - Mixture model of a normal and constant -


i'd model distribution mixture of normal , constant 0.

i couldn't find solution because in mixture examples i've found class of distribution same every category.

here code illustrate i'm looking for:

with pm.model() model:     x_non_zero = pm.normal(...)     zero_rate = pm.uniform('zero_rate', lower=0.0, upper=.0, testval=0.5)     fr = pm.bernoulli('fr', p=zero_rate)     x = pm.???('x', pm.switch(pm.eq(fr, 0), x_non_zero, 0), observed=data['x']) 

i'm interested in rate data 0 , parameters of normal when non-zero.

here how data i'm modelling looks like: mixture of normal constant

one option try gaussian mixture model, may think of gaussian sd=0 constant value. option use model following:

with pm.model() model:     mean = pm.normal('mean', mu=100, sd=10)     sd = pm.halfnormal('sd', sd=10)      category = pm.categorical('category', p=[0.5, 0.5], shape=len(x))     mu = pm.switch(pm.eq(category, 0), 0, mean)     eps = pm.switch(pm.eq(category, 0), 0.1, sd)      obs = pm.normal('obs', mu=mu, sd=eps, observed=x)      step0 = pm.elemwisecategorical(vars=[category], values=[0, 1])     step1 = pm.metropolis(vars=[mean, sd])     trace = pm.sample(10000, step=[step0, step1]) 

to find out rate can compute

burnin = 100   np.mean(trace[burnin]['category']) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -