`compute_average_dev_head_t` averages head rotation with squared time weights (translation uses linear weights)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 66/100
Línea de trabajo
El error está en _average_quats en mne/transforms.py, que es llamada por compute_average_dev_head_t en mne/preprocessing. Empieza por las líneas que multiplican los cuaterniones por los pesos antes del einsum que construye A, y comprueba dónde se elevan los pesos al cuadrado. Ejecuta el script de reproducción del issue: el ángulo de rotación debería salir en unos 0,1501 rad, no 0,1801. Está terminado cuando el ángulo de rotación coincide con la media ponderada y las pruebas existentes de transformaciones siguen pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description of the problem
_average_quats (used by mne.preprocessing.compute_average_dev_head_t) is documented in a comment as the weighted quaternion average of Markley et al., which maximizes q^T A q with A = sum_i w_i q_i q_i^T. The implementation multiplies each quaternion by its weight and then forms the outer products, so it actually builds A = sum_i w_i^2 q_i q_i^T. The rotation is therefore averaged with squared weights, while the translation in the same function is averaged with the plain time weights, so the two parts of the returned transform are inconsistent.
Steps to reproduce
import numpy as np, mne
from mne.transforms import rot_to_quat
def rz(t):
return np.array([[np.cos(t), -np.sin(t), 0], [np.sin(t), np.cos(t), 0], [0, 0, 1]])
sfreq = 100.0
raw = mne.io.RawArray(np.zeros((1, 1000)), mne.create_info(1, sfreq, "eeg"))
q = rot_to_quat(np.array([rz(0.0), rz(0.2)]))
# columns: time, q1, q2, q3, x, y, z, g, error, velocity
pos = np.array([[0.0, *q[0], 0.00, 0, 0, 1, 0, 0],
[2.5, *q[1], 0.01, 0, 0, 1, 0, 0]])
trans = mne.preprocessing.compute_average_dev_head_t(raw, pos)["trans"]
print(np.arctan2(trans[1, 0], trans[0, 0])) # 0.1801
print(trans[0, 3]) # 0.0075
Link to data
No response
Expected results
The translation is the time-weighted mean (0.75 * 0.01 = 0.0075). The rotation should be the matching weighted quaternion mean: with A = sum_i w_i q_i q_i^T the dominant eigenvector corresponds to a rotation angle of 0.1501 rad (close to the weighted mean angle 0.75 * 0.2 = 0.15).
Actual results
The rotation angle is 0.1801 rad, which matches what squared weights give (0.5625 / (0.0625 + 0.5625) * 0.2 = 0.18). The head-position average is biased towards the longest segment.
Additional information
I suspect the problem is in mne/transforms.py, _average_quats:
quats = np.concatenate((_quat_real(quats)[..., np.newaxis], quats), -1)
quats *= weights[:, np.newaxis]
A = np.einsum("ij,ik->jk", quats, quats) # sum of outer product of each q
- Lenguaje dominante
- Python
- Estrellas
- 3.6k
- Forks
- 1.6k
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 73
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de mne-tools/mne-python
-
BUG
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
mne-tools/mne-python#14477 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ENH: Add `description` filter parameter to `Raw.crop_by_annotations()`Posiblemente ocupada @aman-coder03 la tomó hace 210 días. AbiertoENH
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
mne-tools/mne-python#13743 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Wrong exponent in the denominator of the transfer function in the filtering background tutorialPosiblemente ocupada @qxzzxq la tomó hoy. AbiertoDOC
Dificultad 1/5 Menos de una hora Aptitud para principiantes 20/100
mne-tools/mne-python#14486 ·
Los mantenedores suelen responder en 1 día
-
cannot plot into matplotlib subfigurePosiblemente ocupada @ishaaaan17 la tomó hoy. AbiertoBUG
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
mne-tools/mne-python#14481 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
BUG: One layer BEM construction fails for current ANTS6-0Months3T templatePosiblemente ocupada @sruthisureshkumar-arch la tomó hace 2 días. AbiertoBUG
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
mne-tools/mne-python#14468 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de mne-tools/mne-python
Issues similares
-
New InternshipAbiertonew_internship
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
get_graph warns that the oneway column is missing when no way has a oneway tagPosiblemente ocupada @HTenkanen la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cython/cython#8110 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
fix: security 🔐 style: article/section 📝 system: data-mgmt 🗃️ system: security 🔐 system: software 💻
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
uabrc/uabrc.github.io#1267 ·
-
Link Checker ReportAbiertoBot Type: Bug Type: Documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día