77
88def RESS (X , sfreq : int , peak_freq : float , neig_freq : float = 1 ,
99 peak_width : float = .5 , neig_width : float = 1 , n_keep : int = 1 ,
10- return_maps : bool = False ):
10+ gamma : float = 0.01 , return_maps : bool = False ):
1111 """Rhythmic Entrainment Source Separation.
1212
1313 As described in [1]_.
@@ -29,6 +29,10 @@ def RESS(X, sfreq: int, peak_freq: float, neig_freq: float = 1,
2929 FWHM of the neighboring frequencies (default=1).
3030 n_keep : int
3131 Number of components to keep (default=1). -1 keeps all components.
32+ gamma : float
33+ Regularization coefficient, between 0 and 1 (default=0.01, which
34+ corresponds to 1 % regularization and helps reduce numerical problems
35+ for noisy or reduced-rank matrices [2]_).
3236 return_maps : bool
3337 If True, also output mixing (to_ress) and unmixing matrices
3438 (from_ress), used to transform the data into RESS component space and
@@ -67,6 +71,9 @@ def RESS(X, sfreq: int, peak_freq: float, neig_freq: float = 1,
6771 .. [1] Cohen, M. X., & Gulbinaite, R. (2017). Rhythmic entrainment source
6872 separation: Optimizing analyses of neural responses to rhythmic sensory
6973 stimulation. Neuroimage, 147, 43-56.
74+ .. [2] Cohen, M. X. (2021). A tutorial on generalized eigendecomposition
75+ for source separation in multichannel electrophysiology.
76+ ArXiv:2104.12356 [Eess, q-Bio].
7077
7178 """
7279 n_samples , n_chans , n_trials = theshapeof (X )
@@ -82,8 +89,12 @@ def RESS(X, sfreq: int, peak_freq: float, neig_freq: float = 1,
8289 fwhm = neig_width , n_harm = 1 ))
8390 c1 , _ = tscov (gaussfilt (X , sfreq , peak_freq , fwhm = peak_width , n_harm = 1 ))
8491
92+ # add 1% regularization to avoid numerical precision problems in the GED
93+ c0 = (c01 + c02 ) / 2
94+ c0 = c0 * (1 - gamma ) + gamma * np .trace (c0 ) / len (c0 ) * np .eye (len (c0 ))
95+
8596 # perform generalized eigendecomposition
86- d , to_ress = linalg .eig (c1 , ( c01 + c02 ) / 2 )
97+ d , to_ress = linalg .eigh (c1 , c0 )
8798 d = d .real
8899 to_ress = to_ress .real
89100
0 commit comments