def test_isotropic_zero_mean_equals_log_gaussian_pdf(): D = 2 x = np.random.randn(D) g = IsotropicZeroMeanGaussian(sigma=np.sqrt(2)) log_pdf = log_gaussian_pdf(x, mu=np.zeros(D), Sigma=np.eye(D) * 2, is_cholesky=False, compute_grad=False) assert_close(log_pdf, g.log_pdf(x))
def proposal(self, current, current_log_pdf): """ Returns a sample from the proposal centred at current, acceptance probability, and its log-pdf under the target. """ if current_log_pdf is None: current_log_pdf = self.target.log_pdf(current) L_R = self.construct_proposal_covariance_(current) proposal = sample_gaussian(N=1, mu=current, Sigma=L_R, is_cholesky=True)[0] proposal_log_prob = log_gaussian_pdf(proposal, current, L_R, is_cholesky=True) proposal_log_pdf = self.target.log_pdf(proposal) # probability of proposing y when would be sitting at proposal L_R_inv = self.construct_proposal_covariance_(proposal) proopsal_log_prob_inv = log_gaussian_pdf(current, proposal, L_R_inv, is_cholesky=True) log_acc_prob = proposal_log_pdf - current_log_pdf + proopsal_log_prob_inv - proposal_log_prob return proposal, np.exp(log_acc_prob), proposal_log_pdf
def log_prior_log_pdf(x): D = len(x) return log_gaussian_pdf(x, mu=0. * np.ones(D), Sigma=np.eye(D) * 5)
def test_isotropic_zero_mean_equals_log_gaussian_pdf(): D = 2 x = np.random.randn(D) g = IsotropicZeroMeanGaussian(sigma=np.sqrt(2)) log_pdf = log_gaussian_pdf(x, mu=np.zeros(D), Sigma=np.eye(D) * 2, is_cholesky=False, compute_grad=False) assert_close(log_pdf, g.log_pdf(x))
def log_prior_log_pdf(x): D = len(x) return log_gaussian_pdf(x, mu=0.*np.ones(D), Sigma=np.eye(D) * 5)