def log_marginal_likelihood(params, data): cluster_lls = [] for log_proportion, mean, chol in zip(*unpack_params(params)): cov = np.dot(chol.T, chol) + 0.000001 * np.eye(D) cluster_log_likelihood = log_proportion + mvn.logpdf(data, mean, cov) cluster_lls.append(np.expand_dims(cluster_log_likelihood, axis=0)) cluster_lls = np.concatenate(cluster_lls, axis=0) return np.sum(logsumexp(cluster_lls, axis=0))
def predict(params, x, y, xstar): """Returns the predictive mean and covariance at locations xstar, of the latent function value f (without observation noise).""" mean, cov_params, noise_scale = unpack_params(params) cov_f_f = cov_func(cov_params, xstar, xstar) cov_y_f = cov_func(cov_params, x, xstar) cov_y_y = cov_func(cov_params, x, x) + noise_scale * np.eye(len(y)) pred_mean = mean + np.dot(solve(cov_y_y, cov_y_f).T, y - mean) pred_cov = cov_f_f - np.dot(solve(cov_y_y, cov_y_f).T, cov_y_f) return pred_mean, pred_cov
def log_marginal_likelihood(params, x, y): mean, cov_params, noise_scale = unpack_params(params) cov_y_y = cov_func(cov_params, x, x) + noise_scale * np.eye(len(y)) prior_mean = mean * np.ones(len(y)) return mvn.logpdf(y, prior_mean, cov_y_y)