pyhf.infer.mle.fit#
- pyhf.infer.mle.fit(data, pdf, init_pars=None, par_bounds=None, fixed_params=None, **kwargs)[source]#
Run a maximum likelihood fit. This is done by minimizing the objective function
twice_nll()
of the model parameters given the observed data. This is used to produce the maximal likelihood \(L\left(\hat{\mu}, \hat{\boldsymbol{\theta}}\right)\) in the profile likelihood ratio in Equation (7) in [1007.1727]\[\lambda\left(\mu\right) = \frac{L\left(\mu, \hat{\hat{\boldsymbol{\theta}}}\right)}{L\left(\hat{\mu}, \hat{\boldsymbol{\theta}}\right)}\]Note
twice_nll()
is the objective function given to the optimizer and is returned evaluated at the best fit model parameters when the optional kwargreturn_fitted_val
isTrue
.Example
>>> import pyhf >>> pyhf.set_backend("numpy") >>> model = pyhf.simplemodels.uncorrelated_background( ... signal=[12.0, 11.0], bkg=[50.0, 52.0], bkg_uncertainty=[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 datapdf (Model) – The statistical model adhering to the schema model.json
init_pars (
list
offloat
) – The starting values of the model parameters for minimization.par_bounds (
list
oflist
/tuple
) – The extrema of values the model parameters are allowed to reach in the fit. The shape should be(n, 2)
forn
model parameters.fixed_params (
tuple
orlist
ofbool
) – The flag to set a parameter constant to its starting value during minimization.kwargs – Keyword arguments passed through to the optimizer API
- Returns:
See optimizer API