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

[ENH, WIP] Multivariate connectivity methods (imaginary coherence and Granger causality) #125

Closed
wants to merge 174 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
6fe5abf
Create epochs_multivar.py
richardkoehler Oct 13, 2022
5725616
Initialize tests
richardkoehler Oct 13, 2022
fb0df37
Delete unused code
richardkoehler Oct 13, 2022
88679da
Fix imports
richardkoehler Oct 13, 2022
96cf0e3
Update init files
richardkoehler Oct 13, 2022
c6b7b4f
Remove unused arguments
richardkoehler Oct 13, 2022
aac8e43
Merge pull request #1 from vss245/main
nguyen-td Oct 13, 2022
cff4213
add multivar seed_target_indices
nguyen-td Oct 13, 2022
f61f36f
Merge pull request #1 from Hiyeri/main
vss245 Oct 13, 2022
e7b1d16
added mvc methods
tsbinns Oct 13, 2022
45ac4c2
began implementing mvc
tsbinns Oct 13, 2022
7ee771b
Merge branch 'main' of https://github.com/vss245/mne-connectivity
tsbinns Oct 13, 2022
fe861c1
add seed_tar_idcs to api
tsbinns Oct 13, 2022
4b44354
Fix circular import
richardkoehler Oct 13, 2022
23d03da
removed redundant import
tsbinns Oct 13, 2022
a109ce3
Update test_epochs_multivar.py
richardkoehler Oct 13, 2022
4bd0283
Merge branch 'main' of https://github.com/vss245/mne-connectivity
richardkoehler Oct 13, 2022
05d2610
mvc index compatibility
tsbinns Oct 13, 2022
36e23d8
Update test_epochs_multivar.py
orestis-stylianou Oct 13, 2022
32004b4
Merge branch 'main' of https://github.com/vss245/mne-connectivity
orestis-stylianou Oct 13, 2022
4cbba7c
Raise ValueError if indices is None
richardkoehler Oct 13, 2022
604a300
Update tests
richardkoehler Oct 13, 2022
c550909
added mim and mic
tsbinns Oct 13, 2022
0798823
Merge branch 'main' of https://github.com/vss245/mne-connectivity
tsbinns Oct 13, 2022
3b8ac64
Update tests
richardkoehler Oct 13, 2022
fe18307
Add _check_inputs
richardkoehler Oct 13, 2022
c1aa22f
added support for time-freq con
tsbinns Oct 13, 2022
4d28f3a
Merge branch 'main' of https://github.com/vss245/mne-connectivity
tsbinns Oct 13, 2022
8b1fb4c
Update tests
richardkoehler Oct 13, 2022
d202da2
fixed bug where all methods were assigned to con
tsbinns Oct 14, 2022
75c8083
add checking if the number of components to take is correct
vss245 Oct 14, 2022
29108d1
Change ValueError to Assertion
richardkoehler Oct 14, 2022
f2431ee
Final tests
richardkoehler Oct 14, 2022
3637aab
changed input checking
tsbinns Oct 14, 2022
6c56465
changed mv classes, cleaned up ind remapping, changed
tsbinns Oct 18, 2022
f789935
overhauled mv classes
tsbinns Oct 18, 2022
3eed657
improved computational efficiency
tsbinns Oct 19, 2022
94bef82
removed redundant conj
tsbinns Oct 20, 2022
94f7cbf
removed redundant code
tsbinns Oct 21, 2022
13156ea
removed redundant code
tsbinns Oct 21, 2022
7e98123
created separate classes file
tsbinns Oct 21, 2022
07b8d0c
refactoring
tsbinns Oct 21, 2022
3440286
bug fix
tsbinns Oct 21, 2022
d7c91f7
refactoring for GC
tsbinns Oct 21, 2022
069e423
added GC classes
tsbinns Oct 21, 2022
7b21f12
added GC classes
tsbinns Oct 22, 2022
6f08c65
renamed func
tsbinns Oct 22, 2022
95e7180
added support for GC params
tsbinns Oct 22, 2022
edbe492
improved error checking
tsbinns Oct 22, 2022
8cdf76e
implement GC and refactor
tsbinns Oct 23, 2022
e21c34a
improved error checking
tsbinns Oct 24, 2022
a069cc1
GC SVD indices bug fix
tsbinns Oct 24, 2022
822c399
improved error checking
tsbinns Oct 24, 2022
b965a3e
bug fix
tsbinns Oct 24, 2022
2ad8d7a
refactoring
tsbinns Oct 24, 2022
7c06a13
refactoring
tsbinns Oct 24, 2022
68a9386
bug fix
tsbinns Oct 24, 2022
5ce0ad6
remove time for-loop in csd_to_autocov
nguyen-td Nov 3, 2022
b65c5ba
remove time for-loop, include time dimension directly in csd matrices
nguyen-td Nov 4, 2022
9ee95ae
removed time loop for csd_to_autocov
tsbinns Nov 7, 2022
74c2166
Merge branch 'efficient' into efficient
nguyen-td Nov 8, 2022
3550947
Merge pull request #6 from vss245/efficient
nguyen-td Nov 8, 2022
0623e4f
bugfix
nguyen-td Nov 8, 2022
cacb648
Merge pull request #2 from Hiyeri/efficient
nguyen-td Nov 8, 2022
cb1a6e3
bug fix
tsbinns Nov 10, 2022
7e8129c
Fix autocov shape
richardkoehler Nov 11, 2022
e88d6e9
Fix handling of numpy arrays as indices
richardkoehler Nov 11, 2022
a5ab9cb
updated error text
tsbinns Nov 11, 2022
c67f806
Merge branch 'main' of https://github.com/vss245/mne-connectivity
tsbinns Nov 11, 2022
b7878df
bug fix
tsbinns Nov 11, 2022
f227b7a
bug fix
tsbinns Nov 11, 2022
286a3e4
variable renaming
tsbinns Nov 11, 2022
5e5bd17
added option for automatically finding rank of data
tsbinns Nov 15, 2022
b9d5274
put remapped indices into tuple
tsbinns Nov 15, 2022
fe2c3b8
bug fix GC indices
tsbinns Nov 15, 2022
165609d
fixed tolerance for finding epochs rank
tsbinns Nov 16, 2022
fa07dc3
fixed tolerance for finding epochs rank
tsbinns Nov 16, 2022
1ce4a12
fixed bug with epochs SVD for GC breaking
tsbinns Nov 16, 2022
be82ffc
fixed bug with epochs SVD for GC breaking
tsbinns Nov 16, 2022
2c85ce4
bug fix
tsbinns Nov 16, 2022
2e264f4
updated docstring for rank in SVD
tsbinns Nov 18, 2022
9da9788
updated tolerance for matrix rank
tsbinns Nov 18, 2022
e65a99b
removed redundant code
tsbinns Nov 18, 2022
5b19ffb
parallelizing autocov_to_full_var/whittle_lwr_recursion function call
nguyen-td Nov 25, 2022
c34509d
parallelizing autocov_to_full_var/whittle_lwr_recursion function call
nguyen-td Nov 25, 2022
133eaa5
formatting
nguyen-td Nov 25, 2022
b866b82
removed unnecessary conjugates when transposing
tsbinns Nov 25, 2022
7a3f5e3
parallelizing full_var_to_iss
nguyen-td Nov 30, 2022
4bd6042
paraellizing full_var_to_iss
nguyen-td Nov 30, 2022
aa79827
updated docstring
tsbinns Nov 30, 2022
68f5f74
parallelizing autocov_to_gc
nguyen-td Dec 2, 2022
abc0ebe
Merge branch 'main' into efficient
tsbinns Dec 5, 2022
c4522c0
Merge branch 'pr/3' into efficient
tsbinns Dec 5, 2022
50842dc
removed redundant comments
tsbinns Dec 5, 2022
c019b80
standardised indexing and processing
tsbinns Dec 5, 2022
4799616
bug fix
tsbinns Dec 5, 2022
8599171
bug fix
tsbinns Dec 5, 2022
00496d4
bug fix
tsbinns Dec 5, 2022
ac7fd78
Merge branch 'main' into efficient
tsbinns Dec 7, 2022
5cd32e9
standardise indexing
tsbinns Dec 7, 2022
13016d5
added n_jobs argument to conn classes
tsbinns Dec 7, 2022
aff0c93
changed logging output
tsbinns Dec 7, 2022
e67f9f6
parallelised computation of T
tsbinns Dec 7, 2022
b102cec
replaced matmul with @
tsbinns Dec 8, 2022
d537977
replaced matmul with @
tsbinns Dec 8, 2022
ccc83d8
updated GC variable names
tsbinns Dec 8, 2022
7a96f42
removed unnecessary repetition of z
tsbinns Dec 8, 2022
1b98e8e
incorporated time loop into iss_to_tf
tsbinns Dec 8, 2022
6f752ef
renamed vars and removed loop over freqs for usgc
tsbinns Dec 8, 2022
34ed8c3
updated GC variable names
tsbinns Dec 8, 2022
820a2f7
removed unnecessary repetition of z
tsbinns Dec 8, 2022
d82bbf6
incorporated time loop into iss_to_tf
tsbinns Dec 8, 2022
e4626da
renamed vars and removed loop over freqs for usgc
tsbinns Dec 8, 2022
02f2a4e
missing n_jobs arguments bug fix
tsbinns Dec 8, 2022
9e73168
changed variable dimensions
tsbinns Dec 8, 2022
b08097d
changed variable dimensions
tsbinns Dec 8, 2022
6c5cc85
changes formatting and var names
tsbinns Dec 8, 2022
4fb957c
changes formatting and var names
tsbinns Dec 8, 2022
b1e996f
bug fix missing argument
tsbinns Dec 9, 2022
4b56662
updated _compute_t docstring
tsbinns Dec 9, 2022
36f0a4d
updated _compute_t docstring
tsbinns Dec 9, 2022
4a5b1da
made var names consistent
tsbinns Dec 9, 2022
ac00f81
added parallelisation of H computation
tsbinns Dec 9, 2022
b3c64b4
Merge branch 'joblib_parallelisation'
tsbinns Dec 9, 2022
21270aa
bug fix missing argument
tsbinns Dec 9, 2022
b0ed7f6
updated var names
tsbinns Dec 10, 2022
91fe292
added multivar conn classes
tsbinns Dec 10, 2022
45c16c2
bug fix z parameter
tsbinns Dec 13, 2022
09aaa87
bug fix z parameter
tsbinns Dec 13, 2022
08e0a51
bug fix missing type checks
tsbinns Dec 14, 2022
3aa8485
bug fix wrong type n_components
tsbinns Dec 14, 2022
0346293
Merge branch 'main' into mic_topographies
tsbinns Jan 2, 2023
5dd745b
added topography support, multivariate
tsbinns Jan 3, 2023
13baa54
bug fix incorrect classes
tsbinns Jan 4, 2023
dae5b56
added check for data quality
tsbinns Jan 4, 2023
9b16416
minor styling update
tsbinns Jan 4, 2023
afb9ba6
minor styling update
tsbinns Jan 4, 2023
5ae584b
added taking absolute MIC values
tsbinns Jan 4, 2023
f730705
minor styling update
tsbinns Jan 4, 2023
25fa7ad
bug fix incorrect function name
tsbinns Jan 5, 2023
67c0c04
bug fix incorrect indexing
tsbinns Jan 5, 2023
f8aa00d
added logging of computation progress
tsbinns Jan 5, 2023
06e1106
bug fix incorrect indices
tsbinns Jan 5, 2023
179d76f
improved progress bar implementation
tsbinns Jan 6, 2023
e2b97f3
bug fix progress tracking and updated tracking
tsbinns Jan 6, 2023
2fb3c82
changed progress tracker for CSD and refactoring
tsbinns Jan 6, 2023
032561c
added missing docstring
tsbinns Jan 6, 2023
65f267d
bug fix progress bar errors
tsbinns Jan 7, 2023
be96dbc
updated progress bar message
tsbinns Jan 7, 2023
805455a
bug fix seed/target component parameters
tsbinns Jan 7, 2023
f21dff7
added precautionary check before saving
tsbinns Jan 7, 2023
096c9f2
refactoring and improved efficiency of when
tsbinns Jan 7, 2023
eede6ca
added precautionary check before saving
tsbinns Jan 7, 2023
be0f51b
Merge branch 'revamped_gc'
tsbinns Jan 7, 2023
04c55b2
bug fix missing parameters
tsbinns Jan 8, 2023
8ac0bd2
added n_lags to conn class
tsbinns Jan 8, 2023
f9a9866
refactored functions into classes
tsbinns Jan 8, 2023
77024d1
changed to require n_lags input
tsbinns Jan 8, 2023
d9dfe8b
refactored funcs to class and added n_component
tsbinns Jan 9, 2023
78ba859
Merge remote-tracking branch 'upstream/main'
tsbinns Jan 9, 2023
09050f4
bug fixes
tsbinns Jan 9, 2023
4072083
bug fix missing args
tsbinns Jan 9, 2023
19f932b
bug fix wrong name
tsbinns Jan 9, 2023
b171c39
added note on parallelisation
tsbinns Jan 11, 2023
281a3ce
updated tests
tsbinns Jan 11, 2023
751b491
updated tests
tsbinns Jan 11, 2023
c2dc4bb
updated tests
tsbinns Jan 11, 2023
ba0b89a
bug fix incorrect index
tsbinns Jan 11, 2023
4e59c4d
updated tests
tsbinns Jan 11, 2023
8cab1d7
Add tests
richardkoehler Jan 12, 2023
9769f42
Add tests
richardkoehler Jan 12, 2023
388283c
Merge remote-tracking branch 'upstream/main'
richardkoehler Jan 12, 2023
5f9b500
add tests, error checks, fixed bugs
tsbinns Jan 12, 2023
024bc7d
Merge branch 'main' into pr_branch
tsbinns Feb 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mne_connectivity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
from .base import (Connectivity, EpochConnectivity, EpochSpectralConnectivity,
EpochSpectroTemporalConnectivity, EpochTemporalConnectivity,
SpectralConnectivity, SpectroTemporalConnectivity,
TemporalConnectivity)
TemporalConnectivity, MultivariateSpectralConnectivity,
MultivariateSpectroTemporalConnectivity)
from .effective import phase_slope_index
from .envelope import envelope_correlation, symmetric_orth
from .io import read_connectivity
from .spectral import spectral_connectivity_time, spectral_connectivity_epochs
from .spectral import (spectral_connectivity_time, spectral_connectivity_epochs,
multivariate_spectral_connectivity_epochs)
from .vector_ar import vector_auto_regression, select_order
from .utils import check_indices, degree, seed_target_indices
from .utils import (check_indices, degree, seed_target_indices,
multivariate_seed_target_indices)
373 changes: 370 additions & 3 deletions mne_connectivity/base.py

