Skip to content

Commit

Permalink
ENH: Better log when applying proj during ICA (mne-tools#8345)
Browse files Browse the repository at this point in the history
Previously:
```
Inferring max_pca_components from picks
    Applying projection operator with 3 vectors
    Applying projection operator with 3 vectors
Selecting by explained variance: 74 components
```

Now:
```
Inferring max_pca_components from picks
    Applying projection operator with 3 vectors (pre-whitener computation)
    Applying projection operator with 3 vectors (pre-whitener application)
Selecting by explained variance: 74 components
```
  • Loading branch information
hoechenberger authored Oct 6, 2020
1 parent 697f7e9 commit ad43de7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mne/preprocessing/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def _fit_epochs(self, epochs, picks, decim, verbose):

def _compute_pre_whitener(self, data):
"""Aux function."""
data = self._do_proj(data)
data = self._do_proj(data, log_suffix='(pre-whitener computation)')

if self.noise_cov is None:
# use standardization as whitener
Expand Down Expand Up @@ -653,21 +653,22 @@ def _compute_pre_whitener(self, data):
assert data.shape[0] == pre_whitener.shape[1]
self.pre_whitener_ = pre_whitener

def _do_proj(self, data):
def _do_proj(self, data, log_suffix=''):
if self.info is not None and self.info['projs']:
proj, nproj, _ = make_projector(
[p for p in self.info['projs'] if p['active']],
self.info['ch_names'], include_active=True)
if nproj:
logger.info(
f' Applying projection operator with {nproj} '
f'vector{_pl(nproj)}')
f'vector{_pl(nproj)}'
f'{" " if log_suffix else ""}{log_suffix}')
if self.noise_cov is None: # otherwise it's in pre_whitener_
data = proj @ data
return data

def _pre_whiten(self, data):
data = self._do_proj(data)
data = self._do_proj(data, log_suffix='(pre-whitener application)')
if self.noise_cov is None:
data /= self.pre_whitener_
else:
Expand Down

0 comments on commit ad43de7

Please sign in to comment.