Skip to content

Commit

Permalink
Fix :class:pyriemann_qiskit.utils.filtering.ChannelSelection (#354)
Browse files Browse the repository at this point in the history
* Fix :class:`pyriemann_qiskit.utils.filtering.ChannelSelection` that caused incorrect channel selection
Details: NeuroTechX/moabb#685

* [pre-commit.ci] auto fixes from pre-commit.com hooks

* Update filtering.py

Remove static method get_indices (not used anymore)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: gcattan <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2025
1 parent 17987c8 commit a5b7f6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
10 changes: 10 additions & 0 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
What's new in the package
=========================



Develop branch
----------------

- Fix :class:`pyriemann_qiskit.utils.filtering.ChannelSelection` that caused incorrect channel selection




v0.4.0
------

Expand Down
22 changes: 3 additions & 19 deletions pyriemann_qiskit/utils/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ def __init__(self, n_channels, cov_est="lwf"):
self.n_channels = n_channels
self.cov_est = cov_est

@staticmethod
def _get_indices(maxes, mean_cov):
indices = []
for v in maxes:
indices.extend(np.argwhere(mean_cov == v).flatten())
return np.unique(indices)

def fit(self, X, y=None, **kwargs):
"""Select channel based on covariances
Expand All @@ -166,19 +159,10 @@ def fit(self, X, y=None, **kwargs):
covs = Covariances(estimator=self.cov_est).fit_transform(X)
# Get the average covariance between the channels.
mean_cov = np.mean(covs, axis=0)
n_feats, _ = mean_cov.shape
# Select the `n_channels` channels having the maximum covariances.
all_max = []
for i in range(n_feats):
for j in range(i, n_feats):
self._chs_idx = ChannelSelection._get_indices(all_max, mean_cov)

if len(self._chs_idx) < self.n_channels:
all_max.append(mean_cov[i, j])
else:
if mean_cov[i, j] > max(all_max):
all_max[np.argmin(all_max)] = mean_cov[i, j]

self._chs_idx = np.argpartition(
np.max(mean_cov, axis=0), -self.n_channels, axis=None
)[-self.n_channels :]
return self

def transform(self, X, **kwargs):
Expand Down

0 comments on commit a5b7f6d

Please sign in to comment.