erlab.analysis.fit.minuit¶
Classes
|
|
|
A thin wrapper around |
|
|
|
All the operations on a read-only sequence. |
- class erlab.analysis.fit.minuit.LeastSq(x, y, yerror, model, *, loss='linear', verbose=0, grad=None, name=None)[source]¶
Bases:
LeastSquaresA thin wrapper around
iminuit.cost.LeastSquaresthat 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 (
intorarray-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, g2=None, hessian=None, name=None, **kwds)[source]¶
Bases:
Minuitiminuit.Minuitwith additional functionality.This class extends the functionality of the
iminuit.Minuitclass by providing a convenient methodfrom_lmfitto initialize theMinuitobject from anlmfit.Modelobject.For more information on the
iminuitlibrary, 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, params=None, **kwargs)[source]¶
Create an iminuit fit from an lmfit model.
- Parameters:
model (
Model) – Lmfit model to evaluate. Parameter values, fixed states, and finite bounds are transferred to the returned minimizer.data (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |DataArray) – Dependent data values.ivars (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |DataArray|Sequence[ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |DataArray]) – Independent-variable values in the order given bymodel.independent_vars. A single array is accepted when the model has one independent variable.yerr (
float|ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]] |None, default:None) – Standard uncertainty ofdata, as a scalar or an array broadcastable to it. If omitted, every uncertainty is one in the units ofdata.return_cost (
bool, default:False) – IfTrue, return the constructedLeastSqcost function together with the minimizer.params (default:
None) – Lmfit parameters to transfer. If omitted, callmodel.guessor, for a model without a guess method,model.make_params.**kwargs – Initial parameter values or dictionaries of arguments for
lmfit.Parameter.set(). These overrides are applied only whenparamsis omitted.
- Returns:
- Raises:
ValueError – If the number of independent-variable arrays does not match the model, or if a parameter that varies is constrained by an lmfit expression. Fixed expression-constrained parameters are omitted from the iminuit parameter list.
- Return type: