Skip to content

Commit cd7cb92

Browse files
authored
Fix RANSAC-breaking bug in RANSAC correlation window chunking code (#67)
* Fixed reshaping bug in RANSAC * Updated whats_new.rst * Improved whats_new.rst
1 parent 42f909a commit cd7cb92

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docs/whats_new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Bug
4545
- Fixed RANSAC to give consistent results with a fixed seed across different chunk sizes, by `Austin Hurst`_ and `Yorguin Mantilla`_ (:gh:`43`)
4646
- Fixed "bad channel by flat" threshold in :meth:`NoisyChannels.find_bad_by_nan_flat` to be consistent with MATLAB PREP, by `Austin Hurst`_ (:gh:`60`)
4747
- Changed "bad channel by deviation" and "bad channel by correlation" detection code in :class:`NoisyChannels` to compute IQR and quantiles in the same manner as MATLAB, thus producing identical results to MATLAB PREP, by `Austin Hurst`_ (:gh:`57`)
48+
- Fixed a bug where EEG data was getting reshaped into RANSAC windows incorrectly (channel samples were not sequential), which was causing considerable variability and noise in RANSAC results, by `Austin Hurst`_ (:gh:`67`)
4849

4950
API
5051
~~~

pyprep/ransac.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,18 @@ def _ransac_correlations(
273273

274274
# For the actual data
275275
data_window = data[chans_to_predict, : n * w_correlation]
276-
data_window = data_window.reshape(len(chans_to_predict), n, w_correlation)
276+
data_window = data_window.reshape(len(chans_to_predict), w_correlation, n)
277+
data_window = data_window.swapaxes(1, 0)
277278

278279
# For the ransac predicted eeg
279280
pred_window = ransac_eeg[: len(chans_to_predict), : n * w_correlation]
280-
pred_window = pred_window.reshape(len(chans_to_predict), n, w_correlation)
281+
pred_window = pred_window.reshape(len(chans_to_predict), w_correlation, n)
282+
pred_window = pred_window.swapaxes(1, 0)
281283

282284
# Perform correlations
283285
for k in range(w_correlation):
284-
data_portion = data_window[:, :, k]
285-
pred_portion = pred_window[:, :, k]
286+
data_portion = data_window[k, :, :]
287+
pred_portion = pred_window[k, :, :]
286288

287289
R = np.corrcoef(data_portion, pred_portion)
288290

0 commit comments

Comments
 (0)