def mixture_loglike(data, thetas, covs, labels): n = len(data) likes = pdfs.mvnpdf(data, thetas, covs) loglike = likes.ravel('F').take(labels * n + np.arange(n)).sum() if np.isnan(loglike): return -1e300 return loglike if np.isnan(likes).any(): loglike = 0. for j, (theta, cov) in enumerate(zip(thetas, covs)): this_data = data[labels == j] ch = chol(cov) loglike += pm.mv_normal_chol_like(this_data, theta, ch) return loglike
def mixture_loglike2(data, thetas, taus, weights): n = len(data) covs = [inv(tau) for tau in taus] likes = pdfs.mvnpdf(data, thetas, covs) loglike = (likes * weights).sum() # loglike = likes.ravel('F').take(labels * n + np.arange(n)).sum() if np.isnan(loglike): st() return -1e300 return loglike if np.isnan(likes).any(): loglike = 0. for j, (theta, cov) in enumerate(zip(thetas, covs)): this_data = data[labels == j] loglike += pm.mv_normal_chol_like(this_data, theta, ch) return loglike