Skip to content
Derek Fujimoto edited this page Mar 10, 2021 · 6 revisions

Conveience wrapper for the iminuit.Minuit class, with pre-defined chi-squared (source).

Constructor

minuit(fn, x, y, dy=None, dx=None, dy_low=None, dx_low=None, fn_prime=None, fn_prime_dx=1e-6, name=None, start=None, error=None, limit=None, fix=None, print_level=1, **kwargs)
  • fn: function handle. f(x, a, b, c, ...)
  • x: x data
  • y: y data
  • dy: [optional] error in y
  • dx: [optional] error in x
  • dy_low: [optional] if error in y is asymmetric. If not none, dy is upper error
  • dx_low: [optional] if error in y is asymmetric. If not none, dx is upper error
  • fn_prime: [optional] function handle for the first derivative of fn. f'(x, a, b, c, ...)
  • fn_prime_dx: Spacing in x to calculate the derivative for default calculation
  • name: [optional] sequence of strings. If set, use this for setting parameter names
  • start: [optional] sequence of numbers. Required if the function takes an array as input or if it has the form f(x, *pars), and name is not defined. Default: 1, broadcasted to all inputs
  • error: [optional] sequence of numbers. Initial step sizes.
  • limit: [optional] sequence of limits that restrict the range format: [[low, high], [low, high], ...] in which a parameter is varied by minuit., with None, inf or -inf used to disable limit
  • fix: [optional] sequence of booleans. Default: False
  • print_level: Set the print_level
    • 0 is quiet.
    • 1 prints out at the end of MIGRAD/HESSE/MINOS.
    • 2 prints debug messages.
  • kwargs: passed to Minuit.from_array_func and Minuit. To set for parameter "a" one can assign the following keywords instead of the array inputs:
    • a = initial_value
    • error_a = start_error
    • limit_a = (low, high)
    • fix_a = True

Chi-squared is as calculated here.

Functions and Attributes

Of the functionality is described in the iminuit documentation, listed here for reference:

Function/Attribute Description
minuit.migrad(ncall, iterate) Run Migrad minimization.
minuit.hesse(ncall) Run HESSE algorithm to compute asymptotic errors.
minuit.minos(*parameters, cl, ncall) Run Minos algorithm to compute confidence intervals.
minuit.values Access parameter values via an array-like view.
minuit.errors Access parameter parabolic errors via an array-like view.
minuit.merrors Return a dict-like with Minos data objects.
minuit.fixed Access whether parameters are fixed via an array-like view.
minuit.limits Access parameter limits via a array-like view.
minuit.covariance Return covariance matrix.
minuit.valid Return True if the function minimum is valid.
minuit.accurate Return True if the covariance matrix is accurate.
minuit.fval Get function value at minimum.
minuit.nfit Get number of fitted parameters (fixed parameters not counted).
minuit.mnprofile(vname, *, size, bound, …) Get Minos profile over a specified interval.
minuit.draw_mnprofile(vname, *, size, bound, …) Draw Minos profile over a specified interval (requires matplotlib).

The bfit wrapper also implements the following functions and attributes

Function/Attribute Description
minuit.chi2 Return reduced chi squared (mintuit.fval / dof) or nan if dof <= 0
minuit.get_merrors(attribute) Return array composed of the attribute attribute of the items in minuit.merrors
minuit.mat_lower_limit Return minuit.get_merrors("at_lower_limit")
minuit.mat_lower_max_fcn Return minuit.get_merrors("mat_lower_max_fcn")
minuit.mat_upper_limit Return minuit.get_merrors("at_upper_limit")
minuit.mat_upper_max_fcn Return minuit.get_merrors("at_upper_max_fcn")
minuit.mis_valid Return minuit.get_merrors("is_valid")
minuit.mlower Return minuit.get_merrors("lower")
minuit.mlower_new_min Return minuit.get_merrors("lower_new_min")
minuit.mlower_valid Return minuit.get_merrors("lower_valid")
minuit.mmin Return minuit.get_merrors("min")
minuit.mname Return minuit.get_merrors("name")
minuit.mnfcn Return minuit.get_merrors("nfcn")
minuit.mnumber Return minuit.get_merrors("number")
minuit.mupper Return minuit.get_merrors("upper")
minuit.mupper_new_min Return minuit.get_merrors("upper_new_min")
minuit.mupper_valid Return minuit.get_merrors("upper_valid")
Clone this wiki locally