def test_logprior(self): t0 = [10.0] lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) lp_test = lpost.logprior(t0) lp = np.log(scipy.stats.norm(self.countrate, self.countrate).pdf(t0)) assert lp == lp_test
def test_counts_are_nan(self): y = np.nan * np.ones(self.x.shape[0]) t0 = [10.0] self.model.amplitude = t0[0] mean_model = self.model(self.x) lpost = PoissonPosterior(self.x, y, self.model) lpost.logprior = set_logprior(lpost, self.priors) assert np.isclose(lpost(t0), logmin, 1e-5)
def test_negative_loglikelihood(self): t0 = [10.0] self.model.amplitude = t0[0] mean_model = self.model(self.x) loglike = -np.sum(-mean_model + self.y*np.log(mean_model) - scipy_gammaln(self.y+1)) lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) loglike_test = lpost.loglikelihood(t0, neg=True) assert np.isclose(loglike, loglike_test)
def test_negative_posterior(self): t0 = [10.0] self.model.amplitude = t0[0] mean_model = self.model(self.x) lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) post_test = lpost(t0, neg=True) loglike = np.sum(-mean_model + self.y*np.log(mean_model) - scipy_gammaln(self.y+1)) logprior = np.log(scipy.stats.norm(self.countrate, self.countrate).pdf(t0)) post = -loglike - logprior assert np.isclose(post_test, post, atol=1.e-10)
def test_correct_number_of_parameters(self): lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) with pytest.raises(IncorrectParameterError): lpost([2, 3])
def test_making_posterior(self): lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) assert lpost.x.all() == self.x.all() assert lpost.y.all() == self.y.all()
def test_logprior_fails_without_prior(self): lpost = PoissonPosterior(self.x, self.y, self.model) with pytest.raises(AttributeError): lpost.logprior([10])
def test_correct_number_of_parameters(self): lpost = PoissonPosterior(self.x, self.y, self.model) lpost.logprior = set_logprior(lpost, self.priors) with pytest.raises(IncorrectParameterError): lpost([2,3])