Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

ENH: Adds Sparse Fascicle and Gaussian Process models #60

Merged
merged 6 commits into from
Dec 10, 2021

Conversation

josephmje
Copy link
Contributor

@josephmje josephmje commented Dec 2, 2021

Addresses nipreps/nifreeze#4 and #53

@pep8speaks
Copy link

pep8speaks commented Dec 2, 2021

Hello @josephmje! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-12-10 20:07:16 UTC

@josephmje josephmje force-pushed the enh/test_gp_model branch 7 times, most recently from f0c9b7d to 48823aa Compare December 2, 2021 20:58
param = {
"isotropic": ExponentialIsotropicModel,
}
param = {"solver": GaussianProcessRegressor}
Copy link
Contributor

@dPys dPys Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long-term, I'd bet we get more miles out of using https://docs.pymc.io/en/v3/Gaussian_Processes.html in place of sklearn's GaussianProcessRegressor but for now this implementation should be fine!?

RE: tuning this, we could start by trying to make alpha very small like what we did with the elastic-net case, but I don't know about the kernel hyperparameters. @arokem -- would the idea here be that by wrapping this in SFM, we'd avoid the need for learning the kernel's shape? The default used for GP in sklearn is ConstantKernel(1.0, constant_value_bounds="fixed" * RBF(1.0, length_scale_bounds="fixed").

If we're sticking with this default, then I think that either way, we should remove the fixed option since "kernel hyperparameters are optimized during fitting unless the bounds are marked as fixed" and from Andersson & Sotiropoulos 2015: "The smoothness is determined from hyperparameters whose values are determined directly from the data" and "the hyperparameters will be such that the predictions are a smooth function of gradient direction and, in the case of multi-shell data, b-value." Also noteworthy was this point: "the data given by original hyperparameters is very sharp and even for a dataset with 300 points will give almost half the weight to the center-point (i.e., when predicting the signal for a diffusion direction half the information comes from the point itself)."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for selecting the kernel, https://www.sciencedirect.com/science/article/pii/S1053811915006874?via%3Dihub#:~:text=Finding%20k(x,scaling%20or%20variance. they suggest using either exponential or spherical and then optimizing with maximum likelihood


def fit(self, data, **kwargs):
"""Clean-up permitted args and kwargs, and call model's fit."""
self._model = self._model.fit(data[self._mask, ...])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For parallelization, we can divide the data up into chunks before calling this, and then call this separately on each chunk (on a separate thread/process)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @arokem, I'm going to hand it over to @dPys to work on the chunking in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arokem and @oesteban -- Did we ever decide on whether the best approach for this would be to migrate @sebastientourbier 's asyncio parallelization routines for the DTI model to a base class for parallel fit/predict that could be imported to each of the SFM and DKI API's as well?

On a separate note-- would it be better to stick with asyncio, switch to joblib, or expose both approaches as optional?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would stick with a copy of Sebastien's solution here. Let's worry about a more elegant OO design after we see that this works well here.

@oesteban oesteban changed the title WIP: Adds Guassian Process model WIP: Adds Gaussian Process model Dec 9, 2021
"bids_dir = base_dir / \"bids\"\n",
"derivatives_dir = base_dir / \"dmriprep\"\n",
"\n",
"dwi_file = bids_dir / \"sub-05\" / \"ses-JHU1\" / \"dwi\" / \"sub-05_ses-JHU1_acq-GD72_dwi.nii.gz\"\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file contain b=0 volumes? I believe it should not (i.e., our dwi object doesn't filter them out)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. I think the load function filters out b values less than 50.

https://github.com/nipreps/eddymotion/blob/main/eddymotion/dmri.py#L224-L226

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just realized that the load function as it currently stands affects the AverageB0 model since no b0s will be found. Will address in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an AverageB0 model? I think it's AverageDWI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning, it actually doesn't expect bzeros

eddymotion/model.py Outdated Show resolved Hide resolved
eddymotion/model.py Outdated Show resolved Hide resolved
@josephmje josephmje marked this pull request as ready for review December 10, 2021 19:50
@josephmje josephmje changed the title WIP: Adds Gaussian Process model ENH: Adds Sparse Fascicle and Gaussian Process models Dec 10, 2021
Copy link
Contributor

@dPys dPys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dPys dPys merged commit 8ccd9d7 into nipreps:main Dec 10, 2021
@oesteban
Copy link
Member

oesteban commented Dec 11, 2021 via email

arokem pushed a commit that referenced this pull request Jun 24, 2022
ENH: Adds Sparse Fascicle and Gaussian Process models
Former-commit-id: 8ccd9d7
Former-commit-id: 9e9b146
arokem pushed a commit that referenced this pull request Jun 24, 2022
ENH: Adds Sparse Fascicle and Gaussian Process models
Former-commit-id: 84f05e9 [formerly 8ccd9d7]
Former-commit-id: 9e9b146
Former-commit-id: 128cb09
mathdugre pushed a commit to mathdugre/eddymotion that referenced this pull request Jun 24, 2022
ENH: Adds Sparse Fascicle and Gaussian Process models
mathdugre pushed a commit to mathdugre/eddymotion that referenced this pull request Jun 24, 2022
ENH: Adds Sparse Fascicle and Gaussian Process models
oesteban pushed a commit that referenced this pull request Jun 30, 2022
ENH: Adds Sparse Fascicle and Gaussian Process models
Former-commit-id: 8ccd9d7
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants