FitResult¶

class
zfit.minimize.
FitResult
(params, edm, fmin, status, converged, info, loss, minimizer)[source]¶ Bases:
zfit.minimizers.interface.ZfitResult
Create a FitResult from a minimization. Store parameter values, minimization infos and calculate errors.
Any errors calculated are saved under self.params dictionary with:
{parameter: {error_name1: {'low': value, 'high': value or similar}}
 Parameters
params (
Dict
[ZfitParameter
,float
]) – Result of the fit where eachParameter
key has the value from the minimum found by the minimizer.edm (
float
) – The estimated distance to minimum, estimated by the minimizer (if available)fmin (
float
) – The minimum of the function found by the minimizerstatus (
int
) – A status code (if available)converged (
bool
) – Whether the fit has successfully converged or not.info (
dict
) – Additional information (if available) like number of function calls and the original minimizer return message.loss (
ZfitLoss
) – The loss function that was minimized. Contains also the pdf, data etc.minimizer (
ZfitMinimizer
) – Minimizer that was used to obtain this FitResult and will be used to calculate certain errors. If the minimizer is statebased (like “iminuit”), then this is a copy and the state of other FitResults or of the actual minimizer that performed the minimization won’t be altered.

classmethod
from_minuit
(loss, params, result, minimizer)[source]¶ Create a FitResult from a :py:class:~`iminuit.util.MigradResult` returned by
iminuit.Minuit.migrad()
and a iminuit :py:class:~`iminuit.Minuit` instance with the corresponding zfit objects. Parameters
loss (
ZfitLoss
) – zfit Loss that was minimized.params (
Iterable
[ZfitParameter
]) – Iterable of the zfit parameters that were floating during the minimization.result (
MigradResult
) – Return value of the iminuit migrad command.minimizer (
Union
[ZfitMinimizer
,Minuit
]) – Instance of the iminuit Minuit that was used to minimize the loss.
 Return type
 Returns
A FitResult as if zfit Minuit was used.

property
edm
¶ The estimated distance to the minimum.
 Returns
Numeric

property
fmin
¶ Function value at the minimum.
 Returns
Numeric

hesse
(params=None, method=None, error_name=None)[source]¶ Calculate for params the symmetric error using the Hessian/covariance matrix.
 Parameters
params (
Optional
[Iterable
[ZfitParameter
]]) – The parameters to calculate the Hessian symmetric error. If None, use all parameters.method (
Union
[str
,Callable
,None
]) – the method to calculate the covariance matrix. Can be {‘minuit_hesse’, ‘hesse_np’} or a callable.error_name (
Optional
[str
]) – The name for the error in the dictionary.
 Return type
 Returns
 Result of the hessian (symmetric) error as dict with each parameter holding
the error dict {‘error’: sym_error}.
So given param_a (from zfit.Parameter(.)) error_a = result.hesse(params=param_a)[param_a][‘error’] error_a is the hessian error.

error
(params=None, method=None, error_name=None, sigma=1.0)[source]¶ Deprecated since version unknown: Use
errors()
instead. Parameters
params (
Optional
[Iterable
[ZfitParameter
]]) – The parameters or their names to calculate the errors. If params is None, use all floating parameters.method (
Union
[str
,Callable
,None
]) – The method to use to calculate the errors. Valid choices are {‘minuit_minos’} or a Callable.sigma (
float
) –Errors are calculated with respect to sigma std deviations. The definition of 1 sigma depends on the loss function and is defined there.
For example, the negative loglikelihood (without the factor of 2) has a correspondents of \(\Delta\) NLL of 1 corresponds to 1 std deviation.
error_name (
Optional
[str
]) – The name for the error in the dictionary.
 Return type
 Returns
 A OrderedDict containing as keys the parameter names and as value a dict which
contains (next to probably more things) two keys ‘lower’ and ‘upper’, holding the calculated errors. Example: result[‘par1’][‘upper’] > the asymmetric upper error of ‘par1’

errors
(params=None, method=None, error_name=None, sigma=1.0)[source]¶ Calculate and set for params the asymmetric error using the set error method.
 Parameters
params (
Optional
[Iterable
[ZfitParameter
]]) – The parameters or their names to calculate the errors. If params is None, use all floating parameters.method (
Union
[str
,Callable
,None
]) – The method to use to calculate the errors. Valid choices are {‘minuit_minos’} or a Callable.sigma (
float
) –Errors are calculated with respect to sigma std deviations. The definition of 1 sigma depends on the loss function and is defined there.
For example, the negative loglikelihood (without the factor of 2) has a correspondents of \(\Delta\) NLL of 1 corresponds to 1 std deviation.
error_name (
Optional
[str
]) – The name for the error in the dictionary.
 Return type
 Returns
 A OrderedDict containing as keys the parameter and as value a dict which
contains (next to probably more things) two keys ‘lower’ and ‘upper’, holding the calculated errors. Example: result[par1][‘upper’] > the asymmetric upper error of ‘par1’

covariance
(params=None, method=None, as_dict=False)[source]¶ Calculate the covariance matrix for params.
 Parameters
params (
Optional
[Iterable
[ZfitParameter
]]) – The parameters to calculate the covariance matrix. If params is None, use all floating parameters.method (
Union
[str
,Callable
,None
]) – The method to use to calculate the covariance matrix. Valid choices are {‘minuit_hesse’, ‘hesse_np’} or a Callable.as_dict (
bool
) – Default False. If True then returns a dictionnary.
 Returns
2D numpy.array of shape (N, N); dict`(param1, param2) > covariance if `as_dict == True.

correlation
(params=None, method=None, as_dict=False)[source]¶ Calculate the correlation matrix for params.
 Parameters
params (
Optional
[Iterable
[ZfitParameter
]]) – The parameters to calculate the correlation matrix. If params is None, use all floating parameters.method (
Union
[str
,Callable
,None
]) – The method to use to calculate the correlation matrix. Valid choices are {‘minuit_hesse’, ‘hesse_np’} or a Callable.as_dict (
bool
) – Default False. If True then returns a dictionnary.
 Returns
2D numpy.array of shape (N, N); dict`(param1, param2) > correlation if `as_dict == True.