def log_prob(theta): mol_radii, mol_scales = construct_arrays(theta) if min(theta) < 0.001 or max(theta) > 2: print('out of bounds!') return -np.inf logp = 0 for i in range(len(mols)): radii = mol_radii[i] scales = mol_scales[i] W_F = np.array([ compute_OBC_energy_vectorized(distance_matrix, radii, scales, charges[i]) for distance_matrix in distance_matrices[i] ]) w_F = W_F * kj_mol_to_kT pred_free_energy = one_sided_exp(w_F) if gaussian_ll: logp += norm.logpdf(pred_free_energy, loc=expt_means[i], scale=expt_uncs[i]**2) else: logp += student_t.logpdf(pred_free_energy, loc=expt_means[i], scale=expt_uncs[i], df=7) return logp
def log_prob(theta): L = log_prior(theta) if not (L > -np.inf): return L else: parameterized_list = construct_arrays(theta) for i in range(len(mols)): radii, scales = parameterized_list[i] W_F = np.array([ compute_OBC_energy_vectorized(distance_matrix, radii, scales, charges[i]) for distance_matrix in distance_matrices[i] ]) w_F = W_F * kj_mol_to_kT pred_free_energy = one_sided_exp(w_F) if ll == 'gaussian': L += norm.logpdf(pred_free_energy, loc=expt_means[i], scale=expt_uncs[i]**2) else: L += student_t.logpdf(pred_free_energy, loc=expt_means[i], scale=expt_uncs[i]**2, df=7) return L
def log_density(self, var_param, x): if x.ndim == 1: x = x[np.newaxis, :] param_dict = self._pattern.fold(var_param) return np.sum(t_dist.logpdf(x, self.df, param_dict['mu'], np.exp(param_dict['log_sigma'])), axis=-1)
def student_t_log_likelihood(predictions, expt_means, expt_uncertainties): components = student_t.logpdf(predictions, loc=expt_means, scale=expt_uncertainties, df=7) return np.sum(components)
def logdensity(x, var_param): mean, log_scale = unpack_params(var_param) if x.ndim == 1: x = x[np.newaxis,:] return np.sum(t_dist.logpdf(x, df, mean, np.exp(log_scale)), axis=-1)
def logprob(weights, latents, noise_std, observed): preds = predict(weights, latents) log_lik = np.sum(t.logpdf(preds, 2.4, observed, noise_std)) return log_lik