calamari.fitting.engine.fit#
- calamari.fitting.engine.fit(model, x, y, *, yerr=None, initial=None, limits=None, fixed=None, run_minos=False)#
Least-squares fit of model to
(x, y)via iminuit MIGRAD + HESSE.- Parameters:
model (
str|ModelDefinition) – A registered model name (seecalamari.fitting.MODELS) or aModelDefinitiondirectly.x (
ArrayLike) – Finite one-dimensional independent and dependent data of equal length. Recast to float arrays; select valid observations explicitly.y (
ArrayLike) – Finite one-dimensional independent and dependent data of equal length. Recast to float arrays; select valid observations explicitly.yerr (
ArrayLike|None) – Per-point 1-sigma errors. IfNone(default), the scatter is assumed constant and estimated from the residuals, and the reported uncertainties are the unit-error ones rescaled bysqrt(chi2/dof)(curve_fitabsolute_sigma=Falseequivalent); the result then hasyerr_assumed=True. The minimisation itself runs against a sigma on the data’s own scale, not 1, so that data in small units (a susceptibility in emu/Oe) converge – see the module docstring. A scalar broadcasts to every point. Supplied values must be finite and strictly positive, with one value per point or a scalar.initial (
dict[str,float] |None) – Starting values overriding the model defaults / data guess.limits (
dict[str,tuple[float,float]] |None) –{name: (lower, upper)}box constraints; a bound may beNoneor-inf(lower) or+inf(upper) to leave that side unconstrained. Endpoints are inclusive, including equal bounds. For a parameter also infixed, bounds must be ordered and contain no NaN.fixed (
dict[str,float] |None) –{name: value}parameters to hold constant. Fixed parameters are excluded from the degrees of freedom. A value also constrained bylimitsmust be finite and lie within its inclusive interval.run_minos (
bool) – WhenTrueand the fit is valid, also run MINOS and report the asymmetric bands inminos_errors(display-only; HESSE stays canonical). DefaultFalse.
- Return type:
- Returns:
calamari.fitting.engine.FitResult– The fit outcome. On a numerical fit failure (an arithmetic/linear-algebra exception or an invalid minimum) this is returned withsuccess=Falserather than propagating the error. So is a problem with no more points than free parameters (dof <= 0): it is not minimised, and the result carries the starting values, no uncertainties, and the true, unclampeddof. No warning is issued;successis the signal, as for every other failure.
Notes
Unexpected model/backend exceptions propagate, including during MINOS. ArithmeticError and numpy.linalg.LinAlgError during MINOS leave the valid HESSE result available with
minos_errors=None.- Raises:
FitInputError – If observations are non-finite, not one-dimensional or misaligned, or supplied uncertainties are non-finite, non-positive or misaligned. Raised before minimisation, including for sparse inputs.
FitConstraintError – If a parameter in both
fixedandlimitshas a fixed value outside its permitted interval or is non-finite, or the interval has reversed or NaN bounds. This caller error raises before minimisation, even for empty or underdetermined data. Correct the fixed value or its bounds; it never becomessuccess=False.UnknownModelError – For an unknown model name (also a
KeyError).FitParameterError – For a name in
initial,limitsorfixedthat is not one of the model’s parameters (also aKeyError). These are caller errors, not fit failures, so they raise whatever the data – including on a problem too sparse to fit – rather than coming back assuccess=False.