Fit¶
-
class
gammapy.modeling.Fit(backend='minuit', optimize_opts=None, covariance_opts=None, confidence_opts=None, store_trace=False)[source]¶ Bases:
objectFit class.
The fit class provides a uniform interface to multiple fitting backends. Currently available: “minuit”, “sherpa” and “scipy”
- Parameters
- backend{“minuit”, “scipy” “sherpa”}
Global backend used for fitting, default : minuit
- optimize_optsdict
Keyword arguments passed to the optimizer. For the
"minuit"backend see https://iminuit.readthedocs.io/en/latest/api.html#iminuit.Minuit for a detailed description of the available options. If there is an entry ‘migrad_opts’, those options will be passed toiminuit.Minuit.migrad().For the
"sherpa"backend you can from the optionsmethod = {"simplex", "levmar", "moncar", "gridsearch"}Those methods are described and compared in detail on http://cxc.cfa.harvard.edu/sherpa/methods/index.html. The available options of the optimization methods are described on the following pages in detail:For the
"scipy"backend the available options are described in detail here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html- covariance_optsdict
Covariance options passed to the given backend.
- confidence_optsdict
Extra arguments passed to the backend. E.g.
iminuit.Minuit.minossupports amaxcalloption. For the scipy backendconfidence_optsare forwarded tobrentq. If the confidence estimation fails, the bracketing interval can be adapted by modifying the the upper bound of the interval (b) value.- store_tracebool
Whether to store the trace of the fit
Attributes Summary
Iminuit object
Methods Summary
confidence(datasets, parameter[, sigma, …])Estimate confidence interval.
covariance(datasets)Estimate the covariance matrix.
optimize(datasets)Run the optimization.
run(datasets)Run all fitting steps.
stat_contour(datasets, x, y[, numpoints, sigma])Compute stat contour.
stat_profile(datasets, parameter[, reoptimize])Compute fit statistic profile.
stat_surface(datasets, x, y[, reoptimize])Compute fit statistic surface.
Attributes Documentation
-
minuit¶ Iminuit object
Methods Documentation
-
confidence(datasets, parameter, sigma=1, reoptimize=True)[source]¶ Estimate confidence interval.
Extra
kwargsare passed to the backend. E.g.iminuit.Minuit.minossupports amaxcalloption.For the scipy backend
kwargsare forwarded tobrentq. If the confidence estimation fails, the bracketing interval can be adapted by modifying the the upper bound of the interval (b) value.- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- parameter
Parameter Parameter of interest
- sigmafloat
Number of standard deviations for the confidence level
- reoptimizebool
Re-optimize other parameters, when computing the confidence region.
- datasets
- Returns
- resultdict
Dictionary with keys “errp”, ‘errn”, “success” and “nfev”.
-
covariance(datasets)[source]¶ Estimate the covariance matrix.
Assumes that the model parameters are already optimised.
- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- datasets
- Returns
- result
CovarianceResult Results
- result
-
optimize(datasets)[source]¶ Run the optimization.
- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- datasets
- Returns
- optimize_result
OptimizeResult Optimization result
- optimize_result
-
run(datasets)[source]¶ Run all fitting steps.
- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- datasets
- Returns
- fit_result
FitResult Fit result
- fit_result
-
stat_contour(datasets, x, y, numpoints=10, sigma=1)[source]¶ Compute stat contour.
Calls
iminuit.Minuit.mncontour.This is a contouring algorithm for a 2D function which is not simply the fit statistic function. That 2D function is given at each point
(par_1, par_2)by re-optimising all other free parameters, and taking the fit statistic at that point.Very compute-intensive and slow.
- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- x, y
Parameter Parameters of interest
- numpointsint
Number of contour points
- sigmafloat
Number of standard deviations for the confidence level
- datasets
- Returns
- resultdict
Dictionary containing the parameter values defining the contour, with the boolean flag “success” and the info objects from
mncontour.
-
stat_profile(datasets, parameter, reoptimize=False)[source]¶ Compute fit statistic profile.
The method used is to vary one parameter, keeping all others fixed. So this is taking a “slice” or “scan” of the fit statistic.
- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- parameter
Parameter Parameter of interest. The specification for the scan, such as bounds and number of values is taken from the parameter object.
- reoptimizebool
Re-optimize other parameters, when computing the confidence region.
- datasets
- Returns
- resultsdict
Dictionary with keys “values”, “stat” and “fit_results”. The latter contains an empty list, if
reoptimizeis set to False
-
stat_surface(datasets, x, y, reoptimize=False)[source]¶ Compute fit statistic surface.
The method used is to vary two parameters, keeping all others fixed. So this is taking a “slice” or “scan” of the fit statistic.
Caveat: This method can be very computationally intensive and slow
See also:
Fit.stat_contour- Parameters
- datasets
Datasetsor list ofDataset Datasets to optimize.
- x, y
Parameter Parameters of interest
- reoptimizebool
Re-optimize other parameters, when computing the confidence region.
- datasets
- Returns
- resultsdict
Dictionary with keys “x_values”, “y_values”, “stat” and “fit_results”. The latter contains an empty list, if
reoptimizeis set to False