Skip to content

Commit

Permalink
move nD binning to parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephJHowlett committed May 7, 2021
1 parent 4955fa4 commit 08b3ced
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
18 changes: 3 additions & 15 deletions GOFevaluation/evaluators_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@
from GOFevaluation import test_statistics


class nd_test_statistics(test_statistics):
"""
Override binning to work in arbitrary dimensions
"""
def bin_data(self, bin_edges):
# function to bin nD data:
if len(self.data.shape)==1:
self.binned_data, _ = np.histogram(self.data, bins=bin_edges)
else:
self.binned_data, _ = np.histogramdd(self.data, bins=bin_edges)


class binned_poisson_chi2_gof(nd_test_statistics):
class binned_poisson_chi2_gof(test_statistics):
"""
computes the binned poisson modified Chi2 from Baker+Cousins
In the limit of large bin counts (10+) this is Chi2 distributed.
Expand All @@ -41,7 +29,7 @@ def from_binned(cls, data, expectations):
In this case the bin-edges don't matter, so we bypass the usual init
"""
self = cls(None, None, None, None)
nd_test_statistics.__init__(self=self,
test_statistics.__init__(self=self,
data=data,
pdf=expectations / np.sum(expectations),
nevents_expected=np.sum(expectations))
Expand All @@ -56,7 +44,7 @@ def __init__(self, data, pdf, bin_edges, nevents_expected):
# bypass init, using binned data
return
# initialise with the common call signature
nd_test_statistics.__init__(self=self,
test_statistics.__init__(self=self,
data=data,
pdf=pdf,
nevents_expected=nevents_expected)
Expand Down
6 changes: 5 additions & 1 deletion GOFevaluation/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def calculate_gof(self):
raise NotImplementedError("Your goodnes of fit computation goes here!")

def bin_data(self, bin_edges):
self.binned_data, _ = np.histogram(self.data, bins=bin_edges)
# function to bin nD data:
if len(self.data.shape)==1:
self.binned_data, _ = np.histogram(self.data, bins=bin_edges)
else:
self.binned_data, _ = np.histogramdd(self.data, bins=bin_edges)

def get_result_as_dict(self):
assert self._name is not None, str(self.__class__.__name__) + ": You need to define self._name for your goodnes of fit measure!"
Expand Down

0 comments on commit 08b3ced

Please sign in to comment.