Skip to content

feat(dss): native MNE covariance support for Evoked inputs#42

Open
snesmaeili wants to merge 2 commits into
mainfrom
fix/evoked-cov-issue-39
Open

feat(dss): native MNE covariance support for Evoked inputs#42
snesmaeili wants to merge 2 commits into
mainfrom
fix/evoked-cov-issue-39

Conversation

@snesmaeili

Copy link
Copy Markdown
Contributor

Summary

DSS._fit_mne fell back to the internal NumPy covariance path for Evoked
inputs, because mne.compute_covariance accepts only Epochs and Raw. This
adds a small compute_evoked_covariance helper that treats the averaged
response's time samples as observations and returns a genuine mne.Covariance,
then wires it into the Evoked branch of _fit_mne so the estimation stays
within the MNE ecosystem — consistent with the Raw and Epochs branches.

Changes

  • mne_denoise/dss/utils/covariance.py: new compute_evoked_covariance. It
    wraps the Evoked as a single-trial EpochsArray and defers to
    mne.compute_covariance with keep_sample_mean=True (so the single average
    is not subtracted away). The intentional "not baseline corrected" notice is
    suppressed, since DSS uses the raw second-moment covariance.
  • mne_denoise/dss/linear.py: the Evoked branch builds baseline/biased
    covariances through the helper instead of calling _fit_numpy.
  • Tests: unit tests for the helper (type/shape, second-moment value, guard on
    too-few samples) plus a regression test asserting the Evoked fit reproduces
    compute_dss on the MNE-side covariances.

Closes #39

DSS._fit_mne previously fell back to the internal NumPy covariance path
for Evoked objects, because mne.compute_covariance accepts only Epochs
and Raw. Add compute_evoked_covariance, which treats the averaged
response's time samples as observations and returns a genuine
mne.Covariance, and use it in the Evoked branch so the estimation stays
within the MNE ecosystem, consistent with the Raw and Epochs branches.

Closes #39
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (c097b7d) to head (1cea115).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
- Coverage   95.93%   95.92%   -0.01%     
==========================================
  Files          41       41              
  Lines        4599     4613      +14     
  Branches      849      851       +2     
==========================================
+ Hits         4412     4425      +13     
  Misses         88       88              
- Partials       99      100       +1     
Flag Coverage Δ
unittests 95.92% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
mne_denoise/dss/linear.py 95.75% <100.00%> (+0.01%) ⬆️
mne_denoise/dss/utils/__init__.py 100.00% <100.00%> (ø)
mne_denoise/dss/utils/covariance.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Exercise the dimensionality check so the added Evoked covariance code is
fully covered by the patch.
@BabaSanfour

Copy link
Copy Markdown
Member

Thanks for implementing this sina; but I was mainly thinking whether we could make mne-python mne.compute_covariance function accepts an evoked object too? that would be the cleanest way of doing it. @drammock @larsoner what do you think of this? I can open the issue on mne-python to make the change; if it is out of scope for mne-python we can work on the changes @snesmaeili suggested.

@larsoner

Copy link
Copy Markdown
Member

Yeah I think in principle compute_covariance could accept evoked at the MNE level

@BabaSanfour

Copy link
Copy Markdown
Member

Amazing, I will open a PR and work on it in mne; probably next week. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Native MNE Evoked Covariance Support

3 participants