Improve Fit class, add confidence method #1927
Conversation
# set amplitude of fit model to best fit amplitude | ||
parameters["amplitude"].value = amplitude | ||
covar_opts.setdefault("backend", "minuit") | ||
if covar_opts["backend"] in registry.register["covar"]: |
adonath
Nov 15, 2018
Member
I think this logic is at the wrong place, no? I think it should mainly reduce to the one line covar_result = self.covar(**covar_opts)
, the rest should be handled either in Fit.covar
or the Registry.
(like raising an error if a backend does not support covar). There is no need to set "covar_opts.setdefault("backend", "minuit")" either, as it is already set as a default in Fit.covar
.
I think this logic is at the wrong place, no? I think it should mainly reduce to the one line covar_result = self.covar(**covar_opts)
, the rest should be handled either in Fit.covar
or the Registry.
(like raising an error if a backend does not support covar). There is no need to set "covar_opts.setdefault("backend", "minuit")" either, as it is already set as a default in Fit.covar
.
cdeil
Nov 15, 2018
Author
Member
The registry always gives an error. Here I want to emit a warning and continue.
I've changed this a bit, using a simpler if
clause, which I prefer over try-except in this case.
The registry always gives an error. Here I want to emit a warning and continue.
I've changed this a bit, using a simpler if
clause, which I prefer over try-except in this case.
def run(self, optimize_opts=None, covar_opts=None): | ||
def confidence(self, parameter, backend="minuit", sigma=1, maxcall=0): | ||
"""Estimate confidence interval. | ||
adonath
Nov 15, 2018
Member
Add section Parameters
to the docstring?
Add section Parameters
to the docstring?
cdeil
Nov 15, 2018
Author
Member
Done
Done
else: | ||
raise NotImplementedError() | ||
|
||
def likelihood_profiles(self, model, parameters="all"): |
adonath
Nov 15, 2018
Member
As I said already in private communication, I'd be fine to remove this method, as it can be achieved by users with a few lines of Python.
As I said already in private communication, I'd be fine to remove this method, as it can be achieved by users with a few lines of Python.
cdeil
Nov 15, 2018
Author
Member
done
done
@@ -207,59 +172,130 @@ def covar(self, backend="minuit"): | |||
result : `CovarResult` |
adonath
Nov 15, 2018
Member
Add section Parameters
to the Fit.covar
docstring?
Add section Parameters
to the Fit.covar
docstring?
cdeil
Nov 15, 2018
Author
Member
done
done
73ba34e
into
gammapy:master
This PR improves the
Fit
class ingammapy.utils.fitting
a bit, doing some polishing.It also adds a new feature
Fit.covariance
as a new feature, wrappingMinuit.minos
.Seems to work OK for one simple example, see
test_confidence
I also made a small change to the
Parameters
class, so that one can access parameters not just by name and number, but also to pass a Parameter object in.This is what Sherpa does, users can pass in Parameter objects, not just names, see e.g. https://sherpa.readthedocs.io/en/latest/quick.html#a-single-parameter .
I'd like to evolve the Fit API more i this direction, because if you have a double-Gaussian, then you currently can't reach the second parameter by name. Maybe that globally unique name can be achieved, maybe not, but working with Parameter objects more in the API seems like a nice solution to me.
@adonath - Please review, especially if you're OK to have the
sigma
option inconfidence
, or if you want or need some other API, like being able to select aTS
difference to reach instead. Did we make a decision there in the discussion on API to select confidence intervals?Note that both MINUIT and Sherpa use an option "sigma" here:
https://sherpa.readthedocs.io/en/latest/fit/index.html#changing-the-error-bounds
So I think I'm +1 to also go that route, but I'm not sure. Especially the whole question of one vs two-sided is a bit more unintuitive with "sigma" ,no?