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

Fix RANSAC-breaking bug in RANSAC correlation window chunking code #67

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 array-reshaping bug that broke RANSAC completely, by `Austin Hurst`_ (:gh:`67`)
sappelhoff marked this conversation as resolved.
Show resolved Hide resolved

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