fitresult

class zfit.minimizers.fitresult.FitResult(params: Dict[zfit.core.interfaces.ZfitParameter, float], edm: float, fmin: float, status: int, converged: bool, info: dict, loss: zfit.core.interfaces.ZfitLoss, minimizer: zfit.minimizers.interface.ZfitMinimizer)[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 (OrderedDict[Parameter, float]) – Result of the fit where each

:param Parameter key has the value: from the minimum found by the minimizer. :param edm: The estimated distance to minimum, estimated by the minimizer (if available) :type edm: Union[int, float] :param fmin: The minimum of the function found by the minimizer :type fmin: Union[numpy.float64, float] :param status: A status code (if available) :type status: int :param converged: Whether the fit has successfully converged or not. :type converged: bool :param info: Additional information (if available) like number of function calls and the

original minimizer return message.
Parameters:
  • loss (Union[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 state-based (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.
converged
covariance(params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None, method: Union[str, Callable] = None, as_dict: bool = False)[source]

Calculate the covariance matrix for params.

Parameters:
  • params (list(Parameter)) – The parameters to calculate the covariance matrix. If params is None, use all floating parameters.
  • method (str or Callbel) – 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.

edm

The estimated distance to the minimum.

Returns:numeric
error(params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None, method: Union[str, Callable] = None, error_name: str = None, sigma: float = 1.0) → collections.OrderedDict[source]

DEPRECATED! Use ‘errors’ instead :param params: The parameters or their names to calculate the

errors. If params is None, use all floating parameters.
Parameters:
  • method (str or Callable) – 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 log-likelihood (without the factor of 2) has a correspondents of \(\Delta\) NLL of 1 corresponds to 1 std deviation.

  • error_name (str) – The name for the error in the dictionary.
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’

Return type:

OrderedDict

errors(params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None, method: Union[str, Callable] = None, error_name: str = None, sigma: float = 1.0) → Tuple[collections.OrderedDict, Union[None, zfit.minimizers.fitresult.FitResult]][source]

Calculate and set for params the asymmetric error using the set error method.

Parameters:
  • params (list(Parameter or str)) – The parameters or their names to calculate the errors. If params is None, use all floating parameters.
  • method (str or Callable) – 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 log-likelihood (without the factor of 2) has a correspondents of \(\Delta\) NLL of 1 corresponds to 1 std deviation.

  • error_name (str) – The name for the error in the dictionary.
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’

Return type:

OrderedDict

fmin

Function value at the minimum.

Returns:numeric
hesse(params: Optional[Iterable[zfit.core.interfaces.ZfitParameter]] = None, method: Union[str, Callable] = None, error_name: Optional[str] = None) → collections.OrderedDict[source]

Calculate for params the symmetric error using the Hessian/covariance matrix.

Parameters:
  • params (list(Parameter)) – The parameters to calculate the Hessian symmetric error. If None, use all parameters.
  • method (str) – the method to calculate the covariance matrix. Can be {‘minuit_hesse’, ‘hesse_np’} or a callable.
  • error_name (str) – The name for the error in the dictionary.
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.

Return type:

OrderedDict

info
loss
minimizer
params
status
valid
class zfit.minimizers.fitresult.ParamHolder[source]

Bases: dict

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys()

Create a new dictionary with keys from iterable and values set to value.

get()

Return the value for key if key is in the dictionary, else default.

items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault()

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values
zfit.minimizers.fitresult.color_on_bool(value, on_true='\x1b[48;5;10m', on_false='\x1b[48;5;9m')[source]
zfit.minimizers.fitresult.dict_to_matrix(params, matrix_dict)[source]
zfit.minimizers.fitresult.format_value(value, highprec=True)[source]
zfit.minimizers.fitresult.matrix_to_dict(params, matrix)[source]