OptimizerMixin#

class pyhf.optimize.mixins.OptimizerMixin(**kwargs)[source]#

Bases: object

Mixin Class to build optimizers.

__init__(**kwargs)[source]#

Create an optimizer.

Parameters:
  • maxiter (int) – maximum number of iterations. Default is 100000.

  • verbose (int) – verbose output level during minimization. Default is off (0).

Attributes

maxiter#
verbose#

Methods

_internal_minimize(func, x0, do_grad=False, bounds=None, fixed_vals=None, options={}, par_names=None)[source]#
_internal_postprocess(fitresult, stitch_pars, return_uncertainties=False)[source]#

Post-process the fit result.

Returns:

A modified version of the fit result.

Return type:

fitresult (scipy.optimize.OptimizeResult)

minimize(objective, data, pdf, init_pars, par_bounds, fixed_vals=None, return_fitted_val=False, return_result_obj=False, return_uncertainties=False, return_correlations=False, do_grad=None, do_stitch=False, **kwargs)[source]#

Find parameters that minimize the objective.

Parameters:
  • objective (func) – objective function

  • data (list) – observed data

  • pdf (Model) – The statistical model adhering to the schema model.json

  • init_pars (list of float) – The starting values of the model parameters for minimization.

  • par_bounds (list of list/tuple) – The extrema of values the model parameters are allowed to reach in the fit. The shape should be (n, 2) for n model parameters.

  • fixed_vals (list of list/tuple) – The pairs of index and constant value for a constant model parameter during minimization. Set to None to allow all parameters to float.

  • return_fitted_val (bool) – Return bestfit value of the objective. Default is off (False).

  • return_result_obj (bool) – Return scipy.optimize.OptimizeResult. Default is off (False).

  • return_uncertainties (bool) – Return uncertainties on the fitted parameters. Default is off (False).

  • return_correlations (bool) – Return correlations of the fitted parameters. Default is off (False).

  • do_grad (bool) – enable autodifferentiation mode. Default depends on backend (pyhf.tensorlib.default_do_grad).

  • do_stitch (bool) – enable splicing/stitching fixed parameter.

  • kwargs – other options to pass through to underlying minimizer

Returns:

  • parameters (tensor): fitted parameters

  • minimum (float): if return_fitted_val flagged, return minimized objective value

  • result (scipy.optimize.OptimizeResult): if return_result_obj flagged

Return type:

Fitted parameters or tuple of results