Skip to content

[FIX] Make geometric_median tolerance relative - #127

Open
EzraPalmers wants to merge 1 commit into
nbara:masterfrom
EzraPalmers:fix-geometric-median-tol
Open

EzraPalmers wants to merge 1 commit into
nbara:masterfrom
EzraPalmers:fix-geometric-median-tol

Conversation

@EzraPalmers

Copy link
Copy Markdown

geometric_median stops when a step moves the estimate by less than an absolute tol. ASR runs it on covariance matrices, so the result depends on the unit of the data. In volts (what MNE returns) the entries are around 1e-10 and the loop stops one step from the mean. In microvolts it often runs to max_iter.

This makes the tolerance relative to the norm of the estimate, which is how EEGLAB's ASR implementation (clean_rawdata) does it. A test checks that scaling the data scales the median.

import numpy as np
from meegkit.utils.asr import geometric_median

X = np.random.default_rng(0).standard_normal((200, 4))
X[:20] += 50
print(geometric_median(X))
print(geometric_median(X * 1e-6) * 1e6)

Before:

[ 0.16856843  0.09678857 -0.02583845  0.12255347]
[0.67111286 0.6364464  0.48670383 0.69730942]

After:

[ 0.16856779  0.09678812 -0.02583902  0.12255226]
[ 0.16856779  0.09678812 -0.02583902  0.12255226]

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.28%. Comparing base (7f1b3e0) to head (c041f2e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #127   +/-   ##
=======================================
  Coverage   83.28%   83.28%           
=======================================
  Files          25       25           
  Lines        2860     2860           
=======================================
  Hits         2382     2382           
  Misses        478      478           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

This branch has not been deployed

No deployments
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.

1 participant