nifreeze.model.base module¶
Base infrastructure for nifreeze’s models.
- class nifreeze.model.base.BaseModel(self, dataset, **kwargs)[source]¶
Bases:
ABCDefines the interface and default methods.
Implements the interface of
dipy.reconst.base.ReconstModel. Instead of inheriting from the abstract base, this implementation follows type adaptation principles, as it is easier to maintain and to read (see https://www.youtube.com/watch?v=3MNVP9-hglc).Base initialization.
- abstract fit_predict(index: int | None = None, **kwargs) ndarray | None[source]¶
Fit and predict the indicated index of the dataset (abstract signature).
In the default Leave-One-Volume-Out (LOVO) mode,
indexnames the volume to hold out: the model is fit on every other volume and used to predict the held-out one. This held-out independence sets a base to claim that predictions are unbiased.If
indexisNone, the model is executed in single-fit mode: it is fit once on all available data (no volume held out). The fit is locked (_locked_fitevaluates to true), such that later calls reuse the fit object without refitting.
- set_dataset(dataset) None[source]¶
Read another version of the same volumes, such as the realigned view.
The estimator calls this on a model instance built on the dataset it estimates, so that instances train on the realigned view as models given by name do. Cached data are refreshed with
update().- Parameters:
dataset (
BaseDataset) – A dataset with the same volumes, in the same order.
- single_fit_is_canary: bool = False¶
Whether single-fit only makes sense as a self-consistency canary (see
_warn_single_fit_canary()).
- update(index: int) None[source]¶
Refresh what the model holds about volume
indexafter the dataset changed it.The estimator calls this after writing a realigned volume (and b-vector) into the dataset the model was built on. Models that read the dataset on every fit need nothing; models that cache the data override this.
- Parameters:
index (
int) – The volume that changed.
- class nifreeze.model.base.ExpectationModel(self, dataset, stat='median', **kwargs)[source]¶
Bases:
BaseModelA trivial model that returns an expectation map (for example, average).
Initialize a new model.
- nifreeze.model.base.MASK_ABSENCE_WARN_MSG = 'No mask provided; consider using a mask to avoid issues in model optimization.'¶
Mask warning message.
- class nifreeze.model.base.ModelFactory(self, /, *args, **kwargs)[source]¶
Bases:
objectA factory for instantiating data models.
- static init(model: str | None = None, **kwargs)[source]¶
Instantiate a diffusion model.
- Parameters:
model (
str) – Diffusion model. Options:"DTI","DKI","GQI","GP","S0","AverageDWI"."GP"(aliases"GPR","GaussianProcess") builds aGPModel; passkernel_modelthroughkwargsto select the covariance."GP-LOO"(GPLOOModel) and"GQI-KRR"(GQIKRRModel) predict each held-out volume in closed form (seenifreeze.model.lovo).- Returns:
model – A model object compliant with DIPY’s interface.
- Return type:
ReconstModel
- nifreeze.model.base.PREDICTED_MAP_ERROR_MSG = 'This model requires the predicted map at initialization'¶
Oracle requirement error message.
- nifreeze.model.base.SINGLE_FIT_CANARY_MSG = 'Single-fit for this model is a self-consistency check (canary): the held-out volume is also in the training set, so it is reproduced near-perfectly. It validates the implementation rather than being a genuine prediction.'¶
Single-fit canary warning message.
- exception nifreeze.model.base.SingleFitCanaryWarning[source]¶
Bases:
UserWarningSingle-fit for this model only makes sense as a self-consistency canary.
- class nifreeze.model.base.TrivialModel(self, dataset, predicted=None, **kwargs)[source]¶
Bases:
BaseModelA trivial model that returns a given map always.
Implement object initialization.
- nifreeze.model.base.UNSUPPORTED_MODEL_ERROR_MSG = 'Unsupported model <{model}>.'¶
Unsupported model error message