Skip to content

Commit

Permalink
Add cash_sum_cython and cstat_sum_cython reference tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adonath committed Apr 3, 2019
1 parent f98867d commit 3eefe97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gammapy/cube/fit.py
Expand Up @@ -165,6 +165,8 @@ def likelihood(self, parameters, mask=None):
"""
counts, npred = self._counts_data, self.npred().data

#TODO: add mask handling to _stat_sum, so that the temp copy
# created by the fancy indexing is avoided
if self.mask is None and mask is None:
stat = self._stat_sum(counts.ravel(), npred.ravel())
elif self.mask is None:
Expand Down
18 changes: 16 additions & 2 deletions gammapy/stats/tests/test_fit_statistics.py
Expand Up @@ -105,18 +105,32 @@ def test_wstat(test_data, reference_values):
assert_allclose(statsvec, reference_values["wstat"])


@requires_dependency("sherpa")
def test_cash(test_data, reference_values):
statsvec = stats.cash(n_on=test_data["n_on"], mu_on=test_data["mu_sig"])
assert_allclose(statsvec, reference_values["cash"])


@requires_dependency("sherpa")
def test_cstat(test_data, reference_values):
statsvec = stats.cstat(n_on=test_data["n_on"], mu_on=test_data["mu_sig"])
assert_allclose(statsvec, reference_values["cstat"])


def test_cash_sum_cython(test_data):
counts = np.array(test_data["n_on"], dtype=float)
npred = np.array(test_data["mu_sig"], dtype=float)
stat = stats.cash_sum_cython(counts=counts, npred=npred)
ref = stats.cash(counts, npred).sum()
assert_allclose(stat, ref)


def test_ctstat_sum_cython(test_data):
counts = np.array(test_data["n_on"], dtype=float)
npred = np.array(test_data["mu_sig"], dtype=float)
stat = stats.cstat_sum_cython(counts=counts, npred=npred)
ref = stats.cstat(counts, npred).sum()
assert_allclose(stat, ref)


def test_wstat_corner_cases():
"""test WSTAT formulae for corner cases"""
n_on = 0
Expand Down

0 comments on commit 3eefe97

Please sign in to comment.