Skip to content

Fix apply weights linearly in _average_quats - #14496

Merged
larsoner merged 3 commits into
mne-tools:mainfrom
ChenziqiAdam:fix-average-quats-weights
Nov 5, 2026
Merged

larsoner merged 3 commits into
mne-tools:mainfrom
ChenziqiAdam:fix-average-quats-weights

Conversation

@ChenziqiAdam

@ChenziqiAdam ChenziqiAdam commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Fixes #14478.

What does this implement/fix?

_average_quats (used by compute_average_dev_head_t) scaled each quaternion by its weight before forming the outer products, so the matrix being decomposed was sum_i w_i^2 q_i q_i^T rather than the sum_i w_i q_i q_i^T of the Markley et al. method. The rotation was therefore averaged with squared weights, while the translation used linear weights.

This PR scales each quaternion by sqrt(w_i) instead. For the example in the issue, the averaged rotation angle changes from 0.1801 rad to 0.1501 rad, consistent with the time-weighted mean translation.

I extended the existing test_average_quats with a weighted case.

Additional information

AI disclosure: I used Claude Code to help draft the fix and the test assertion, and I reviewed the changes myself.

@larsoner
larsoner enabled auto-merge (squash) November 5, 2026 17:17
@larsoner
larsoner merged commit a1a68c4 into mne-tools:main Nov 5, 2026
25 checks passed
@welcome

welcome Bot commented Nov 5, 2026

Copy link
Copy Markdown

🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪

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.

compute_average_dev_head_t averages head rotation with squared time weights (translation uses linear weights)

2 participants