MVG with mixture in Dirichlet Process


#1

Hi folks,

I’m trying to fit this model:

K = 20       # the number of components
mu = np.array([xm,ym])

def stick_breaking(v):
    return v * tt.concatenate([tt.ones_like(v[..., :1]),
                               tt.extra_ops.cumprod(1 - v, axis=1)[..., :-1]],
                              axis=1)

with pm.Model() as model:    
    sigma_1 = pm.HalfNormal('simga_1', 5, shape=(K))
    sigma_2 = pm.HalfNormal('sigma_2', 5, shape=(K))
    rho = pm.Uniform('rho', -1, 1, shape=(K))
    alpha = pm.Gamma('alpha', 1., 1.)
    beta = pm.Beta('beta', 1., alpha, shape=(1, K))
    w = pm.Deterministic('w', stick_breaking(beta))
    w = w/w.sum()

    compdist = []
    for i in range(K):
        cov = pm.math.stack(([sigma_1[i]**2, sigma_1[i]*sigma_2[i]*rho[i]],\
                             [sigma_1[i]*sigma_2[i]*rho[i], sigma_2[i]**2]))
        compdist.append(pm.MvNormal.dist(mu=mu, cov=cov))
    obs = pm.Mixture('obs', w, compdist, observed=vals)

but when I start to sampling, I’m getting:
“MissingInputError: Input 0 of the graph (indices start from 0), used to compute Elemwise{exp,no_inplace}(alpha_log__), was not provided and not given a value. Use the Theano flag exception_verbosity=‘high’, for more information on this error.”

Can someone help me? Thank you very much!


#2

Hmm, this error doesnt really make sense. I can run the code with no problem:

K = 20       # the number of components
mu = np.array([.5, .9])

def stick_breaking(v):
    return v * tt.concatenate([tt.ones_like(v[..., :1]),
                               tt.extra_ops.cumprod(1 - v, axis=1)[..., :-1]],
                              axis=1)

with pm.Model() as model:    
    sigma_1 = pm.HalfNormal('simga_1', 5, shape=(K))
    sigma_2 = pm.HalfNormal('sigma_2', 5, shape=(K))
    rho = pm.Uniform('rho', -1, 1, shape=(K))
    alpha = pm.Gamma('alpha', 1., 1.)
    beta = pm.Beta('beta', 1., alpha, shape=(1, K))
    w = pm.Deterministic('w', stick_breaking(beta))
    w = w/w.sum()

    compdist = []
    for i in range(K):
        cov = pm.math.stack(([sigma_1[i]**2, sigma_1[i]*sigma_2[i]*rho[i]],\
                             [sigma_1[i]*sigma_2[i]*rho[i], sigma_2[i]**2]))
        compdist.append(pm.MvNormal.dist(mu=mu, cov=cov))
    obs = pm.Mixture('obs', w, compdist, observed=np.random.randn(1000, 2))
    trace = pm.sample()