Skip to content

ICC_rep_anova speedup suggestion #3450

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

Closed
kristoferm94 opened this issue Apr 20, 2022 · 4 comments
Closed

ICC_rep_anova speedup suggestion #3450

kristoferm94 opened this issue Apr 20, 2022 · 4 comments
Milestone

Comments

@kristoferm94
Copy link
Contributor

kristoferm94 commented Apr 20, 2022

Summary

ICC_rep_anova can be sped up by rearranging the matrix multiplication order and using the hermitian=True flag in pinv

Actual behavior

As implemented, pinv is called without the hermitian=True flag.
dot(X.T, X) will always be a hermitian matrix so speedup can be achieved by setting the hermitian flag in pinv to True.

The matrix multiplication in line 117 in icc.py is arranged in a way that fat matrices end up being multiplied together.
The matrix multiplication order can be rearranged in a way that we end up multiplying fat matrices with column vectors most of the time.

Script/Workflow details

Suggested modification in lines 117: https://github.com/kristoferm94/nipype/blob/linalg-speedup/nipype/algorithms/icc.py

I.e. replace:

predicted_Y = dot(dot(dot(X, pinv(dot(X.T, X))), X.T), Y.flatten("F"))

with

predicted_Y = X @ (pinv(X.T @ X, hermitian=True) @ (X.T @ Y.flatten("F")))
@effigies
Copy link
Member

Seems like a good idea. Would you mind also changing dot(a, b) with a @ b in these expressions?

@kristoferm94
Copy link
Contributor Author

Sure. I've updated the first comment.

@effigies
Copy link
Member

Sorry, should have been clearer: Do you want to submit a quick PR?

@kristoferm94
Copy link
Contributor Author

No problem.
Sure, I've submitted a pull request with the proposed change: #3453

@effigies effigies added this to the 1.8.0 milestone Apr 22, 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

No branches or pull requests

2 participants