diff --git a/docs/whats_new.rst b/docs/whats_new.rst index f100c457..e348cf61 100644 --- a/docs/whats_new.rst +++ b/docs/whats_new.rst @@ -45,6 +45,7 @@ Bug - Fixed RANSAC to give consistent results with a fixed seed across different chunk sizes, by `Austin Hurst`_ and `Yorguin Mantilla`_ (:gh:`43`) - 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`) - 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`) +- 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`) API ~~~ diff --git a/pyprep/ransac.py b/pyprep/ransac.py index ef25068e..36586b9c 100644 --- a/pyprep/ransac.py +++ b/pyprep/ransac.py @@ -273,16 +273,18 @@ def _ransac_correlations( # For the actual data data_window = data[chans_to_predict, : n * w_correlation] - data_window = data_window.reshape(len(chans_to_predict), n, w_correlation) + data_window = data_window.reshape(len(chans_to_predict), w_correlation, n) + data_window = data_window.swapaxes(1, 0) # For the ransac predicted eeg pred_window = ransac_eeg[: len(chans_to_predict), : n * w_correlation] - pred_window = pred_window.reshape(len(chans_to_predict), n, w_correlation) + pred_window = pred_window.reshape(len(chans_to_predict), w_correlation, n) + pred_window = pred_window.swapaxes(1, 0) # Perform correlations for k in range(w_correlation): - data_portion = data_window[:, :, k] - pred_portion = pred_window[:, :, k] + data_portion = data_window[k, :, :] + pred_portion = pred_window[k, :, :] R = np.corrcoef(data_portion, pred_portion)