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

RF: Optimize ICC_rep_anova using a global cache #3407

Closed
wants to merge 3 commits into from

Conversation

bbfrederick
Copy link
Contributor

@bbfrederick bbfrederick commented Nov 9, 2021

Summary

Fixes #3406 .

List of changes proposed in this PR (pull-request)

  • Caches design matrix setup information for speed.
  • Adds a nan_to_num to the final ICC calculation to catch bad values.

Acknowledgment

  • (Mandatory) I acknowledge that this contribution will be available under the Apache 2 license.

@codecov
Copy link

codecov bot commented Nov 9, 2021

Codecov Report

Merging #3407 (e373173) into master (f756b71) will decrease coverage by 0.00%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3407      +/-   ##
==========================================
- Coverage   65.21%   65.21%   -0.01%     
==========================================
  Files         307      307              
  Lines       40474    40485      +11     
  Branches     5351     5354       +3     
==========================================
+ Hits        26395    26402       +7     
- Misses      13004    13006       +2     
- Partials     1075     1077       +2     
Flag Coverage Δ
unittests 64.94% <81.81%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
nipype/algorithms/icc.py 58.33% <81.81%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f756b71...e373173. Read the comment docs.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

@bbfrederick Thanks for your patience. I think when I first looked at this, I wanted to try to figure out an alternative to using global, but I don't think that should hold this up. Giving up on that dream and revisiting this, the only suggestion I have is that we can use the @ operator to have more readable matrix multiplication. Happy to merge this in as-is, though.

x = kron(eye(nb_conditions), ones((nb_subjects, 1))) # sessions
x0 = tile(eye(nb_subjects), (nb_conditions, 1)) # subjects
X = hstack([x, x0])
centerbit = dot(dot(X, pinv(dot(X.T, X))), X.T)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
centerbit = dot(dot(X, pinv(dot(X.T, X))), X.T)
centerbit = X @ pinv(X.T @ X) @ X.T


# Sum Square Error
predicted_Y = dot(dot(dot(X, pinv(dot(X.T, X))), X.T), Y.flatten("F"))
predicted_Y = dot(centerbit, Y.flatten("F"))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
predicted_Y = dot(centerbit, Y.flatten("F"))
predicted_Y = centerbit @ Y.flatten("F")

@effigies
Copy link
Member

effigies commented Apr 3, 2022

Actually, yes, let's revert the nan_to_num, and leave that decision to downstream consumers. Otherwise we'll be changing things on people who've been using the presence of nans to make decisions.

@effigies effigies changed the title Resolution to #3406 RF: Optimize ICC_rep_anova using a global cache Apr 3, 2022
@effigies effigies added this to the 1.7.1 milestone Apr 3, 2022
@effigies effigies mentioned this pull request Apr 3, 2022
10 tasks
@effigies effigies modified the milestones: 1.7.1, 1.8.0 Apr 5, 2022
@effigies
Copy link
Member

@bbfrederick Looking to do another release next week, if you want to try to get this one finished off?

@effigies
Copy link
Member

Consider #3454 as an alternative.

@effigies effigies closed this Apr 26, 2022
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.

[enhancement] ICC_rep_anova could be significantly faster than it is when running on images
2 participants