Closed tsbinns closed 11 months ago
Sorry for the delay. We fixed any irrelevant CI issues in #139, but the rest it seems stems from changes in this PR. @tsbinns
@adam2392 I have been continuing to add the changes/fixes discussed above.
The main thing now would be how to handle the ragged arrays that could occur when working with multivariate methods (e.g. indices, results, patterns). We discussed some ideas for this, but never came to a decision. Would you prefer it if I add some MultivariateMixIn class, or would you want something more general like an N-dimensional results class of its own that could be used for other purposes as well? I think that would be the last big step before this can be finalised.
Apologies for the delays in sorting this; unfortunately I have not been able to dedicate as much time as I would have liked to the PR, but it still something I am very much interested in!
The main thing now would be how to handle the ragged arrays that could occur when working with multivariate methods (e.g. indices, results, patterns). We discussed some ideas for this, but never came to a decision. Would you prefer it if I add some MultivariateMixIn class, or would you want something more general like an N-dimensional results class of its own that could be used for other purposes as well? I think that would be the last big step before this can be finalised.
Let's revisit this when this PR is merged if that's okay with you? IIUC, we don't need the ragged part for all the methods, and thus, per https://github.com/mne-tools/mne-connectivity/pull/125#issuecomment-1435723509, we can implement this first?
I think the ragged part would take some discussion and ideally some thought to make it as lightweight as possible and compatible with where scientific python is heading: https://discuss.scientific-python.org/t/ragged-array-summit/465/4. We might consider adding an optional dependency, implementing the soln. ourselves, or a combination.
Apologies for the delays in sorting this; unfortunately I have not been able to dedicate as much time as I would have liked to the PR, but it still something I am very much interested in!
No problem! I've been quite swamped. Ping me whenever you have the changes/fixes up.
DONE:
attrs
IN PROGRESS:
spectral_connectivity_time
- adding the methods to
spectral_connectivity_time
Hi @tsbinns how is this part going? Would you like me to review anything? Thanks!
- adding the methods to
spectral_connectivity_time
Hi @tsbinns how is this part going?
Hi @adam2392, this is still a WIP, however from Monday I have 2 full weeks to dedicate to this, so it will be finished then. I will tag you once I have it and all tests are passing.
Would you like me to review anything?
I would be interested to hear your thoughts on the examples I added (mic_mim.py
and granger_causality.py
) and documentation changes I made for spectral_connectivity_epochs
. Do you think there are any improvements I could make? Cheers!
Hi @adam2392, I have now:
In terms of the goals of this PR I believe that is everything finished, assuming it is up to standard. I would be very grateful for any feedback!
Thanks very much for the feedback @adam2392! I believe I have addressed everything, but please unresolve any comments you think I should work on further.
Also please let me know when you think it's appropriate for me to update the whats_new.rst
.
Cheers!
@tsbinns feel free to add a changelog entry rn that summarizes this major feature effort! Follow the pattern there to link your name/github page.
I will take a look later in-depth on the code.
LGTM. Thanks @tsbinns and team!
congrats on getting this one merged in! great effort.
@adam2392 Sorry for the delay, but I finally have something I think we can move forward with.
What I have implemented?
spectral_connectivity_epochs
function, with the original structure of e.g. theindices
parameter (i.e. no support for ragged indices added yet, as we discussed).spectral_connectivity_epochs
to reflect these new measures.rank
,n_lags
, andpatterns
).What are the limitations?
spectral_connectivity_epochs
function making assumptions about the number of signals in the seeds/targets matching the number of connections, which is not the case for the multivariate methods at this time. It is quite easy (and clean) to adapt the functions to handle this differently when only multivariate methods are called, however things become much trickier when trying to work with bivariate and multivariate methods simultaneously. If you would like the ability to compute bivariate and multivariate methods simultaneously to be included, perhaps we can adapt some of the functions to make this easier, otherwise we could stick with the current limitation I have imposed.indices
.indices
be ragged.What have I not added?
spectral_connectivity_time
. Again, this is still on my to-do list. I have structured the MIC/MIM and GC computation code in a way that we could very easily re-use the code I have added here and just switch out the time dimension (used in case of time-frequency modes) to store epoch information, so I do not consider this a major hurdle.There is, however, a bigger issue: the assertion of the connectivity object in
test_spectral_connectivity_parallel
matching that which has been saved and then reloaded now fails, because there is ~1 kB size difference in the objects. As far as I can tell, all of the critical information in the objects are identical (e.g. the results are the same, all entries inattrs
are the same). Interestingly, this only occurs for the multitaper and fourier modes. I checked in the original test, and the size of the saved and reloaded connectivity object is also not a perfect match, however it seems to be rounded to the same "~XX kB". My hunch would be that the attrs I added to the connectivity classes (rank
,n_lags
, andpatterns
), even when unfilled, are pushing the estimated size in the repr to be rounded up when combined with the pre-existing small difference in size that occurs when saving and reloading a connectivity object. Even though I think everything is in order, I am clearly not happy with this test suddenly failing, so if you have any ideas as to why this is happening, I would really appreciate it!The test in question: https://github.com/tsbinns/mne-connectivity/blob/100e235c8520664510401d73394df1c953a6721f/mne_connectivity/spectral/tests/test_spectral.py#L134-L145
An example of the reprs from the test with the multitaper mode:![image](https://user-images.githubusercontent.com/56922019/233856258-3d371473-5272-41f4-8e09-fe51cff048d8.png)
What are the next steps?
Adding further unit tests, as well as implementing these measures in
spectral_connectivity_time
are my two biggest targets. Once I have your input, I am happy to also start addressing the limitations I listed (e.g. by adding support for ragged indices). Making sure all tests are passing would also be nice!One again, I am very sorry for the delay (a lot of other work got in the way), but I am still very excited to move forward with this! If there is anything you think would be best discussed over a call, I am very happy to do that again. I will also answer anything here as soon as I can.
Cheers, Thomas