pyhf.infer.mle.fit

pyhf.infer.mle.fit(data, pdf, init_pars=None, par_bounds=None, **kwargs)[source]

Run a unconstrained maximum likelihood fit.

Note

twice_nll() is the objective function given to the optimizer and is returned evaluated at the best fit model parameters when the optional kwarg return_fitted_val is True.

Example

>>> import pyhf
>>> pyhf.set_backend("numpy")
>>> model = pyhf.simplemodels.hepdata_like(
...     signal_data=[12.0, 11.0], bkg_data=[50.0, 52.0], bkg_uncerts=[3.0, 7.0]
... )
>>> observations = [51, 48]
>>> data = pyhf.tensorlib.astensor(observations + model.config.auxdata)
>>> bestfit_pars, twice_nll = pyhf.infer.mle.fit(data, model, return_fitted_val=True)
>>> bestfit_pars
array([0.        , 1.0030512 , 0.96266961])
>>> twice_nll
array(24.98393521)
>>> -2 * model.logpdf(bestfit_pars, data) == twice_nll
array([ True])
Parameters
  • data (tensor) – The data

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

  • init_pars (list) – Values to initialize the model parameters at for the fit

  • par_bounds (list of lists or tuples) – The extrema of values the model parameters are allowed to reach in the fit

  • kwargs – Keyword arguments passed through to the optimizer API

Returns

See optimizer API