fittable
fittable
¶
FittableModel protocol and BaseBoundModel base class.
This module defines the interface between signal models and the shared
fitting infrastructure. A FittableModel is a model with all
independent variables bound (time, AIF, b-values, PLDs, etc.) so that
only free parameters remain.
Each modality provides a wrapper class that creates a FittableModel
from its domain-specific signal model:
- DCE:
BoundDCEModel(model, t, aif) - IVIM:
BoundIVIMModel(model, b_values) - ASL:
BoundASLModel(plds, m0, params) - DSC:
BoundGammaVariateModel(time)
The BaseBoundModel base class handles fixed-parameter logic shared
across all wrappers.
FittableModel
¶
Bases: Protocol
Protocol for fitting-ready models.
All independent variables are bound; only free parameters remain. The fitter interacts exclusively through this interface and never needs to know about modality-specific context (time, AIF, b-values).
Shapes
observed_batch:(n_observations, n_voxels)params_batch:(n_free_params, n_voxels)predict_array_batchreturns:(n_observations, n_voxels)compute_jacobian_batchreturns:(n_free_params, n_observations, n_voxels)orNone
get_initial_guess_batch
¶
Compute initial parameter guesses from observed data.
| PARAMETER | DESCRIPTION |
|---|---|
observed_batch
|
Observed signal, shape
TYPE:
|
xp
|
Array module (numpy or cupy).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray
|
Initial guesses, shape |
predict_array_batch
¶
Predict signal from parameter values.
| PARAMETER | DESCRIPTION |
|---|---|
params_batch
|
Parameter values, shape
TYPE:
|
xp
|
Array module (numpy or cupy).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray
|
Predicted signal, shape |
compute_jacobian_batch
¶
Return analytical Jacobian or None for numerical fallback.
| PARAMETER | DESCRIPTION |
|---|---|
params_batch
|
Parameter values, shape
TYPE:
|
predicted
|
Predicted signal, shape
TYPE:
|
xp
|
Array module (numpy or cupy).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NDArray | None
|
Jacobian of shape |
BaseBoundModel
¶
Shared base for all modality binding wrappers.
Handles fixed-parameter logic: filtering parameters, bounds, and initial guesses to exclude fixed values, and injecting them back into the full parameter array for model evaluation.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The underlying signal model.
TYPE:
|
fixed
|
Parameters to fix at constant values during fitting.
These are removed from the free parameter list and injected
back into the full array inside
TYPE:
|
ensure_device
¶
Transfer stored arrays to the device associated with xp.
Call this once before the fitting loop so that every internal array lives on the same device as the observed data. The method is idempotent — repeated calls with the same xp are safe and essentially free.
The base implementation converts any array items in
_fixed_values. Subclasses should call super() and
then convert their own arrays (time, AIF, b-values, PLDs,
etc.) via xp.asarray().
| PARAMETER | DESCRIPTION |
|---|---|
xp
|
Array module (numpy or cupy).
TYPE:
|
compute_jacobian_batch
¶
Return analytical Jacobian or None for numerical fallback.
Default returns None (numerical finite differences). Subclasses with analytical Jacobians should override.