-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add caching of ranks for computing RSA with Spearman #34
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really neat little speedup!
would this also word for the tau-a metric? |
To give an indication of the speedup of this PR, here is a speed test: import mne_rsa
import numpy as np
from tqdm import trange
rng = np.random.default_rng(1)
# 10 model RDMs
model_rdms = [rng.random(1_000) for _ in range(10)]
# 100_000 data RDMs
def gen_data_rdms(n=100_000):
"""Generate the same RDM over and over again."""
data_rdm = rng.random(1_000)
for _ in trange(n):
yield data_rdm
# RSA the 10 model against the 100_000 data RDMs
for _ in mne_rsa.rsa_gen(gen_data_rdms(), model_rdms):
pass On my analysis machine, using a single core, before this PR, this took about 13 minutes to complete. After this PR it takes a single minute. |
thanks @gydis! |
I have added a cache_ranks flag to rsa_gen and rsa_array to enable caching of ranks for model RDMs when computing RSA with Spearman. For now, the ignore_nan=True case is ignored and an error is raised when cache_ranks is used with it.