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

Implement scipy confidence method #2146

Merged
merged 4 commits into from May 21, 2019
Merged

Conversation

@adonath
Copy link
Member

@adonath adonath commented May 20, 2019

This PR implements a confidence_scipy method, that uses scipy.optimize.brentq to find the error boundaries given some TS difference.

@adonath adonath self-assigned this May 20, 2019
@adonath adonath added this to the 0.12 milestone May 20, 2019

actual = fp.table["norm_err"].data
assert_allclose(actual, [0.069966, 0.052617, 0.092854], rtol=1e-3)
assert_allclose(actual, [0.069966, 0.052617, 0.092854], rtol=1e-2)
Copy link
Contributor

@registerrier registerrier May 21, 2019

Choose a reason for hiding this comment

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

Any idea why the results are sensitive to the platform used?
These tolerances are fine on my mac but not on the linux used by Travis CI?

Copy link
Member Author

@adonath adonath May 21, 2019

Choose a reason for hiding this comment

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

No, I have no idea. I could not reproduce these fails locally, which makes it almost impossible to debug...I've actually committed this change to master (5bd1e1a) to get a green Travis build first. I'll remove it from this PR again, because it's unrelated...


def confidence(self, parameter, backend="minuit", sigma=1, **kwargs):
"""Estimate confidence interval.
Extra ``kwargs`` are passed to the backend.
E.g. `iminuit.Minuit.minos` supports a ``maxcall`` option.
For the scipy backend ``kwargs`` are forwared to `~scipy.optimize.brentq`. If the
Copy link
Contributor

@registerrier registerrier May 21, 2019

Choose a reason for hiding this comment

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

'are forwarded'

Copy link
Member Author

@adonath adonath May 21, 2019

Choose a reason for hiding this comment

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

Done

def __init__(self, function, parameters, parameter, ts_diff):
self.loglike_ref = function(parameters)
self.parameters = parameters
self.function = function
Copy link
Contributor

@registerrier registerrier May 21, 2019

Choose a reason for hiding this comment

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

I would call it ts_function and ts_ref. Since most of the time this is 2*loglike

Copy link
Contributor

@registerrier registerrier May 21, 2019

Choose a reason for hiding this comment

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

Note that the same function could be used to compute 2D confidence regions.
I would use a more specific name for the tested parameter(s).

Copy link
Member Author

@adonath adonath May 21, 2019

Choose a reason for hiding this comment

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

Concerning the naming of the fit statistics I've made a reminder issue #2149.

@adonath adonath force-pushed the scipy_confidence branch from d8cad8e to abdd36a May 21, 2019
@adonath adonath merged commit 3d9345a into gammapy:master May 21, 2019
4 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants