Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions docs/head-motion/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ kernelspec:

The proposed method requires inferring a motion-less, reference DW map for a given diffusion orientation for which we want to estimate the misalignment.
Inference of the reference map is achieved by first fitting some diffusion model (which we will draw from [DIPY](https://dipy.org)) using all data, except the particular DW map that is to be aligned.
We call this scheme "leave one gradient out" or "logo".

All models are required to offer the same API (application programmer interface):

1. The initialization takes a gradient table as first argument, and then arbitrary parameters as keyword arguments.
2. A `fit(data)` method, which only requires a positional argument `data`.
3. A `predict(gradient)` method, which only requires a `gradient` entry (b-vector and b-value).
1. The initialization takes a DIPY `GradientTable` as the first argument, and then arbitrary parameters as keyword arguments.
2. A `fit(data)` method, which only requires a positional argument `data`, a 4D array with DWI data.
3. A `predict(gradient_table)` method, which only requires a `GradientTable` as input.
This method produces a prediction of the signal for every voxel in every direction represented in the input `gradient_table`.

```{code-cell} python
:tags: [hide-cell]
Expand All @@ -41,13 +43,16 @@ This model will allow to easily test the overall integration of the different co
Also, this model will allow a very straightforward implementation of registration to the *b=0* reference, which is commonly used to initialize the head-motion estimation parameters.

```{code-cell} python

class TrivialB0Model:
"""
A trivial model that returns a *b=0* map always.

Implements the interface of :obj:`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).

"""

__slots__ = ("_S0",)
Expand All @@ -65,19 +70,18 @@ class TrivialB0Model:
def predict(self, gradient, **kwargs):
"""Return the *b=0* map."""
return self._S0
```

```


The model can easily be initialized as follows (assuming we still have our dataset loaded):
```{code-cell} python
model = TrivialB0Model(
dmri_dataset.gradients,
S0=dmri_dataset.bzero
)
```

Then, at each iteration of our estimation strategy, we will fit this model (which does nothing) to the diffusion weighted data after holding one particular direction (`data_test`) out:
Then, at each iteration of our estimation strategy, we will fit this model to the data, after holding one particular direction (`data_test`) out, using the `logo_split` method of the dataset. In every iteration, this finds the b=0 volumes in the data and averages their values in every voxel:

```{code-cell} python
data_train, data_test = dmri_dataset.logo_split(10)
Expand Down Expand Up @@ -183,7 +187,7 @@ data_train, data_test = dmri_dataset.logo_split(88, with_b0=True)
```

### The model factory
To permit flexibly select models, the `eddymotion` package offers a `ModelFactory` that implements the *facade design pattern*.
To permit flexibility in selecting models, the `eddymotion` package offers a `ModelFactory` that implements the *facade design pattern*.
This means that `ModelFactory` makes it easier for the user to switch between models:

```{code-cell} python
Expand Down