Skip to content

Commit

Permalink
Merge pull request #26 from Eric89GXL/simpler
Browse files Browse the repository at this point in the history
MRG: Simpler formulation
  • Loading branch information
agramfort committed Jan 19, 2017
2 parents fd3c553 + 113901c commit 3b41012
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions mne_sandbox/preprocessing/_sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Sensor noise suppression"""

import numpy as np
from scipy import linalg

from mne import compute_raw_covariance, pick_info
from mne.cov import (_check_scalings_user, _picks_by_type, _apply_scaling_cov,
Expand Down Expand Up @@ -133,13 +132,16 @@ def fit(self, raw, verbose=None):
norm[use_mask] = 1. / np.sqrt(eigval[use_mask])
eigvec *= norm
del eigval
# augment with given channel
eigvec = linalg.block_diag([1.], eigvec)
idx = np.concatenate(([ii], idx))
# The channel is projected on this basis and replaced by its
# projection (rotate and project)
corr = np.dot(np.dot(eigvec.T, data_cov[np.ix_(idx, idx)]), eigvec)
operator[ii, idx[1:]] = np.dot(corr[0, 1:], eigvec[1:, 1:].T)
# projection
operator[ii, idx] = np.dot(eigvec,
np.dot(data_cov[ii][idx], eigvec))
# Equivalently (and less efficiently):
# eigvec = linalg.block_diag([1.], eigvec)
# idx = np.concatenate(([ii], idx))
# corr = np.dot(np.dot(eigvec.T, data_cov[np.ix_(idx, idx)]),
# eigvec)
# operator[ii, idx[1:]] = np.dot(corr[0, 1:], eigvec[1:, 1:].T)
if operator[ii, ii] != 0:
raise RuntimeError
# scale our results back (the ratio of channel scales is what matters)
Expand Down

0 comments on commit 3b41012

Please sign in to comment.