Mixed multivariate Gauss distribution

OK I see, and this is where the error comes from. You need to rewrite the function H into a theano function. Something like below should work:

# instead of computing H(rho), do most of the computation outside of theano
H0 = np.zeros((n, n))
for i in range(0, n):
    for j in range(0, n):
        H0[i, j] = np.abs(time[j] - time[i])

with pm.Model() as model:
    M = pm.Gamma('M', 1., 1.)
    sigma_w = pm.Uniform('sigma_w', 0.0, 1.5, shape=K)
    rho = pm.Uniform('rho', 0.0, 0.1, shape=K)

    beta = pm.Beta('beta', 1., M, shape=K)
    w = pm.Deterministic('w', stick_breaking(beta))

    # MvNormal only accept one cov at a time, you need to construct 
    # each component one by one
    compdist = []
    for i in range(K):
        compdist.append(pm.MvNormal.dist(
            mu=mu0, cov=sigma_w[i]**2 * tt.pow(rho[i], H0)))

    obs = pm.Mixture('obs', w, compdist, observed=dataSet1)

You can find a similar example discussed in this post: Properly sampling mixture models

1 Like