Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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])
Пример #10
0
    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()
Пример #11
0
    def test_logprior_fails_without_prior(self):
        lpost = PoissonPosterior(self.x, self.y, self.model)

        with pytest.raises(AttributeError):
            lpost.logprior([10])
Пример #12
0
    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])
Пример #13
0
    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()
Пример #14
0
    def test_logprior_fails_without_prior(self):
        lpost = PoissonPosterior(self.x, self.y, self.model)

        with pytest.raises(AttributeError):
            lpost.logprior([10])