calamari.fitting#

Least-squares fitting with iminuit for Calamari.

Re-exports the model registry, the built-in model functions, the fit() entry point with its FitResult, and fit_windows(), which repeats one fit over several x-ranges to show whether a parameter depends on the range chosen, and fit_breakpoint(), which locates a change of slope and compares it with no change at all. See calamari.fitting.models for the model catalogue and calamari.fitting.engine for the fit driver and error conventions.

The curie_weiss model includes a constant susceptibility background:

\[\chi(T) = \chi_0 + \frac{C}{T-\theta}.\]

The inverse_curie_weiss model fits \(1/\chi=(T-\theta)/C\) and has no background term. An omitted constant background can make its fitted Weiss temperature depend on the fitting range. Fitting curie_weiss with chi0 free accounts for that contribution; other model inadequacies can still cause range dependence. fit_windows() records that sensitivity.

Fixed parameters and limits#

A parameter named in both fixed and limits must satisfy the limits exactly, with inclusive endpoints (including equal bounds). None or an outward infinity leaves that side open. For parameters in both mappings, fixed values must be finite and bounds ordered without NaN. An incompatible request raises FitConstraintError (also a ValueError) before minimisation, even for empty or underdetermined data. Correct the fixed value or the bounds. fit_windows propagates this caller error; numerical fit failures remain ordinary success=False results.

Model and parameter selection#

An unknown model raises UnknownModelError; an unknown parameter in initial, fixed or limits raises FitParameterError. Both are also KeyError and CalamariError. These caller errors remain distinct from ordinary unsuccessful numerical fits.

Quickstart#

>>> import numpy as np
>>> from calamari.fitting import fit
>>> T = np.linspace(5, 300, 60)
>>> chi = 2.5 / (T + 8.0)                      # Curie-Weiss, theta = -8 K
>>> result = fit("curie_weiss", T, chi)
>>> round(result.parameters["theta"], 1)
-8.0

Modules

breakpoint

Fit a sharp or rounded change of slope and compare it with a straight line.

engine

Least-squares fitting driver (iminuit) and its result object.

models

Built-in magnetometry fit functions and the model registry.

windows

Fit the same model over several caller-specified ranges.