Skip to content

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

Draft
snesmaeili wants to merge 1 commit into
mainfrom
fix/evoked-cov-issue-39
Draft

feat(dss): native MNE covariance support for Evoked inputs#42
snesmaeili wants to merge 1 commit 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

@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 96.10%. Comparing base (e84d8d0) to head (441e596).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   96.08%   96.10%   +0.02%     
==========================================
  Files          65       65              
  Lines        8170     8187      +17     
  Branches     1420     1423       +3     
==========================================
+ Hits         7850     7868      +18     
  Misses        152      152              
+ Partials      168      167       -1     
Flag Coverage Δ
unittests 96.10% <100.00%> (+0.02%) ⬆️

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 99.31% <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.

@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.

@BabaSanfour
BabaSanfour force-pushed the fix/evoked-cov-issue-39 branch from 441e596 to f9c5e66 Compare August 4, 2026 18:49
@BabaSanfour

Copy link
Copy Markdown
Member

This PR depends on mne-tools/mne-python#14129 (mne-tools/mne-python#14129), which closes mne-tools/mne-python#14115 (mne-tools/mne-python#14115). It will remain a draft and can be merged once that PR is merged and MNE-Python 1.13 is released, since these changes intentionally require mne>=1.13.

@BabaSanfour BabaSanfour mentioned this pull request Aug 27, 2026
13 tasks
@BabaSanfour BabaSanfour linked an issue Aug 27, 2026 that may be closed by this pull request
13 tasks
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.

v0.0.2 release Improve Native MNE Evoked Covariance Support

3 participants