erlab.analysis.fit.minuit

Classes

LeastSq(x, y, yerror, model[, loss, ...])

A thin wrapper around iminuit.cost.LeastSquares that produces better plots.

Minuit(fcn, *args[, grad, name])

iminuit.Minuit with additional functionality.

class erlab.analysis.fit.minuit.LeastSq(x, y, yerror, model, loss='linear', verbose=0, grad=None)[source]

Bases: LeastSquares

A thin wrapper around iminuit.cost.LeastSquares that produces better plots.

visualize(args, model_points=0)[source]

Visualize data and model agreement (requires matplotlib).

The visualization is drawn with matplotlib.pyplot into the current axes.

Parameters:
  • args (array-like) – Parameter values.

  • model_points (int or array-like, optional) – How many points to use to draw the model. Default is 0, in this case an smart sampling algorithm selects the number of points. If array-like, it is interpreted as the point locations.

class erlab.analysis.fit.minuit.Minuit(fcn, *args, grad=None, name=None, **kwds)[source]

Bases: Minuit

iminuit.Minuit with additional functionality.

This class extends the functionality of the iminuit.Minuit class by providing a convenient method from_lmfit to initialize the Minuit object from an lmfit.Model object.

For more information on the iminuit library, see its documentation.

Examples

>>> import lmfit.models
>>> import numpy as np
>>> from erlab.analysis.fit.minuit import Minuit
>>> # Create an lmfit.Model object
>>> model = lmfit.models.LinearModel()
>>> # Generate some data
>>> x = np.linspace(0, 10, 100)
>>> y = model.eval(x=x, a=2, b=1)
>>> rng = np.random.default_rng(1)
>>> y = rng.normal(y, 0.5)
>>> # Initialize a Minuit object from the lmfit.Model object
>>> m = Minuit.from_lmfit(model, y, x)
>>> # Perform the fit
>>> m.migrad()
classmethod from_lmfit(model, data, ivars, yerr=None, return_cost=False, **kwargs)[source]