Large diffs are not rendered by default.

29 changes: 25 additions & 4 deletions mne_connectivity/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from .base import (Connectivity, EpochConnectivity, EpochSpectralConnectivity,
EpochSpectroTemporalConnectivity, EpochTemporalConnectivity,
SpectralConnectivity, SpectroTemporalConnectivity,
TemporalConnectivity)
TemporalConnectivity, BaseMultivariateConnectivity,
MultivariateSpectralConnectivity,
MultivariateSpectroTemporalConnectivity)


def _xarray_to_conn(array, cls_func):
def _xarray_to_conn(array, cls_func, restore_attrs):
"""Create connectivity class from xarray.

Parameters
Expand All @@ -18,6 +20,10 @@ def _xarray_to_conn(array, cls_func):
Xarray containing the connectivity data.
cls_func : Connectivity class
The function of the connectivity class to use.
restore_attrs : bool
Whether or not to restore the nature of attributes of the class that
were modified to enable saving with HDF5 (only relevant for multivariate
connectivity classes).

Returns
-------
Expand Down Expand Up @@ -57,6 +63,11 @@ def _xarray_to_conn(array, cls_func):
conn = cls_func(
data=data, names=names, metadata=metadata, **array.attrs
)

# restore attrs modified for saving (for multivariate connectivity only)
if restore_attrs:
conn._restore_attrs()

return conn


Expand Down Expand Up @@ -97,10 +108,20 @@ def read_connectivity(fname):
'EpochConnectivity': EpochConnectivity,
'EpochTemporalConnectivity': EpochTemporalConnectivity,
'EpochSpectralConnectivity': EpochSpectralConnectivity,
'EpochSpectroTemporalConnectivity': EpochSpectroTemporalConnectivity
'EpochSpectroTemporalConnectivity': EpochSpectroTemporalConnectivity,
'MultivariateSpectralConnectivity': MultivariateSpectralConnectivity,
'MultivariateSpectroTemporalConnectivity': \
MultivariateSpectroTemporalConnectivity
}
cls_func = conn_cls[data_structure_name]

# checks whether ragged attrs of the class padded for saving need to be
# restored (so far only the case for multivariate connectivity)
if issubclass(cls_func, BaseMultivariateConnectivity):
restore_attrs = True
else:
restore_attrs = False

# get the data as a new connectivity container
conn = _xarray_to_conn(conn_da, cls_func)
conn = _xarray_to_conn(conn_da, cls_func, restore_attrs)
return conn
1 change: 1 addition & 0 deletions mne_connectivity/spectral/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .epochs import spectral_connectivity_epochs
from .epochs_multivariate import multivariate_spectral_connectivity_epochs
from .time import spectral_connectivity_time
Loading