Skip to content

Commit

Permalink
Fix RANSAC-breaking bug in RANSAC correlation window chunking code (#67)
Browse files Browse the repository at this point in the history
* Fixed reshaping bug in RANSAC

* Updated whats_new.rst

* Improved whats_new.rst
  • Loading branch information
a-hurst authored Apr 19, 2021
1 parent 42f909a commit cd7cb92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~
Expand Down
10 changes: 6 additions & 4 deletions pyprep/ransac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cd7cb92

Please sign in to comment.