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

[ENH] pad t and F 'short' contrasts with zeros #4067

Merged
merged 10 commits into from Oct 24, 2023

Conversation

Remi-Gau
Copy link
Collaborator

Changes proposed in this pull request:

  • pad t and F constrast when they are too short
  • throw a warning when padding is done
  • throw error only when contrast are longer than the number of columns

@github-actions
Copy link
Contributor

👋 @Remi-Gau Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.

  • PR has an interpretable title.
  • PR links to Github issue with mention Closes #XXXX (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.

@Remi-Gau
Copy link
Collaborator Author

mentioned in the associated issue, using the contrasts symbolically (eg. 'c1 - c2') in the example mentioned in the issue so avoid having to change contrast length when the high pass filter model is changed.

@Remi-Gau
Copy link
Collaborator Author

@bthirion I would not mind an early review on this.

I do not like that the warnings / errors that have to be thrown in different places, feels like there should be a single function checking contrast shape and doing the padding rather than changes in several places.

@bthirion
Copy link
Member

You mean, one single function for t and F ?

@bthirion
Copy link
Member

The PR looks good overall.

Comment on lines +110 to +112
con_val = pad_contrast(
con_val=con_val, theta=reg.theta, contrast_type=contrast_type
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bthirion
any reason why for F contrasts we do not rely on the FContrast methods and do something like

reg = regression_result[label_].Fcontrast(con_val)

the way we do it for T contrasts above?

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, this is because we had to trick it somehow to support fixed effects on F contrasts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok this may require a comment if we can remember the why otherwise I could add a TODO to try to refactor this

Copy link
Member

Choose a reason for hiding this comment

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

I can add this to your PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a TODO for now in case we want to merge and tackle this 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.

Maybe rather in another PR.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #4067 (3a13951) into main (0817b96) will increase coverage by 0.09%.
Report is 5 commits behind head on main.
The diff coverage is 96.15%.

@@            Coverage Diff             @@
##             main    #4067      +/-   ##
==========================================
+ Coverage   91.50%   91.60%   +0.09%     
==========================================
  Files         143      143              
  Lines       16072    16091      +19     
  Branches     3339     3345       +6     
==========================================
+ Hits        14707    14740      +33     
+ Misses        820      804      -16     
- Partials      545      547       +2     
Flag Coverage Δ
macos-latest_3.10 91.49% <96.15%> (+<0.01%) ⬆️
macos-latest_3.11 91.49% <96.15%> (+<0.01%) ⬆️
macos-latest_3.12 91.49% <96.15%> (?)
macos-latest_3.8 91.45% <96.15%> (+<0.01%) ⬆️
macos-latest_3.9 91.46% <96.15%> (+<0.01%) ⬆️
ubuntu-latest_3.10 91.49% <96.15%> (+<0.01%) ⬆️
ubuntu-latest_3.11 91.49% <96.15%> (+<0.01%) ⬆️
ubuntu-latest_3.12 91.49% <96.15%> (+<0.01%) ⬆️
ubuntu-latest_3.8 91.45% <96.15%> (+<0.01%) ⬆️
ubuntu-latest_3.9 91.46% <96.15%> (+<0.01%) ⬆️
windows-latest_3.10 91.44% <96.15%> (+<0.01%) ⬆️
windows-latest_3.11 91.44% <96.15%> (+<0.01%) ⬆️
windows-latest_3.12 91.44% <96.15%> (+<0.01%) ⬆️
windows-latest_3.8 91.40% <96.15%> (+<0.01%) ⬆️
windows-latest_3.9 91.40% <96.15%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
nilearn/glm/contrasts.py 92.38% <100.00%> (+0.03%) ⬆️
nilearn/glm/model.py 78.40% <100.00%> (ø)
nilearn/glm/_utils.py 90.37% <94.44%> (+0.62%) ⬆️

... and 7 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Remi-Gau
Copy link
Collaborator Author

Remi-Gau commented Oct 20, 2023

TODO

  • update changelog

@Remi-Gau Remi-Gau marked this pull request as ready for review October 23, 2023 08:11
Copy link
Member

@ymzayek ymzayek left a comment

Choose a reason for hiding this comment

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

LGTM overall!

Where q = number of :term:`contrast` vectors
and p = number of regressors.

theta theta of RegressionResults instances
Copy link
Member

Choose a reason for hiding this comment

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

can you add the type for theta here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added the type but also tried to improve the doc string: let me know if this reads sufficiently well.

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

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

LGTM, thx.

Comment on lines +110 to +112
con_val = pad_contrast(
con_val=con_val, theta=reg.theta, contrast_type=contrast_type
)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rather in another PR.

@Remi-Gau Remi-Gau merged commit 697f77d into nilearn:main Oct 24, 2023
30 of 31 checks passed
@Remi-Gau Remi-Gau deleted the contrast_pad branch October 24, 2023 08:51
Remi-Gau added a commit to Remi-Gau/nilearn that referenced this pull request Oct 24, 2023
* pad contrasts

* refactor

* rm test for warning

* remove obsolete test

* add test for error F contrast

* add comment

* add comment

* update changelog

* update changelog

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

Successfully merging this pull request may close these issues.

Length of contrast vectors depends on high cutoff frequency
3 participants