exponfit#

torchspin.exponfit(x, y, n_exp=1, *, include_offset=True)[source]#

Fit exponential decay or recovery curves.

Fits the model:

\[y(x) = c_0 + c_1 \exp(k_1 x) + [c_2 \exp(k_2 x)]\]

where k values are negative for decay curves.

Parameters:
  • x (ndarray) – Abscissa (time) values.

  • y (ndarray) – Ordinate values. If 2-D with shape (N, M), each column is fitted independently.

  • n_exp (int) – Number of exponential components (1 or 2).

  • include_offset (bool) – If True (default), include a constant offset c_0 in the model.

Returns:

  • k – Decay rate constants (negative for decays). Shape (n_exp,) for single series, (n_exp, M) for multiple.

  • c – Linear coefficients [c_0, c_1, ...] (offset first if included). Shape (n_exp + offset, ) or (n_exp + offset, M).

  • yfit – Fitted function values, same shape as y.

Return type:

tuple[ndarray, ndarray, ndarray]