mne-tools / mne-connectivity

Connectivity algorithms that leverage the MNE-Python API.
https://mne.tools/mne-connectivity/dev/index.html
BSD 3-Clause "New" or "Revised" License
65 stars 34 forks source link

[GSOC] Add a 'decoding' module to expand flexibility of multivariate methods #182

Open tsbinns opened 1 month ago

tsbinns commented 1 month ago

Background

@larsoner @wmvanvliet @drammock

A key limitation with the existing implementation of multivariate connectivity methods in spectral_connectivity_epochs() and spectral_connectivity_time() is the incompatibility with standard decoding paradigms, e.g. fitting filters to some training data and applying them to other data. Note that this applies only to those methods which use filters (CaCoh and MIC; not MIM or GC). Additionally, the low computational cost of this approach (avoiding repeated re-calculation of filters) would make it much more feasible for real-time analyses e.g. for BCIs.

Following the decoding module of MNE-Python, a decoding module in MNE-Connectivity can be created containing classes for each compatible connectivity method, i.e. a CaCoh class and a MIC class. These classes would support:

Both classes will have the same methods & parameters, and also work very similarly internally, allowing for a base class that handles most of the functionality. I envision the following structure (will denote points I think are especially worth discussing with bold italics):


Class initialisation

Similar to the classes in MNE-Python's decoding module, parameters could include:

Here it would just be the case of checking the validity of all input parameters, elements of which already exist within MNE-Connectivity and MNE-Python.


fit method

Similar to the classes in MNE-Python's decoding module, parameters could include:

Processing steps could include:


Technical point: what exactly do we fit filters for?

Ultimately I think treating the frequency band as a single entity and creating a single set of filters for this band collectively is the best approach and keeps things very consistent with the behaviour of SSD and CSP in MNE-Python's decoding module. Happy to discuss the technical details further if people have concerns about this.


transform method

Similar to the classes in MNE-Python's decoding module, parameters could include:

The function would return epoched data with shape [epochs x components x times], which simply involves multiplying the data with the filters and returning up to n_components as specified earlier.


plot_filters and plot_patterns methods

The overall layout of these functions can generally follow those in the CSP class, but with the difference that we need to handle plotting filters/patterns for both the seeds and targets.

My initial thought is to have separate plots returned for the seed components and target components.


Examples/tutorials

Examples for this new 'decoding' approach will be created demonstrating how the classes can be used to fit to/transform data. Other features could be:


Unit tests

Unit tests would be added for the new 'decoding' classes, covering many of the same points as the unit tests for the existing implementations.


Other important considerations

Right now, the filters and patterns of only 1 component are being used in the connectivity estimator classes. This will be addressed by another aim of the GSoC project where users will have the option to return connectivity and filters/patterns for more than just the first component (see #183).


Timeline

This was estimated to be the largest part of the GSoC project, with time allocated until the start of July. However, time will also be spent once support for >1 component is added (as described above) for updating the unit tests and examples.