Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General toyMC unbinned method plus max-slice method #49

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

kdund
Copy link
Contributor

@kdund kdund commented Dec 12, 2023

This PR implements a generalised GOF where you need to provide a toyMC generator and distance measure given your model, which then runs toyMCs, computes the distance measure for each and returns the p-value based on that.
In particular, it also provides a circular max-slice GOF evaluators to compute how asymmetrical a theta-distribution is.

@kdund
Copy link
Contributor Author

kdund commented Dec 12, 2023

As an example,
m = FractionInSlice(np.array([0.,0.]),opening_angle = np.pi) m.get_pvalue() returns 0.5 within toyMC precision

@kdund kdund requested review from FaroutYLq and hammannr December 13, 2023 18:22
Copy link
Collaborator

@hammannr hammannr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @kdund for adding this, looks good! A few minor comments but then I think this is good to go! 🚀

self.distance_measure = distance_measure

def get_pvalue(self, n_toys=10000, generator_kwargs={}, distance_measure_kwargs={}):
self.gof = self.distance_measure(self.data, **distance_measure_kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest defining a trivial method get_gof to get the test statistic value so that it has the same interface as the other tests in this package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. so this is the reason why people call the test statistic gof.

return np.abs((t0 - t1 + np.pi) % (2 * np.pi) - np.pi)

@staticmethod
def get_best_partition(data_t, opening_angle=np.pi, test_angles=None, return_best_angle=False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a short description of all parameters (with types) to the docstring :)

GOFevaluation/evaluators_1d.py Outdated Show resolved Hide resolved
an equal or greater portion in a slice set in the generator
angles in radians
"""
def __init__(self, data, opening_angle=np.pi, fixed_length=True):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opening_angle is not used in the init and fixed_length should be briefly explained in the docstring

tests/test_evaluators_1d.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants