Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docs for using P2S optimally #2382

Merged
merged 9 commits into from
May 4, 2021
Merged

Conversation

ShreyasFadnavis
Copy link
Member

@ShreyasFadnavis ShreyasFadnavis commented May 1, 2021

  • Added information about parameters of Patch2Self
  • Also added information on applying Patch2Self on batches

@ShreyasFadnavis
Copy link
Member Author

Hi! Sorry for the slowness in this small PR. I have added information about how to use Patch2Self optimally. It is ready to be reviewed 👍🏽

ridge regression (model='ridge').

*Please do note that sometimes using ridge regression can hamper the
performance of Patch2Self. If so, please use model='ols'.*
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
performance of Patch2Self. If so, please use model='ols'.*
performance of Patch2Self. If so, please use model='ols'.

After doing this, the 2 denoised batches can be merged as follows:
`denoised_p2s = np.concatenate((denoised_batch1, denoised_batch2), axis=3)`

If using Patch2Self for research purposes, acquisition design tests, etc., one
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If using Patch2Self for research purposes, acquisition design tests, etc., one
If using Patch2Self for research purposes, acquisition design tests, etc., one

I am not sure what the "research purposes" means here. The following "acquisition design, tests, etc." suggests that this is not something that users should do if they want to analyze the data? But I am not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Agreed... Taking that part of the line off. I just wanted to encourage people to experiment with the algorithm.

denoised_arr = patch2self(data, bvals, shift_intensity=True,
clip_negative_vals=False)
denoised_arr = patch2self(data, bvals, model='ols', shift_intensity=True,
clip_negative_vals=False, b0_threshold=100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry -- one more: why is b0_threshold set to a higher value than the gradient_table default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay... Set it back to 50, which is the default (even in the codebase). I added a note that people should change it if they are working with data such as HCP 👍🏽


The default value of `b0_threshold` in DIPY is set to 50. If using data
such as HCP, the b0 volume tends to have a higher value, please set it to 100
or more accordingly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm. The b-values that were used in the HCP 3T dataset are:

array([   5.,  990.,  995., 1000., 1005., 1985., 1990., 1995., 2000.,
       2005., 2010., 2980., 2985., 2990., 2995., 3000., 3005., 3010.])

So, setting b0_threshold=50 and setting b0_threshold=100 would presumably give you exactly the same thing. I am also confused about the phrase the b0 volume tends to have a higher value -- it doesn't seem like this parameter would interact with the values of the image, only with the selection of the image volumes. Or am I missing something?

Copy link
Member Author

@ShreyasFadnavis ShreyasFadnavis May 3, 2021

Choose a reason for hiding this comment

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

Hi @arokem -- That is correct. If the bvals are less than 50 the b0_threshold at 50 and 100 would behave exactly the same way. Here are the bvals for HCP 7T for instance:
image

As you can see they are >=50 somewhere between 55 and 65. Although not common, I do want to warn users in case they have such datasets. Let me try rephrasing the sentence to make it clearer.

denoised_arr = patch2self(data, bvals, shift_intensity=True,
clip_negative_vals=False)
denoised_arr = patch2self(data, bvals, model='ols', shift_intensity=True,
clip_negative_vals=False, b0_denoising=50)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
clip_negative_vals=False, b0_denoising=50)
clip_negative_vals=False, b0_threshold=50)

More here: I believe that b0_denoising is a boolean.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or possibly

Suggested change
clip_negative_vals=False, b0_denoising=50)
clip_negative_vals=False, b0_denoising=True)

But both are the default values, so it's not clear why you are setting either of them.

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad! Good catch -- fixing this.


"""
The above parameters should give optimal denoising performance for Patch2Self.
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimal in this dataset, or generally? If generally, why are these not the default values? For example, the warning below about ridge hampering performance is rather ominous. Should we change the default to 'ols'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

Optimal in this dataset, or generally?

Copy link
Member Author

@ShreyasFadnavis ShreyasFadnavis May 3, 2021

Choose a reason for hiding this comment

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

'ols' is optimal generally. Same goes for shift_intensity=True and clip_negative_vals=False 👍🏽 Ridge does seem to be useful to speedup the regression. I was also looking into using the regression module of sklearn and found this comment from the discussion very useful: scikit-learn/scikit-learn#13923 (comment).

Should I use this? I was thinking of adding an option called ols_fast instead of just replacing ols with ridge and a very small alpha. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it's very odd that ridge is faster than OLS, given that they essentially are the same algorithm with a small tweak that shouldn't really affect performance at all. But 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep... me too!😂

@@ -82,6 +90,15 @@
Please set `shift_intensity=True` and `clip_negative_vals=False` by default to
avoid negative values in the denoised output.

The `b0_threshold` is used to separate the b0 volumes from the DWI volumes.
Changing the value of the b0 threshold is needed is the b0 volumes in the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Changing the value of the b0 threshold is needed is the b0 volumes in the
Changing the value of the b0 threshold is needed if the b0 volumes in the


The default value of `b0_threshold` in DIPY is set to 50. If using data
such as HCP 7T, the b0 volumes tend to have a higher b-value (>=50)
assoiciated with them in the `bval` file. Please check the b-values for b0s and
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assoiciated with them in the `bval` file. Please check the b-values for b0s and
associated with them in the `bval` file. Please check the b-values for b0s and

@ShreyasFadnavis
Copy link
Member Author

ShreyasFadnavis commented May 3, 2021

While we are at it: should I also add Patch2Self in every tutorial as a primary step? I remember @arokem suggesting this in a previous PR 👍🏽 P2S is fast... adds ~3-5 mins for Stanford HARDI data per example (I think used most pervasively). Is this okay? Or will it drive up the compilation time of all tutorials drastically?

@skoudoro
Copy link
Member

skoudoro commented May 3, 2021

70 tutorials x 5min = 350min =~ 6h more.... so I recommend to pick up not more than 10 tutorials.

@ShreyasFadnavis
Copy link
Member Author

70 tutorials x 5min = 350min =~ 6h more.... so I recommend to pick up not more than 10 tutorials.

Yes! I don't think it's relevant for all tutorials either :)

Here are the ones where I would add it:

  1. CSD and MCSD
  2. 3D SHORE
  3. MAP-MRI
  4. DTI
  5. DKI
  6. FW-DTI
  7. WMTI
  8. Basic Tracking EuDX
  9. Deterministic Tracking
  10. Probabilistic Tracking
  11. Particle Filter Tracking

Does this sound okay?

@skoudoro
Copy link
Member

skoudoro commented May 3, 2021

Does this sound okay?

+1 👍🏾

@codecov
Copy link

codecov bot commented May 3, 2021

Codecov Report

Merging #2382 (f2d028a) into master (4148983) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2382   +/-   ##
=======================================
  Coverage   85.23%   85.24%           
=======================================
  Files         126      126           
  Lines       16575    16575           
  Branches     2686     2686           
=======================================
+ Hits        14128    14129    +1     
+ Misses       1762     1759    -3     
- Partials      685      687    +2     
Impacted Files Coverage Δ
dipy/denoise/patch2self.py 73.63% <100.00%> (ø)
dipy/viz/app.py 77.01% <0.00%> (-0.49%) ⬇️
dipy/reconst/forecast.py 89.84% <0.00%> (+1.52%) ⬆️

@skoudoro
Copy link
Member

skoudoro commented May 3, 2021

@arokem, Do you want to have a last look? What is the final decision concerning this PR?

@skoudoro skoudoro added this to the 1.4.1 milestone May 3, 2021
@arokem
Copy link
Contributor

arokem commented May 4, 2021

I would only change those tutorials that already have denoising in them, but I think that we can take that on another PR (or even better, series of PRs). I think that this PR is ready to go.

@skoudoro skoudoro merged commit 00af530 into dipy:master May 4, 2021
@skoudoro
Copy link
Member

skoudoro commented May 4, 2021

Thank you @ShreyasFadnavis, thank you for the review @arokem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants